A lightweight, simple and straight-forward opinionated library for math used in other projects.
Current features are:
Fractions
Great for expressing lossless floats ``` rust use mathio::Fraction;
let frac1 = Fraction::new(2, 3); let frac2 = Fraction::new(3, 6);
asserteq!(frac1 + frac2, Fraction::new(7, 6)); asserteq!(frac1 - frac2, Fraction::new(1, 6)); asserteq!(frac1 * frac2, Fraction::new(1, 3)); asserteq!(frac1 / frac2, Fraction::new(4, 3)); asserteq!(frac1 >= frac_2, true); ```
Periods
Good for clamping repeating values (angles, sin/cosine, etc.)
rust
let period = 360.0;
assert_eq!(315.0, periodical(period, -45.0));
assert_eq!(45.0, periodical(period, 45.0));
assert_eq!(0.0, periodical(period, 360.0));
assert_eq!(90.0, periodical(period, 450.0));
Released under both APACHE and MIT licenses. Pick one that suits you the most!