Home > programming > Is IEE 754 too advanced?

Is IEE 754 too advanced?

August 24th, 2007

In my previous post I’m afraid I exposed my inexperience in the world of floating point programming. As many pointed out it’s the inherited behavior of the IEEE 754 standard, and, in Walter Brights own words, to change it would break legacy usage. In other words I should direct my concerns about the handling of uninitialized values toward the standard and not hold the D Programming Language responsible.

I still feel awkward, and to some extent astonished, that I can use an expression like (x != x) to check for an initialized floating point value, but not (x != real.nan). This behavior goes against my intuition.

NaN is defined to return false for all the normal comparison operators. The standard would have been better – in my opinion – if it made an exception for the equality (==) and not equality (!=) operators. It would save many of us from being caught by surprise.

Anyway, I guess you can’t fight an IEEE standard, so I hereby drop my case. 🙂


I read up on NaN:s in the IEEE 754 specification and found that Not A Number is not necessarily represented by one single value, but rather it could be a whole family of them. That complicates things, but the final nail in the coffin was put by Lars Noshinski on the official D newsgroup. He puts it in this convincing way:

“But you’d probably be surprised to see

0.0/0.0 == sqrt(-1.L)

evaluate to true.”

There is no arguing against that. So I guess the answer to the question in the title is: No, the IEEE 754 is just as advanced as it needs to be.

Update 2:

If you (like me) want to learn more about floating point numbers, there is a great sum up in the What Every Computer Scientists Should Know About Floating-point Arithmetic.

Be Sociable, Share!
Categories: programming Tags:
Comments are closed.