#fraction #struct #format

fuzzy_fraction

Struct for approximated human-readable fraction representation

3 releases

0.1.2 Jul 17, 2023
0.1.1 Nov 30, 2021
0.1.0 Nov 30, 2021

#1332 in Math

MIT license

12KB
267 lines

Rust struct for approximated human-readable fraction representation.. No GCD or any dependencies involved..

use fuzzy_fraction::FuzzyFraction;

assert_eq!(FuzzyFraction::from_float(0.5).to_string(), "1/2");
assert_eq!(FuzzyFraction::from_float(-1.33).to_string(), "-1 1/3");

assert_eq!(FuzzyFraction::from_ints(1920, 1080).to_string(), "1 7/9");
assert_eq!(FuzzyFraction::from_ints(-10, 31).to_string(), "-1/3");

let ff = FuzzyFraction::from_ints(-1920, 1080);
assert_eq!(ff.to_string(), "-1 7/9");
assert_eq!(ff.ratio_fmt(), "16:9");

No runtime deps