Re:Rust 1.50
by masklinn on Thursday February 11, 2021 @03:14PM
(#26106527)
I guess because floats implement PartialOrd, not Ord, and what would you return if one of self, min, and max is non-ordered? Returning an `Option<T>` would usually be inconvenient.
Therefore clamp is implemented on Ord (meaning there's always a value to return), and there's an efficient implementation on floats which can define its behaviour with respect to NaN.
Therefore clamp is implemented on Ord (meaning there's always a value to return), and there's an efficient implementation on floats which can define its behaviour with respect to NaN.
If you want the actual details,
* https://internals.rust-lang.org/t/clamp-function-for-primiti...
* https://github.com/rust-lang/rust/issues/44095