Movement against float.init being nan

claptrap clap at trap.com
Fri Aug 19 23:11:35 UTC 2022


On Friday, 19 August 2022 at 18:04:46 UTC, bachmeier wrote:
> On Friday, 19 August 2022 at 17:14:35 UTC, Steven Schveighoffer 
> wrote:
>
>> I also would prefer that all floats/doubles default to 0 
>> instead of NaN.
>
> It would be awful to choose an arbitrary, often incorrect value 
> in order to give the appearance that your program is running.

Any default value is an incorrect value unless it by luck happens 
to be what the programmer intended it to be. So while zero will 
often be incorrect I would argue that NaN is almost guaranteed to 
be incorrect.

And here's the thing, you find some numerical code you've written 
and change some variable to zero init in instead of whatever it 
was. Your program wont appear to run properly, it'll give 
incorrect results, things wont work.

There's this whole fallacy underpinning the default to NaN 
argument that using zero init will somehow leave programming 
appearing to run fine with no obvious problems.

its nonsense.


> It would be absurd to silently set the value of `z` to 1.0 in 
> this code:
>
> ```
> double w;
> double z = w*2.5 + 1;
> ```
>
> Defaulting to 0 is no better than defaulting to a random number.

What's absurd that the whole point of using NaN as an init value 
is to catch a bug that could much more easily be caught by 
requiring explicit initialisation of floats.

double w; // compiler says NO!




More information about the Digitalmars-d mailing list