News for hackers. Stuff that matters.
Re:Beating Floating Point at Its Own Game: Posit Arithmetic ... by RhysU on Saturday July 01, 2017 @08:20AM (#14676789)
> If a programmer finds the need for NaN values, it indicates the program is not yet finished...

These guys have never allreduced a timestep in a simulation where something can go aphysical.

I mean, sure, one can communicate aphysical conditions using out-of-band means. But it is so pretty when it just rides along for free as a NaN result.

Edit: I stand corrected having looked up authors. I still think having float effectively be Maybe[float] is a feature not a bug.

Re:Beating Floating Point at Its Own Game: Posit Arithmetic ... by psykotic on Saturday July 01, 2017 @08:41PM (#14680047)
Quiet NaN is critically different from the Maybe monad's Nothing value. Maybe gives you proper exception semantics even if it's implemented by means of predicated data flow rather than early-out control flow (and in a pure, non-strict language like Haskell there isn't a real distinction between data flow and control flow). Whereas quiet NaNs have a significant issue with non-termination where you have to very carefully express all your loop conditions positively. For example, 'while (x - y > eps)' will terminate if either x, y or eps are NaN, but any code that relies on 'if (positive_condition) break' and similar constructs for termination will loop or recurse forever if the condition operands become NaN.

A closer analogue of NaN might be the x ("unknown") value in the three/four-valued logic of hardware simulation languages like Verilog. But the situation in Verilog, despite its challenges, is so much better since you don't have a hard discontinuity between "numbers" and "logical values". Numerical comparisons between unknowns can produce unknown logical values, and you have equations like true & unknown = unknown, true | unknown = true, ~unknown = unknown, etc, so you don't have the issue with NaNs where as soon as something crosses from the floating-point realm to the integer or logical realm, it has to commit to a definite value, with all the aforementioned issues.

All that said, NaNs were the right design choice given the constraints. But it's far from ideal.