Movement against float.init being nan

bauss jacobbauss at gmail.com
Thu Aug 25 07:15:58 UTC 2022


On Thursday, 25 August 2022 at 03:08:54 UTC, Steven Schveighoffer 
wrote:
>
> A better option would be to throw an exception if NaN is used 
> in an operation.
>
> -Steve

IMHO this is the better solution and not even an exception, but 
Error.

As soon as you have any NaN values that are being used your 
program is effectively useless and broken.

I think as soon as any variable becomes NaN it should throw, not 
just when an operation happens.

Basically I think it should throw when either of these conditions 
holds true:

- A value was initialized as NaN and used in an operation
- A value was set to NaN outside of initialization
- NaN is returned from a function (Even if not set to a variable 
or anything.)

This will solve all problems because:

- You will never have a NaN value propagate throughout your 
program, making it much easier to track it back to its roots.
- NaN strictly tells you that some value is wrong before it's 
even being used
- There's no way to workaround it effectively, meaning you must 
actually fix any places where NaN is possible.


More information about the Digitalmars-d mailing list