floating point - nan initializers

Anders F Björklund afb at algonet.se
Sun Feb 19 10:58:02 PST 2006


Ivan Senji wrote:

> In that case 0 is as bad as anything else. Atleast with nan, a developer 
> may decide to print sum to console and find out that it is nan. But what 
> if the formula is
> sum = sum*dx + dy; -> this will cause subtle errors if you expected sum 
> to be 1 for example. But you will get some numbers as a result but they 
> are wrong even though you think they are allright, and the next thing 
> you know your D-driven spaceship is falling onto Mars too fast and you 
> are loosing alot of money an thinking: if only that sum was initialized 
> to nan! :)

Then again, it's usually better to catch those bugs at compile time ?

Like in Java: (jikes compiler)
*** Semantic Error: The variable "sum" may be accessed here before 
having been definitely assigned a value.

Sometimes I think D has too many runtime errors, waiting to happen...

--anders



More information about the Digitalmars-d mailing list