In rust, is there a version of f32 / f64 that implements Eq?
The only reason I can see for f32 / f64 not implementing Eq is that NaN != NaN.
Potential ways such a type could behave:
- The type could just make
NaN == NaNfor that type which would be really useful because I often assume thata == ais always true. - Another approach would be to disallow
NaNentirely in that type so that there is noNaNthat could be unequal to itself.
Ideally there would be a way to use that type just by using a suffix (similar to 2.3_f32) but I don't think that is possible.
Since Rust 1.62.0, you can use the
total_cmp()methods off32andf64. Not a type on their own, but you can build a type on top of them if you want.Or you can use the
ordered-floatcrate. It provides theNotNanandOrderedFloattypes, each matching one behavior you described.