Crates.io | fuzzy_fraction |
lib.rs | fuzzy_fraction |
version | 0.1.2 |
source | src |
created_at | 2021-11-30 14:16:14.939703 |
updated_at | 2023-07-17 15:21:31.33756 |
description | Struct for approximated human-readable fraction representation.. |
homepage | |
repository | https://github.com/p4ymak/fuzzy_fraction |
max_upload_size | |
id | 489803 |
size | 11,538 |
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");