[LCP]Negative zero problem

Chuck Martin nrocinu at myrealbox.com
Mon Oct 29 19:59:08 UTC 2001


I tried mailing this several times before, but it never seemed to get
through.  I now have a new address, so maybe it will get through from
here (I'm wondering if it was being blocked due to a misguided attempt
to block spam).

I'm working on a program (the public domain spreadsheet, sc, if anyone's
interested) that contains the following snippet:

    if (val < 0.0) {
        negative = true;
        val = -val;
    }

This appears to be related to a bug that I'm trying to track down, so
I inserted some diagnostic code both immediately before and immediately
after this snippet that uses fprintf to print the value of val to stderr,
which I redirect to another virtual console when I start the program.
The bug only seems to occur when val (which is a double) should be 0,
and in the case where the bug occurs, for some reason, the value is
displayed as -0 both before and after (using a conversion specifier of
%.15g).  How is this possible?  Could someone explain what's going on
here?  If I insert diagnostic code inside the snippet, it never gets
executed, so the test must be false, so why does the fprintf (or any
of the other functions in the printf family) prefix the "-"?

Chuck




More information about the linuxCprogramming mailing list