[Haskell-cafe] How odd...
ok
ok at cs.otago.ac.nz
Mon Aug 6 01:28:14 EDT 2007
On 5 Aug 2007, at 5:26 am, Andrew Coppin wrote:
>
> Infinity times any positive quantity gives positive infinity.
> Infinity times any negative quantity gives negative infinity.
> Infinity times zero gives zero.
>
> What's the problem?
That in IEEE arithmetic, infinity times zero is *NOT* zero.
Everything becomes clear if you think
+0 = some non-standard real bigger than 0 but smaller than
any standard positive real, a possibly different one
every time
-0 = some non-standard real smaller than 0 but bigger than
any non-standard negative real, a possibly different
one every time
+oo = 1/(+0), remembering that this is a possibly different one
each time
-oo = 1/(-0)
So +oo * +0 is (1/eps1) * eps2 = eps2/eps1 which could have *any*
positive non-standard real value.
>> Consider 0.0 / 0.0, which also evaluates to NaN.
>
> Division by zero is *definitely* undefined.
No, division by zero is perfectly well defined in IEEE arithmetic.
If x is a strictly positive number then x/(+0) = +Infinity.
If x is a strictly negative number then x/(+0) = -Infinity.
positive/(-0) = (-positive)/(+0) = -Infinity.
negative/(-0) = (-negative)/(+0) = +Infinity.
Once again, everything becomes clear when you realise that IEEE
arithmetic doesn't really represent 0 but instead has a pair of
non-standard reals one on either side (except that you can never
depend on exactly what the value is).
So 1/(+0) is clearly 1/eps1 = some big non-standard real = +Infinity,
but +0/+0 is eps1/eps2 and we don't know what that is.
I know that the signed zero and infinities stuff is mathematically odd,
but it's closely related to the ability to write floating point stuff
without exception handling, so that if at the end you got NaN something
went wrong (and you need to try another method), otherwise it didn't.
The C99 standard (a draft of which is easy to find on the web) is
perhaps
the easiest place to find out what this means for functions other than
the classical arithmetic operations.
(Personally I've always thought that sqrt(-0) = -0 was more confusing
than
anyone needed, but I can see why they did it.)
More information about the Haskell-Cafe
mailing list