Movement against float.init being nan

Steven Schveighoffer schveiguy at gmail.com
Thu Aug 25 17:38:25 UTC 2022


On 8/25/22 12:39 PM, Walter Bright wrote:
> On 8/24/2022 8:08 PM, Steven Schveighoffer wrote:
>> NaN fails at that. It's silently swallowed by just about everything. 
>> Only when a human looks at some printout does it become obvious.
> 
> Seriously, *when* is 0 better than that?
> 
> If you aren't looking at your output, then why are you calculating the 
> value?

Very few programs have a purpose to print an actual floating point 
number as text. Instead they are used for other things.

Another example, let's say you are using a FP calculation to determine 
some sort of timing for bandwidth limiting. You might have something like:

```d
if(val > maxBW) delaySending();
```

If `val` or `maxBW` are NaN, this will always be a false condition 
(because of the wonderful property that comparisons with NaN are always 
false), so that code effectively never executes. Note that there's no 
`printf` here, and the code happily compiles and runs, it just does 
something unexepected.

0 is no better here *but also no worse*.

-Steve


More information about the Digitalmars-d mailing list