From: David Masover Date: 2010-11-25T08:17:10+09:00 Subject: Re: Ruby 1.8 vs 1.9 On Wednesday, November 24, 2010 01:35:12 pm Josh Cheek wrote: > On Wed, Nov 24, 2010 at 1:16 PM, Phillip Gawlowski < > > cmdjackryan@googlemail.com> wrote: > > On Wed, Nov 24, 2010 at 8:02 PM, Josh Cheek wrote: > > > Its wrongness is an interpretation (I would also prefer that it just > > > > break, > > > > > but I can certainly see why some would say it should be infinity). And > > > it > > > > > doesn't apply only to Ruby: > > It cannot be infinity. It does, quite literally not compute. There's > > no room for interpretation, it's a fact of (mathematical) life that > > something divided by nothing has an undefined result. It doesn't > > matter if it's 0, 0.0, or -0.0. Undefined is undefined. > > From my Calculus book (goo.gl/D7PoI) > > "by observing from the table of values and the graph of y = 1/x*²* in > Figure 1, that the values of 1/x*²* can be made arbitrarily large by > taking x close enough to 0. Thus the values of f(x) do not approach a > number, so lim_(x->0) 1/x*²* does not exist. To indicate this kind of > behaviour we use the notation lim_(x->0) 1/x*²* = ∞" Specifically, the _limit_ is denoted as infinity, which is not a real number. > Since floats define infinity, regardless of its not being a number, it is > not "absurd to the extreme" to result in that value when doing floating > point math. Ah, but it is, for two reasons: First, floats represent real numbers. Having exceptions to that, like NaN or Infinity, is pointless and confusing -- it would be like making nil an integer. And having float math produce something which isn't a float doesn't really make sense. Second, 1/0 is just undefined, not infinity. It's the _limit_ of 1/x as x goes to 0 which is infinity. This only has meaning in the context of limits, because limits are just describing behavior -- all the limit says is that as x gets arbitrarily close to 0, 1/x gets arbitrarily large, but you still can't _actually_ divide x by 0. They didn't teach me that in Calculus, they're teaching me that in proofs. > > That other languages have the same issue makes matters worse, not > > better (but at least it is consistent, so there's that). > > The question was "Is there anything in the above which applies only to Ruby > and not to floating point computation in another other mainstream > programming language?" the answer isn't "other languages have the same > issue", it's "no". I don't know that there's anything in the above that applies only to Ruby. However, Ruby does a number of things differently, and arguably better, than other languages -- for example, Ruby's integer types transmute into Bignum rather than overflowing.