News for hackers. Stuff that matters.
Re:Rust 1.50 by coldtea on Thursday February 11, 2021 @02:53PM (#26106264)

  pub fn clamp(self, min: f64, max: f64) -> f64
Rust has generics iirc, so why there's this?
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.

If you want the actual details,

* https://internals.rust-lang.org/t/clamp-function-for-primiti...

* https://github.com/rust-lang/rust/issues/44095

Re:Rust 1.50 by pornel on Thursday February 11, 2021 @04:02PM (#26107119)
Also the float implementation was chosen to optimize well with SSE, even in presence of NaNs.