[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Zeroes and infinities



Peter Henderson <petercbh@xxxxxxxxxxx> wrote:

If the sign of zero bothers you, ignore it.  It will only cause you 
problems if an overflow occurs and does not resolve itself, in which 
case you will end up with +/-infty or NaN, or if you use copysign, in 
which case you should be paying more attention anyway.  Of course, I am 
assuming you are not a compiler writer, a floating-point hardware 
designer,  a library  routine author or a standards committee member.

No, that is wrong.  The problem is that you CAN'T ignore it, because
IEEE 754, the way that it is interpreted, Java, C99 and so on make
the sign of zero cause wrong answers in all sorts of ways.

Because copysign is defined for zero, language sign functions no
longer give an error - so you don't get told when you make a mistake.

Because IEEE 754 forbids stopping on serious exceptions, and languages
generally can't support its flags (and that DOES include C99), you
have to rely on the values.  And dividing by a zero turns it into a
signed infinity :-(

And then there is the whole morass of C99's bizarre interpretations
of the signs of zero in math.h and, God help us all, complex numbers.


Regards,
Nick Maclaren,
University of Cambridge Computing Service,
New Museums Site, Pembroke Street, Cambridge CB2 3QH, England.
Email:  nmm1@xxxxxxxxx
Tel.:  +44 1223 334761    Fax:  +44 1223 334679

754 | revision | FAQ | references | list archive