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?

Perseids
  • 12,584
  • 5
  • 40
  • 64
  • 1
    There is nothing in the standard library. Does [this answer about a wrapper type](http://stackoverflow.com/a/28248065/155423) fit your goal? – Shepmaster Aug 10 '15 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 '15 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 '15 at 19:49

0 Answers0