まつもと ゆきひろです
In message "[ruby-math:00795] Re: Rational#to_f"
on 02/12/18, masaki <GEC01122 / nifty.ne.jp> writes:
|Bignum#to_f の bug です。
がーん。
|((2**76).div(2731)).to_f =>27666738823110336512.0
|
|正しくは
|
|class Bignum
| def to_f
| n=abs.log2floor - 52
| if n < 0
| Math.ldexp(self,0)
| else
| Math.ldexp((self*2+2**n) >> n+1,n)
| end
| end
|end
|
|((2**76).div(2731)).to_f =>27666738823110332416.0
おっしゃることは分かるのですが、52というマジックナンバーを導
入したくないのです。どうするのが一番良いでしょうね。