|
|
Up |
|
|
  |
Author: norb1norb1 Date: Aug 27, 2006 18:19
After tracking down a bug in my Fortran program, I found that it
assumed
max(NaN,0.) = 0.
This makes no sense, as the outcome of the operation is undefined and
should be NaN.
max(NaN,0.) = NaN
After researching, it appears the first outcome is accepted behavior,
and might be included in the revised IEEE 754 standard, which affects
not only Fortran. The discussion posted at
www.cs.berkeley.edu/~ejr/Projects/ieee754/meeting-minutes/02-11-21.html#minmax
suggests that "There is no mathematical reason to prefer one reason to
another."
But I think otherwise, for the following reason. Suppose the NaN is
produced by x/y, where x=0 came from an underflow and y=0 came from an
underflow. Then x/y would be a well-defined number that could be
postive or negative. The convetion max(NaN,0.) = 0. is wrong at least
half the time.
|
| |
|
| | 99 Comments |
|
  |
Author: P.J. PlaugerP.J. Plauger Date: Aug 27, 2006 18:51
> After tracking down a bug in my Fortran program, I found that it
> assumed
> max(NaN,0.) = 0.
>
> This makes no sense, as the outcome of the operation is undefined and
> should be NaN.
> max(NaN,0.)...
|
| Show full article (1.23Kb) |
|
| | no comments |
|
  |
Author: Steven G. KarglSteven G. Kargl Date: Aug 27, 2006 18:54
> This makes no sense, as the outcome of the operation is undefined and
> should be NaN.
> max(NaN,0.) = NaN
Why?
Don't take this the wrong way. But, the members of the IEEE754
committee probably have much more experience than you (and
many of the people here in c.l.f) in floating point mathematics.
If they came to the conclusion that
"There is no mathematical reason to prefer one reason to another."
then you may want to pay attention to them, and guard against
suspect comparisons.
|
| Show full article (1.46Kb) |
| 43 Comments |
|
  |
Author: Dan NagleDan Nagle Date: Aug 27, 2006 20:01
Hello,
Steven G. Kargl wrote:
> AFAIK, Fortran does not have hysteresis. It does not know
> or care how you got to x = 0 and y = 0. All it tries to
> do is evaluate x/y. This is a NaN.
Note that this is true, *even if the x/y were an argument
of the max()*.
The compiler must evaluate the values of the arguments,
next associate the values with the dummy arguments,
next call the function.
"History is just one damn thing after another." :-)
--
Cheers!
Dan Nagle
Purple Sage Computing Solutions, Inc.
|
| |
| no comments |
|
  |
Author: ejko123ejko123 Date: Aug 27, 2006 20:10
> After tracking down a bug in my Fortran program, I found that it
> assumed
> max(NaN,0.) = 0.
>
> This makes no sense, as the outcome of the operation is undefined and
> should be NaN.
> max(NaN,0.) = NaN
A standard-conforming Fortran processor is allowed to evaluate
max(x,y) as
if(x > y) then
max = x
else
max = y
endif
If x is NaN, then x > y is unordered (i.e., it is not true in IEEE
arithmetic).
The ELSE branch is taken, so max(NaN,0.0) = 0.0.
--Eric
|
| |
| 13 Comments |
|
  |
Author: Tim PrinceTim Prince Date: Aug 27, 2006 20:32
> After tracking down a bug in my Fortran program, I found that it
> assumed
> max(NaN,0.) = 0.
>
> This makes no sense, as the outcome of the operation is undefined and
> should be NaN.
> max(NaN,0.) = NaN
>
> After researching, it appears the first outcome is accepted behavior,
> and might be included in the revised IEEE 754 standard, which affects
> not only Fortran. The discussion posted at
> www.cs.berkeley.edu/~ejr/Projects/ieee754/meeting-minutes/02-11-21.html#minmax
> suggests that "There is no mathematical reason to prefer one reason to
> another."
|
| Show full article (0.99Kb) |
| no comments |
|
  |
Author: Ron ShepardRon Shepard Date: Aug 27, 2006 20:57
> The convetion max(NaN,0.) = 0. is wrong at least
> half the time.
But by your argument, the convention Max(NaN,0.)=NaN would be wrong
the other half. That is probably why they concluded
"There is no mathematical reason to prefer one reason to another."
$.02 -Ron Shepard
|
| |
| 1 Comment |
|
  |
Author: norb1norb1 Date: Aug 27, 2006 21:33
Ron Shepard wrote:
>> The convetion max(NaN,0.) = 0. is wrong at least
>> half the time.
>
> But by your argument, the convention Max(NaN,0.)=NaN would be wrong
> the other half.
|
| Show full article (1.01Kb) |
| no comments |
|
  |
Author: highegghighegg Date: Aug 27, 2006 22:45
> After researching, it appears the first outcome is accepted behavior,
> and might be included in the revised IEEE 754 standard, which affects
> not only Fortran. The discussion posted at
> www.cs.berkeley.edu/~ejr/Projects/ieee754/meeting-minutes/02-11-21.html#minmax
> suggests that "There is no mathematical reason to prefer one reason to
> another."
>From the above minutes:
--------------------------------------------
Kahan proposed two mathematical characterizations for max over the
reals plus points at +/-inf which can be extended to NaNs:
1. z := Max{x, y} iff z <= x or z <= y
2. z := Max{x, y} iff z >= x and z >= y
Using the first definition, Max{5, NaN} = 5. Under the second
definition, Max{5, NaN} = NaN. There is no mathematical reason to
prefer one reason to another.
---------------------------------------------
I don't understand 1. - doesn't look like a correct Max definition to
me (even if the missing "z belongs to {x,y}" is added).
Jaroslav
|
| |
| no comments |
|
  |
|
|
  |
Author: Christer EricsonChrister Ericson Date: Aug 27, 2006 23:06
> [...]
> A standard-conforming Fortran processor is allowed to evaluate
> max(x,y) as
>
> if(x > y) then
> max = x
> else
> max = y
> endif
>
> If x is NaN, then x > y is unordered (i.e., it is not true in IEEE
> arithmetic).
> The ELSE branch is taken, so max(NaN,0.0) = 0.0.
Is that how max is defined by the standard? if not, if your
processor instead evaluates max(x,y) as
|
| Show full article (0.80Kb) |
| 12 Comments |
|
RELATED THREADS |
  |
|
|
|
|
|