Re: On writing negative zero - with or without sign
- From: tholen@xxxxxxxxxxxx
- Date: 16 Jul 2007 21:11:10 GMT
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..
.
- Follow-Ups:
- Re: On writing negative zero - with or without sign
- From: James Giles
- Re: On writing negative zero - with or without sign
- References:
- On writing negative zero - with or without sign
- From: Jerry DeLisle
- Re: On writing negative zero - with or without sign
- From: robert . corbett
- Re: On writing negative zero - with or without sign
- From: Richard Maine
- Re: On writing negative zero - with or without sign
- From: robert . corbett
- Re: On writing negative zero - with or without sign
- From: Richard Maine
- Re: On writing negative zero - with or without sign
- From: Terence
- Re: On writing negative zero - with or without sign
- From: Ron Shepard
- Re: On writing negative zero - with or without sign
- From: James Giles
- On writing negative zero - with or without sign
- Prev by Date: Re: fortran compilers
- Next by Date: Re: Reading an image array.
- Previous by thread: Re: On writing negative zero - with or without sign
- Next by thread: Re: On writing negative zero - with or without sign
- Index(es):
Relevant Pages
|
|