From: Joel VanderWerf Date: 2009-09-19T16:28:42+09:00 Subject: [ruby-core:25646] Re: [Bug #2121] mathn/rational destroys Fixnum#/, Fixnum#quo and Bignum#/, Bignum#quo Charles Nutter wrote: > The mathn library replaces Fixnum#/ and Bignum#/ causing them to > return a different value. When the result of a division is not an > integral value, the default versions will return 0. I can think of > many algorithms that would use this expectation, and most other > languages will not upconvert integral numeric types to floating-point > or fractional types without explicit consent by the programmer. > > When requiring 'mathn', Fixnum#/ and Bignum#/ are replaced with > versions that return a fractional value ('quo') causing a core math > operator to return not just a different type, but *a different > value*. > > No core library should be allowed to modify the return value of core > numeric operators, or else those operators are worthless; you can't > rely on them to return a specific value *ever* since someone else > could require 'mathn' or 'rational'. Perhaps it should be the responsibility of users of numeric operators to #floor explicitly when that is the intent, rather than rely on the (mostly standard, sometimes convenient, but questionable) 1/2==0 behavior. Doing so would make it easier to adapt the code to float, rational, or other numeric types. In your proposal, would Rational(1,3) be the preferred notation, since 1/3==0? Or would there be something else, 1//3 or ...? I've always thought of mathn as a kind of alternate ruby, not just another core library, hence to be used with caution... -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407