float init 0 request

Walter Bright newshound2 at digitalmars.com
Sat Aug 15 22:48:11 UTC 2026


On 8/15/2026 6:28 AM, monkyyy wrote:
> On Saturday, 15 August 2026 at 04:42:24 UTC, Walter Bright wrote:
>> Some outside opinions:
>>
>> https://stackoverflow.com/questions/1036686/is-it-a-good-idea-to-use-ieee754-floating-point-nan-for-values-which-are-not-set
> 
> We dont care about outsider theory, our **repeated** *personal* **experience** 
> is that nan passed to a graphics api is a no op and its one of the slowest thing 
> to debug. adr ran into it on camera, steve-l guy teachs kids raylib and sees the 
> repeat again and again, etc etc etc etc

Sorry you had a bad initial experience with this.

Default initialization is not the only way a NaN can be appear in floating point:

https://en.wikipedia.org/wiki/NaN#Operations_generating_NaN

There's no getting away from dealing with NaNs. Default initialization to zero 
is not going to make that go away. The std.math functions are all carefully 
crafted to correctly deal with NaNs.

As for the graphics case, what happened is the error showed itself immediately, 
which is much better than having a subtle unintended 0 initialization that may 
go undetected for years.

BTW, I like it when checking in a piece of code, and then the test suite 
promptly fails. To find the problem, I use a binary search on the PR to find out 
where the source is. This can be automated by using Dustmite:

https://blog.dlang.org/archive/2020/04/13/dustmite-the-general-purpose-data-reduction-tool/

> C dev's reading a spec and dreaming has less evidential weight then a new 
> programmer running into this once.

New programmers need to learn about NaN anyway.

There's no reason to believe that a 0.0 is always correct, and debugging it will 
be a lot harder.


More information about the Digitalmars-d mailing list