Re: On writing negative zero - with or without sign



James Giles writes:

So the real problem is that people tend to think that programs
can represent, manipulate, or produce metaphysically perfect
"exact" zeros in the first place. Such things are fabulous
monsters.

I sure hope that a program can represent an exact zero. I don't
really care how it does it, just as long as it can. I'm well
aware of the dangers of performing a floating point comparison
between a variable and zero, but if I write:

REAL X,Y
LOGICAL L

X = 0.0
Y = 0.0
L = X == Y

I sure want L to have the value .TRUE.. Of course, the same
would apply to any nonzero value as well. Two variables
initialized to the same value should test as being the same.

But how about this case:

REAL X,Y,Z
LOGICAL L

X = 1.0
Y = 1.0
Z = Y - X
L = X == Y
L = Z == 0.0

Presumably X and Y have the exact same internal representation,
regardless of how close an approximation it has to unity. I
fully expect the first value of L to be .TRUE., but what about
the second value of L? That's where I sure hope that a program
can represent an exact zero, whatever its internal representation
may be, such that the second value of L is also .TRUE.. After
all, when you difference two identical internal representations,
that's my idea of an exact zero, however it may be represented
internally.

The danger arises when you start manipulating a number. For
example,

REAL X,Y
LOGICAL L

X = 1.0
Y = SQRT(X*X)
L = X == Y

In this case, I no longer expect L to have the value .TRUE.,
even though mathematically it should be the case. It probably
will be .TRUE. for certain selected values of X that can be
exactly represented, but for other values, expect .FALSE..

.



Relevant Pages

  • Re: On writing negative zero - with or without sign
    ... exact zero, contrary to your claim that there is no such thing. ... And I noted that there is a subset of continuous reals that can be ... representation to account for "actual zero"). ...
    (comp.lang.fortran)
  • Re: On writing negative zero - with or without sign
    ... I responded to the issue of an "exact" zero. ... that doesn't mean I believe the thermometer example represents a ... Propagate the quantization error of 0.1 degrees. ...
    (comp.lang.fortran)
  • Re: On writing negative zero - with or without sign
    ... exact zero, contrary to your claim that there is no such thing. ... that using float for something *other* than simulating continuous reals ... "exactitude" in general, but rather a very specific issue, namely ...
    (comp.lang.fortran)
  • Re: On writing negative zero - with or without sign
    ... of representing an "exact" zero... ... My definition of an "exact" zero is whatever internal representation ... *only* value associated with that approximation. ... A subset of floating point numbers can have an exact representation. ...
    (comp.lang.fortran)
  • Re: On writing negative zero - with or without sign
    ... I sure hope that a program can represent an exact zero. ... programs represent, manipulate, and produce approximations. ... (which is not what floating point does) ...
    (comp.lang.fortran)