Expand description
A Rust library for accessing a collection of mathematical and cryptographic constants
Part of the Mini Functions family of libraries.
§Overview 📖
Common (CMN)
is a modern, fast, and user-friendly library that makes it easy to access a wide range of mathematical and cryptographic constants.
§Features ✨
The Common (CMN)
uses the serde
crate to serialize and deserialize the data.
The library has three modules:
- Macros: This module contains functions for generating macros that can be used to access the constants.
- Constants: This module contains the Constants structure, which provides a collection of constant values that are used throughout the library.
- Words: This module contains the Words structure, which provides a collection of words that are used throughout the library.
§Mathematical and Cryptographic Constants
The following table lists the most important mathematical and cryptographic constants available in the Common (CMN)
library:
Constants | Description | Example |
---|---|---|
APERY | Apéry’s constant, is the sum of the reciprocals of the positive cubes.ζ(3) ≈ 1.2020569032 | Used in various mathematical calculations and series approximations. |
AVOGADRO | Avogadro’s constant is the number of atoms or molecules in one mole of a substance.N_A ≈ 6.02214076 x 10^23 mol^-1 | The number of atoms in 12 grams of carbon-12 is 6.02214076 × 10^23. This can be used to calculate the number of atoms or molecules in a given sample. |
BOLTZMANN | Boltzmann’s constant is the physical constant relating the temperature of a system to the average kinetic energy of its constituent particles.k_B ≈ 1.380648 x 10^-23 J K^-1 | The kinetic energy of an atom at room temperature is about 2.0 × 10^-21 joules. This can be used to calculate the temperature of a system, or to calculate the average kinetic energy of its particles. |
CATALAN | Catalan’s constant, is the sum of the alternating harmonic series.C ≈ 0.915965594177219 | Used in various mathematical calculations and series approximations. |
COULOMB | Coulomb’s constant, is the proportionality constant in Coulomb’s law.k_e ≈ 8.9875517923 x 10^9 N m^2 C^-2 | Used in calculations related to electrostatic forces and electric fields. |
EULER | Euler’s constant is a mathematical constant approximately equal to 2.71828.e ≈ 2.7182818284590452353602874713527 | The sum of the infinite series 1 + 1/2 + 1/3 + … is equal to Euler’s constant, e. This can be used to calculate the sum of an infinite series, or to calculate the logarithm of a number. |
FARADAY | Faraday constant, which represents the amount of electric charge carried by one mole of electrons.F ≈ 96485.33212 C mol^-1 | Used in calculations related to electrochemistry and electrolysis. |
GAMMA | The gamma constant is a mathematical constant approximately equal to 0.57721.γ ≈ 0.5772156649015329 | The gamma function of 2 is equal to 1. This can be used to calculate the gamma function of a number, or to calculate the factorial of a number. |
GAS_CONSTANT | The gas constant, which relates the energy scale to the temperature scale in the ideal gas law.R ≈ 8.314462618 J mol^-1 K^-1 | Used in calculations related to the behavior of gases and thermodynamics. |
GLAISHER_KINKELIN | Glaisher-Kinkelin constant, which arises in the asymptotic expansion of the Barnes G-function.A ≈ 1.2824271291 | Used in various mathematical calculations and series approximations. |
GRAVITATIONAL_CONSTANT | The gravitational constant, is the proportionality constant in Newton’s law of universal gravitation.G ≈ 6.67430 x 10^-11 m^3 kg^-1 s^-2 | Used in calculations related to gravitational forces and celestial mechanics. |
HASH_ALGORITHM | The hash algorithm used to generate the hash. The default is Blake3. | The hash of the string “Hello, world!” is 5eb63bbbe01eeed093cb22bb8f5acdc32790160b123138d53f2173b8d3dc3eee. This can be used to verify the integrity of data, or to create a unique identifier for a file. |
HASH_COST | The cost of the hash. | The hash cost of Blake3 is2^128 . This can be used to determine how secure a hash algorithm is. |
HASH_LENGTH | The length of the hash. | The hash length of Blake3 is 32 bytes. This can be used to determine how much space is required to store the hash output. |
KHINCHIN | Khinchin’s constant, which appears in the theory of continued fractions.K ≈ 2.6854520010 | Used in various mathematical calculations and series approximations. |
PHI | The golden ratio is a number approximately equal to 1.618033988749895.φ = (1 + √5) / 2 ≈ 1.6180339887498948482045868343656 | The golden ratio can be used to create a symmetrical design, or a design that is pleasing to the eye. |
Pi (π) | Pi is the ratio of a circle’s circumference to its diameter.π ≈ 3.14159265358979323846264338327950288 | The circumference of a circle with a radius of 1 is equal to pi. This can be used to calculate the circumference, area, and volume of circles, spheres, and other geometric shapes. |
PLANCK | Planck’s constant, which relates the energy of a photon to its frequency.h ≈ 6.62607015 x 10^-34 J s | The energy of a photon of light with a wavelength of 500 nanometers is equal to Planck’s constant multiplied by the frequency of the light. This can be used to calculate the energy of photons and other elementary particles. |
PLANCK_REDUCED | Planck’s reduced constant, is Planck’s constant divided by 2π.ħ = h / (2π) ≈ 1.054571817 x 10^-34 J s | Used in quantum mechanics and related calculations. |
SILVER_RATIO | The silver ratio is one of the silver means.δ_s = 1 + √2 ≈ 2.4142135623730950488016887242097 | The silver ratio can be used to create a symmetrical design, or a design that is pleasing to the eye. |
SPEED_OF_LIGHT | The speed of light in vacuum.c ≈ 299792458 m s^-1 | Used in calculations related to relativity and electromagnetic phenomena. |
SPECIAL_CHARS | A set of special characters. | The special characters are: !@#$%^&*()_+-={}[] |
SQRT2 | The square root of 2.√2 ≈ 1.4142135623730950488016887242097 | The area of a circle with a radius of 1 is equal to the square root of 2. This can be used to calculate the area and volume of circles, spheres, and other geometric shapes. |
SQRT3 | The square root of 3.√3 ≈ 1.7320508075688772935274463415059 | The area of a circle with a radius of 1 is equal to the square root of 3. This can be used to calculate the area and volume of circles. |
SQRT5 | The square root of 5.√5 ≈ 2.23606797749979 | The area of a circle with a radius of 1 is equal to the square root of 5. |
TAU | The circle constant, is the ratio of a circle’s circumference to its radius.τ = 2π ≈ 6.28318530717958647692528676655900577 | The circumference of a circle with a radius of 1 is equal to tau. |
VACUUM_PERMEABILITY | The vacuum permeability, which relates magnetic induction to magnetic field strength.μ_0 ≈ 1.25663706212 x 10^-6 N A^-2 | Used in calculations related to electromagnetism and magnetic fields. |
VACUUM_PERMITTIVITY | The vacuum permittivity, which relates electric displacement to electric field strength.ε_0 ≈ 8.8541878128 x 10^-12 F m^-1 | Used in calculations related to electromagnetism and electric fields. |
The following table lists the dictionaries available in the Common library.
Words | Description |
---|---|
words | Contains a dictionary of common words. |
§Usage
Common can be any serde::Serialize
or serde::Deserialize
types
§Examples
// Import the Common libraries
extern crate cmn;
use cmn::Constants;
use cmn::Words;
use cmn::words::WORD_LIST;
// Constants
let constants = Constants::new();
let constant = constants.constant("EULER");
assert_eq!(constant.unwrap().name, "EULER");
// Words
let words = Words::default();
let words_list = words.words_list();
// Checking the first three elements to verify correct initialization and ordering
assert_eq!(words_list.len(), WORD_LIST.len(), "Default words list length should match WORD_LIST length.");
assert_eq!(words_list[0], "aboard", "Check that words list is sorted and starts with the first word.");
§License
The project is licensed under the terms of both the MIT license and the Apache License (Version 2.0).
§Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
Re-exports§
Modules§
- constants
- The
constants
module contains theConstants
structure, which provides a collection of constant values that are used throughout the library. - macros
- The
macros
module contains functions for generating macros. Macros for the cmn crate. - words
- The
words
module contains theWords
structure, which provides a collection of words that are used throughout the library. This module provides a structured way to manage a collection of words. It is primarily used in applications where word manipulation is necessary, such as generating passphrases or similar textual content.
Macros§
- cmn
- This macro takes any number of arguments and parses them into a Rust value.
- cmn_
assert - This macro asserts that the given condition is true. If the condition is false, the macro panics with the given message.
- cmn_
constants - This macro defines a set of constants with their corresponding values. The macros can be used to define constants in a concise and easy-to-read way.
- cmn_
contains - This macro checks if the given string contains the given substring.
- cmn_
in_ range - This macro checks if the given value is within the given range.
- cmn_
join - This macro joins the given strings together with the given separator.
- cmn_map
- This macro creates a new map of the given key-value pairs.
- cmn_max
- This macro finds the maximum value of the given values.
- cmn_min
- This macro finds the minimum value of the given values.
- cmn_
parse - This macro parses the given input into a Rust value.
- cmn_
print - This macro prints the given arguments to the console.
- cmn_
print_ vec - This macro prints the given vector of values to the console.
- cmn_
split - This macro splits the given string into a vector of strings.
- cmn_
to_ num - This macro converts the given string to a number.
- cmn_vec
- This macro creates a new vector with the given elements.
Structs§
- Common
- The
Common
structure provides a central location to store data that is commonly used throughout the library. The structure implements theSerialize
andDeserialize
traits from theserde
crate to enable serialization and deserialization of the data.
Functions§
- run
- This is the main entry point for the
Common (CMN)
library.