#fraction #period #tweening

mathio

A lightweight, simple and straight-forward opinionated library for math used in other projects

7 releases

0.2.5 Dec 2, 2023
0.2.4 Dec 2, 2023
0.2.1 Aug 24, 2023
0.1.0 Aug 5, 2023

#474 in Math

Download history 16/week @ 2024-06-15 16/week @ 2024-06-22 23/week @ 2024-06-29 10/week @ 2024-07-13 5/week @ 2024-07-20 29/week @ 2024-07-27 11/week @ 2024-08-03 4/week @ 2024-08-10 5/week @ 2024-08-17 6/week @ 2024-08-24 6/week @ 2024-08-31 7/week @ 2024-09-07 8/week @ 2024-09-14 27/week @ 2024-09-21 19/week @ 2024-09-28

62 downloads per month
Used in 5 crates (2 directly)

MIT/Apache

15KB
187 lines

Mathio 🚀️

License crates.io Released API docs

A lightweight, simple and straight-forward opinionated library for math used in other projects.

Current features are:

  • Fractions
  • Tweening
  • Periods

=== Examples ===

Fractions

Great for expressing lossless floats

use mathio::Fraction;

let frac_1 = Fraction::new(2, 3);
let frac_2 = Fraction::new(3, 6);
 
assert_eq!(frac_1 + frac_2, Fraction::new(7, 6));
assert_eq!(frac_1 - frac_2, Fraction::new(1, 6));
assert_eq!(frac_1 * frac_2, Fraction::new(1, 3));
assert_eq!(frac_1 / frac_2, Fraction::new(4, 3));
assert_eq!(frac_1 >= frac_2, true);

Periods

Good for clamping repeating values (angles, sin/cosine, etc.)

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));

=== Licensing ===

Released under both APACHE and MIT licenses. Pick one that suits you the most!

Dependencies

~0–5MB
~92K SLoC