Re:Math.min(Math.max(num, min), max)
by taberiand on Thursday August 20, 2020 @05:12PM
(#24229047)
Having a NaN at that point feels like a bug anyway, the solution is probably to check the arguments and throw an exception if NaN is provided (or use an input type that doesn't allow invalid values)
[ Parent
| on HN ]
That would depend on what you do with the NaNs. For instance I have been using them extensively in time series data representation to denote a specific entry has no value - think of Saturday and stock/forex markets.
Re:Math.min(Math.max(num, min), max)
by moron4hire on Friday August 21, 2020 @08:30AM
(#24234318)
That's not what NaN means. It means there is a value, and that value is... Check this out... "Not a Number".
Recording the lack of a value is what null is for.
Null does not pertain to primitive types in java and in C - it'd be zero when applied to a 'double'. (note: you want double[] as backing storage in java and you absolutely do not indirections). Aside that I have quite a good idea how NaN is represented internally and what it does, e.g. you can have several different NaNs that have different representation bitwise. Baring that - NaNs are pretty decent to represent lack of value as all operations with them result into a NaN. In the end NaN is just a composition of bits that the hardware can optimize for.