I was previously asked about how to do that, and I could only reply that you have to convert one operand to another, with a care not to truncate or lose precision. I knew that some cases are tricky enough that I felt like writing a crate for that… Well, here it is:

https://crates.io/crates/num-cmp

Clearly this is a niche crate but cannot be done without lots of care anyway. It also supports i128 and u128 with --features i128 (requires nightly). (Interesting fact: f32 's maximal finite exponent is 127, so f32 and u128 's maximal values are roughly same.)

I have tested it with tons of edge values and I’m pretty confident that it is mostly correct, but please do not take my words granted. Any idea or PR to test it better would be welcomed.