float init 0 request
Walter Bright
newshound2 at digitalmars.com
Thu Aug 20 03:36:33 UTC 2026
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.
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.
Option 2 is better when writing professional quality software.
---
I googled "software catastrophe caused by incorrect zero initialization" and got:
"A software catastrophe caused by incorrect zero initialization often relates to
uninitialized memory defaulting to zero unexpectedly, or conversely, a critical
variable failing to be zeroed out or handling a zero value improperly (such as a
division-by-zero or arithmetic counter rollover). A famous analogue is the
September 1997 incident on the guided-missile cruiser USS Yorktown, where a crew
member entered a 0 into a database field, causing a division-by-zero collapse
across the ship's propulsion network."
More information about the Digitalmars-d
mailing list