
Aug. 3, 2016
3:52 p.m.
clamp(val, lo, hi) should raise ValueError if either lo or hi is NaN,
NaN and ValueError are kind of redundant. NaN exists as a way to (kind of) propagate value errors within the hardware floating point machinery. So it _might_ make sense for Python to raise ValueError wherever a NaN shows up, but as long as, e.g. X * NaN Returns NaN, so should clamp() or clip() or whatever it's called. Greg spelled it all out, but in short: If a NaN is passed in anywhere, you get a NaN back. One could argue that: clamp(NaN, x,x) Is clearly defined as x. But that would require special casing, and, "equality" is a bit of an ephemeral concept with floats, so better to return NaN. -CHB