4 ms·
> This means that NaNs propagate from the source of the original NaN to the final printed result. An exception would be better. Then you immediately get at the
by inetknght 4y ago
> This means that NaNs propagate from the source of the original NaN to the final printed result.
An exception would be better. Then you immediately get at the first problem instead of having to track down the lifetime of the observed problem to find the first problem.
- insulanus 4y agoDefinitely. Unfortunately, Language implementations that guaranteed exceptions were not in wide use at the time. Also, to have a chance at being implemented on more than one CPU, it had to work in C and assembly.
- thfuran 4y agoYeah, or using a type system that lets you avoid making NaN a float to both force the case to be handled and prevent NaN from leaking into the math.
- jcranmer 4y agoYou can get an exception! Just enable FP exceptions for the invalid exception, and compile all of your code such that it's FP-exception aware, and you can get the exception.
- BeetleB 4y ago> An exception would be better. It depends on the context. Sometimes NaNs are expected and to be ignored. Sometimes they signal a problem.