From: Jim Freeze Date: 2003-04-19T20:45:36+09:00 Subject: Re: Bug in Rational? On Saturday, 19 April 2003 at 10:57:07 +0900, Yukihiro Matsumoto wrote: > Hi, > > In message "Bug in Rational?" > on 03/04/19, "Chris Pine" writes: > > |This *can't* be right: > | > | irb(main):001:0> require 'rational' > | true > | irb(main):002:0> a = Rational.new(1,2) > | Rational(1, 2) > | irb(main):003:0> b = Rational.new(1,3) > | Rational(1, 3) > | irb(main):004:0> Rational.new(a,b) > | Rational(0, 0) > > I don't call this a bug, but a pitfall behavior. ;-) > > Rational() requires integers, so it converts rationals to integers; > thus 1/2 => 0, 1/3 => 3. I will ask Keiju about this behavior. He > might want to change. > Seems to me like a misuse of the constructor. Rational.new(0.1,0.5) #=> Rational(0, 0) Instead of Rational.new(a,b) you should just do a/b. -- Jim Freeze ---------- One of the lessons of history is that nothing is often a good thing to do and always a clever thing to say. -- Will Durant