MathUtils 1.0.0

A high-fidelity Rust mirror of the JavaScript (ECMAScript) Math built-in object.
Documentation
//! Standard mathematical constants defined in the ECMAScript specification.
//!
//! Each constant represents a well-known mathematical value in double-precision floating point
//! format (`f64`). Both uppercase JavaScript-style names (e.g. `LN10`, `SQRT2`) and idiomatic
//! Rust snake-case aliases (e.g. `LN_10`, `SQRT_2`) are provided.

/// Euler's constant ($e$), the base of natural logarithms.
///
/// Mathematically defined as $e = \lim_{n \to \infty} (1 + 1/n)^n \approx 2.718281828459045$.
///
/// Mirrors JavaScript's `Math.E`.
///
/// # Examples
///
/// ```
/// use MathUtils::Math;
///
/// assert!((Math::E - 2.718281828459045).abs() < 1e-15);
/// assert_eq!(Math::log(Math::E), 1.0);
/// ```
pub const E: f64 = std::f64::consts::E;

/// Natural logarithm of 10 ($\ln(10)$).
///
/// The exponent to which $e$ must be raised to produce 10, approximately `2.302585092994046`.
///
/// Mirrors JavaScript's `Math.LN10`.
///
/// # Examples
///
/// ```
/// use MathUtils::Math;
///
/// assert!((Math::LN10 - 2.302585092994046).abs() < 1e-15);
/// assert_eq!(Math::log(10.0), Math::LN10);
/// ```
pub const LN10: f64 = std::f64::consts::LN_10;

/// Snake-case alias for [`LN10`].
pub const LN_10: f64 = std::f64::consts::LN_10;

/// Natural logarithm of 2 ($\ln(2)$).
///
/// The exponent to which $e$ must be raised to produce 2, approximately `0.6931471805599453`.
///
/// Mirrors JavaScript's `Math.LN2`.
///
/// # Examples
///
/// ```
/// use MathUtils::Math;
///
/// assert!((Math::LN2 - 0.6931471805599453).abs() < 1e-15);
/// assert_eq!(Math::log(2.0), Math::LN2);
/// ```
pub const LN2: f64 = std::f64::consts::LN_2;

/// Snake-case alias for [`LN2`].
pub const LN_2: f64 = std::f64::consts::LN_2;

/// Base-10 logarithm of Euler's constant $e$ ($\log_{10}(e)$).
///
/// Equivalent to $1 / \ln(10)$, approximately `0.4342944819032518`.
///
/// Mirrors JavaScript's `Math.LOG10E`.
///
/// # Examples
///
/// ```
/// use MathUtils::Math;
///
/// assert!((Math::LOG10E - 0.4342944819032518).abs() < 1e-15);
/// assert_eq!(Math::log10(Math::E), Math::LOG10E);
/// ```
pub const LOG10E: f64 = std::f64::consts::LOG10_E;

/// Snake-case alias for [`LOG10E`].
pub const LOG10_E: f64 = std::f64::consts::LOG10_E;

/// Base-2 logarithm of Euler's constant $e$ ($\log_2(e)$).
///
/// Equivalent to $1 / \ln(2)$, approximately `1.4426950408889634`.
///
/// Mirrors JavaScript's `Math.LOG2E`.
///
/// # Examples
///
/// ```
/// use MathUtils::Math;
///
/// assert!((Math::LOG2E - 1.4426950408889634).abs() < 1e-15);
/// assert_eq!(Math::log2(Math::E), Math::LOG2E);
/// ```
pub const LOG2E: f64 = std::f64::consts::LOG2_E;

/// Snake-case alias for [`LOG2E`].
pub const LOG2_E: f64 = std::f64::consts::LOG2_E;

/// Archimedes' constant ($\pi$), the ratio of a circle's circumference to its diameter.
///
/// Approximately `3.141592653589793`.
///
/// Mirrors JavaScript's `Math.PI`.
///
/// # Examples
///
/// ```
/// use MathUtils::Math;
///
/// assert!((Math::PI - 3.141592653589793).abs() < 1e-15);
/// assert!(Math::sin(Math::PI).abs() < 1e-15);
/// assert_eq!(Math::cos(Math::PI), -1.0);
/// ```
pub const PI: f64 = std::f64::consts::PI;

/// Square root of 1/2 ($\sqrt{1/2} = 1/\sqrt{2}$).
///
/// Approximately `0.7071067811865476`.
///
/// Mirrors JavaScript's `Math.SQRT1_2`.
///
/// # Examples
///
/// ```
/// use MathUtils::Math;
///
/// assert!((Math::SQRT1_2 - 0.7071067811865476).abs() < 1e-15);
/// assert_eq!(Math::sqrt(0.5), Math::SQRT1_2);
/// ```
pub const SQRT1_2: f64 = std::f64::consts::FRAC_1_SQRT_2;

/// Snake-case alias for [`SQRT1_2`].
pub const SQRT_1_2: f64 = std::f64::consts::FRAC_1_SQRT_2;

/// Square root of 2 ($\sqrt{2}$).
///
/// Approximately `1.4142135623730951`.
///
/// Mirrors JavaScript's `Math.SQRT2`.
///
/// # Examples
///
/// ```
/// use MathUtils::Math;
///
/// assert!((Math::SQRT2 - 1.4142135623730951).abs() < 1e-15);
/// assert_eq!(Math::sqrt(2.0), Math::SQRT2);
/// ```
pub const SQRT2: f64 = std::f64::consts::SQRT_2;

/// Snake-case alias for [`SQRT2`].
pub const SQRT_2: f64 = std::f64::consts::SQRT_2;