Re: Numerics, NaNs, IEEE 754 and C99



On 2006-06-14, Christophe <chris.cavalaria@xxxxxxx> wrote:
Grant Edwards a écrit :
The division by zero trap is really annoying. In my world the
right thing to do is to return Inf.

Your world is flawed then, this is a big mistake. NaN is the
only aceptable return value for a division by zero.

You're probably right if you're talking about math, but I'm not
doing math. I'm doing engineering. In all of the situations
I've ever encountered, Inf was a much better choice.

Aside from Python, every FP library or processor I've ever used
returned Inf for divide by zero (which is the behavior required
by IEEE 754).

I need my Python programs to work the same way as everything
else.


http://standards.ieee.org/reading/ieee/interp/754-1985.html

In IEEE Std 754-1985, subclause 7.2- Division by Zero, it says:

"If the divisor is zero and the dividend is a finite nonzero
number, then the division by zero shall be signaled. The
result, when no trap occurs, shall be a correctly signed
(infinity symbol)(6.3)."

While this is apparently the convention decided on by the
committee, it is mathematically incorrect and it seems as if
it should have been designated as Not-a-Number, since
division by zero is mathematically undefined and implies that
0*infinity=1, which is patently absurd.

Why was this convention chosen instead of NaN, since it leads
to a further degradation of our children's math abilities,
given that the IEEE floating-point standard would be considered
to be authoritative on this subject, yet produces an erroneous
results.

Interpretation for IEEE Std 754-1985

When a non-zero number is divided by a zero number, that is a
divide by zero. It is interpreted as an attempt to
take a limit of the ratio of two numbers as the denominator
becomes too small to be represented in the number system
while the numerator remains representable. Such a limit is best
represented by an infinity of the appropriate sign.

When zero is divided by zero, no such extrapolation can be
made. If it is caused by an attempt to take the limit of
the ratio of two numbers when both become two small to be
represented, then the limit cannot be determined. If it
is caused by some mistake in the programming, then no limit
exists. Thus, this case is thought to be invalid and a NaN
of appropriate sign is returned. (The sign is the only bit of
information that can be determined.)

While counter examples to the mathematical interpretation of
both of these results can be constructed they tend to be either
the result of extreme scaling or an attempt to evaluate a
non-analytic function. The former can be resolved by
rescaling. But, as the latter involve functions that cannot
(formally) be evaluated on a computer (without extreme effort
anyway) in the region of their non-analyticity, usually no good
solution exists.

--
Grant Edwards grante Yow! I represent a
at sardine!!
visi.com
.



Relevant Pages

  • Re: Im always a winner
    ... If black is not a color then zero is not a number. ... Divide by zero in any equation and you get ... NaN is that it isn't equal to anything, including itself, so you can't ... opposite signs or subtract an infinite value from another with the ...
    (alt.usage.english)
  • Re: Im always a winner
    ... Divide by zero in any equation and you get ... so you can't just check it against a NaN you happen to have ... True, but then infinity isn't a number either, ...
    (alt.usage.english)
  • Re: NAN
    ... divide by zero in the box score somewhere. ... Any computers running C, C++ or Java. ... Nan - the most powerful number in computing: ...
    (alt.sports.baseball.bos-redsox)
  • Re: Im always a winner
    ... If black is not a color then zero is not a number. ... NaN is that it isn't equal to anything, including itself, so you can't ... that's only the value if you divide zero by zero. ... opposite signs or subtract an infinite value from another with the ...
    (alt.usage.english)
  • Re: Finding sups and infs
    ... The inf is clearly zero also since the terms are strictly decreasing ... Obviously the sup is 0. ... But how do I find the inf? ... (It might be more sensible to divide it up slightly differently, ...
    (sci.math)

Loading