3

I want to implement a scoring function which returns float like values (but never NaN etc.) and find the minimum values of a list with min_by. As min_by requires its values to implement core::cmp::Ord, I can't use f32 and f64 (which don't have a total ordering).

Is there any floating point alternative in the library implementing core::cmp:Ord and if not, how do I build an alternative that excludes non-real values?

3
  • 1
    There is nothing in the standard library. Does this answer about a wrapper type fit your goal?
    – Shepmaster
    Aug 10, 2015 at 18:19
  • @Shepmaster, does this type prevent its instantiation by other means than NonNan::new, i.e. can I be certain cmp never panics? (In any case, it fits my immediate needs. Thank you so far.)
    – Perseids
    Aug 10, 2015 at 18:30
  • 1
    Outside of the module that it defined in, you can only use the public construction methods, so yes. I'm going to mark this as a duplicate then.
    – Shepmaster
    Aug 10, 2015 at 19:49

0

Browse other questions tagged or ask your own question.