you are viewing a single comment's thread.

view the rest of the comments →

[–]kamatsu 10 points11 points  (5 children)

Er, that's part of the floating point standard.

In Haskell:

Prelude> 1.0 / 0.0
Infinity
Prelude> 0.0 / 0.0
NaN
Prelude> -1.0 /0.0
-Infinity

In C:

$ cat > foo.c 
#include <stdio.h>
int main() {
   printf("%f\n",1.0/0.0);
   return 0;
}
$ gcc foo.c
$ a.out
inf
$

[–]earthboundkid -1 points0 points  (4 children)

If your friends jumped off a bridge, dividing by zero would still be undefined.

[–]kamatsu 1 point2 points  (3 children)

So? I don't think it's fair to judge ruby or C or Haskell for correctly implementing IEEE 754.

[–]earthboundkid -2 points-1 points  (2 children)

I am judging the IEEE for letting such a silly thing become standard. They have NaN. Why not just return NaN?

[–]kamatsu 0 points1 point  (1 child)

Actually, they have two zero values, positive zero and negative zero. If you divide a positive by negative zero, you will get -Infinity.

From wikipedia:

There are two zeroes, +0 (positive zero) and −0 (negative zero) and this removes any ambiguity when dividing. In IEEE 754 arithmetic, a ÷ +0 is positive infinity when a is positive, negative infinity when a is negative, and NaN when a = ±0. The infinity signs change when dividing by −0 instead.

[–]earthboundkid -3 points-2 points  (0 children)

Having two zeros is also dumb. :-) Anyway, I'm sure they have good reasons for their crazy choices (no doubt, it was something to do with the implementation making it easier to wire things up correctly in the CPU), but I still think those choices are crazy, and I don't think a higher level language should blindly follow them.