Skip to main content

Crate MathUtils

Crate MathUtils 

Source
Expand description

§MathUtils

A high-fidelity, zero-dependency Rust crate that mirrors JavaScript’s ECMAScript Math built-in object.

MathUtils provides the exact constants, methods, rounding semantics, and edge-case behaviors specified by the ECMAScript 2024 language specification, with dual support for JavaScript-style naming (Math::clz32, Math::PI, Math::sumPrecise) and idiomatic Rust conventions.

§Quick Start

use MathUtils::Math;

// Exact ECMAScript rounding behavior:
assert_eq!(Math::round(-0.5), -0.0);
assert!(Math::round(-0.5).is_sign_negative());
assert_eq!(Math::round(1.5), 2.0);
assert_eq!(Math::round(-1.5), -1.0);

// Full trigonometric and logarithmic methods:
assert_eq!(Math::sin(0.0), 0.0);
assert_eq!(Math::log10(100.0), 2.0);
assert_eq!(Math::imul(-1, 8), -8);

// IEEE 754 float precision conversions:
assert_eq!(Math::fround(1.337), 1.3370000123977661);
assert_eq!(Math::f16round(std::f64::consts::PI), 3.140625);

// Variadic helpers and macros:
use MathUtils::math_max;
assert_eq!(math_max!(1.0, 99.5, -42.0), 99.5);

Re-exports§

pub use conversions::ToJsInt32;
pub use conversions::ToJsUint32;
pub use constants::*;

Modules§

constants
Standard mathematical constants defined in the ECMAScript specification.
conversions
Traits and conversions mirroring JavaScript’s ToUint32 and ToInt32 operations.
macros
Declarative macros providing JavaScript-like variadic function invocation.

Macros§

math_hypot
Computes the square root of the sum of squares of zero or more numbers ($\sqrt{x_1^2 + x_2^2 + \dots + x_n^2}$).
math_max
Computes the maximum value among zero or more numeric arguments.
math_min
Computes the minimum value among zero or more numeric arguments.

Structs§

Math
The primary namespace mirroring JavaScript’s built-in Math object.