Dividing By Infinity
Solution 1:
Dividing by infinity is fine - it's zero.
Unless you're dividing infinity by infinity, which is undefined (in general at least)
Solution 2:
I think that's a bug in IE. According to the rules of IEEE math, n/Inf=0 (for n!=0). So if IE croaks over this, it's a problem in IE. On the other hand, using Inf in ordinary mathematical operations is problematic, and you'd be better off if your code didn't rely on it in the first place.
Why is it dangerous? Well, for starters, according to IEEE 754:
1/0=Inf1/-0=-Inf
but we know that 0 = -0, hence
Inf = -Inf
which is obviously undesirable. IEEE did not mean to make Inf an ordinary number anyway. Inf and NaN exist to make floating point arithmetics in computers with its inherent limited precision and overflow issues resemble ordinary-world arithmetics, where, to take the simplest example, the set of real numbers is closed under addition (adding two real numbers always results in another real number). If you do that with finite-precision floats, you'll get cases where adding two numbers results in an overflow. To avoid having to treat this as an error condition, IEEE introduced two extra symbols, Inf and NaN, and a set of rules for their behaviour. Now the result of a mathematical operation is always a number, or Inf, or NaN, and whether the result makes any sense or not is left to the user.
Solution 3:
Dividing a number by infinity is perfectly reasonable from a mathematical perspective. It is a number infinitely close to zero, without actually reaching zero.
From a software perspective, this is much more difficult, as infinity is not a discretely representable value. My guess would be that your difference in behavior is based on design decisions.
In Firefox, they probably chose to return a value of zero, since for all practical purposes, this result will work for what you need.
In IE, on the other hand, it appears the developers made the conscious decision to not allow you to perform a calculation that they knew they could not give a discrete answer for.
Post a Comment for "Dividing By Infinity"