float init 0 request
Steven Schveighoffer
schveiguy at gmail.com
Fri Aug 21 02:36:38 UTC 2026
On Thursday, 20 August 2026 at 03:36:33 UTC, Walter Bright wrote:
> On 8/17/2026 5:59 AM, Indraj Gandham wrote:
>> it's more likely you wanted 0.0 than NaN. In fact, NaN is
>> almost guaranteed to be incorrect
>
> And that is exactly the point of NaN - to be incorrect, and to
> stand out like a rock in your shoe.
>
>
>> D has many facets which make it the best programming language
>> in the world. This is not one of them.
>
> Consider the two options:
>
> 1. default initialize to 0, because that will be correct most
> of the time. Never mind if the flight computer says 18,000
> gallons of gas is needed to cross the Atlantic, when 20,000 is
> actually needed. But 18,000 looks good, and you take off, get
> past the halfway point, and fall out of the sky.
This contrived almost impossible to occur scenario where zero
somehow equates to a factor of 2000 which was not caught in
testing is not convincing.
> 2. default initialize to NaN, and your flight computer says you
> need NaN gallons of gas, and you turn around and go immediately
> back to the gate.
I can play too:
```d
if(gas < amountNeeded) warnPilot();
```
-Steve
More information about the Digitalmars-d
mailing list