max(NaN,0) should be NaN
  Home FAQ Contact Sign in
comp.lang.fortran only
 
Advanced search
POPULAR GROUPS

more...

comp.lang.fortran Profile…
 Up
max(NaN,0) should be NaN         


Author: norb1
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
Re: max(NaN,0) should be NaN         


Author: P.J. Plauger
Date: Aug 27, 2006 18:51

yahoo.com> wrote in message
news:1156727969.608759.80730@m73g2000cwd.googlegroups.com...
> 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
Re: max(NaN,0) should be NaN         


Author: Steven G. Kargl
Date: Aug 27, 2006 18:54

In article <1156727969.608759.80730@m73g2000cwd.googlegroups.com>,
norb1@yahoo.com writes:
> This makes no sense, as the outcome of the operation is undefined and
> should be NaN.
> max(NaN,0.) = NaN

Why?
> 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."

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
Re: max(NaN,0) should be NaN         


Author: Dan 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
Re: max(NaN,0) should be NaN         


Author: ejko123
Date: Aug 27, 2006 20:10

norb1@yahoo.com wrote:
> 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
Re: max(NaN,0) should be NaN         


Author: Tim Prince
Date: Aug 27, 2006 20:32

norb1@yahoo.com wrote:
> 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
Re: max(NaN,0) should be NaN         


Author: Ron Shepard
Date: Aug 27, 2006 20:57

In article <1156727969.608759.80730@m73g2000cwd.googlegroups.com>,
norb1@yahoo.com 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. That is probably why they concluded

"There is no mathematical reason to prefer one reason to another."

$.02 -Ron Shepard
1 Comment
Re: max(NaN,0) should be NaN         


Author: norb1
Date: Aug 27, 2006 21:33

Ron Shepard wrote:
> In article <1156727969.608759.80730@m73g2000cwd.googlegroups.com>,
> norb1@yahoo.com 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
Re: max(NaN,0) should be NaN         


Author: highegg
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
Re: max(NaN,0) should be NaN         


Author: Christer Ericson
Date: Aug 27, 2006 23:06

In article <1156734621.572922.27910@m79g2000cwm.googlegroups.com>,
ejko123@yahoo.com says...
> [...]
> 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
SubjectArticles qty Group
Re: debt free, maxed 401k, maxed IRAmisc.invest.financialplan ·
1 2 3 4 5 6 7 8 9