I am not sure if Ratio is supposed to handle negative denominators properly, but the Ord::cmp function does not, see the example below.
use num_rational::Ratio; // 0.4.2
fn main() {
let neg_half = Ratio::<i8>::new_raw(1, -2);
let one_third = Ratio::<i8>::new_raw(1, 3);
println!("{neg_half} is {:?} than {one_third}", neg_half.cmp(&one_third));
println!("{one_third} is {:?} than {neg_half}", one_third.cmp(&neg_half));
}
results in
1/-2 is Greater than 1/3
1/3 is Less than 1/-2
I am not sure if
Ratiois supposed to handle negative denominators properly, but theOrd::cmpfunction does not, see the example below.results in