From: "NARUSE, Yui" <naruse@...>
Date: 2011-09-10T15:50:12+09:00
Subject: [ruby-core:39443] Re: [Ruby 1.9 - Bug #5273][Open] Float#round returns the wrong floats for higher precision

(2011/09/10 10:00), Marc-Andre Lafortune wrote:
> 
> Issue #5273 has been updated by Marc-Andre Lafortune.
> 
> Status changed from Rejected to Open
> 
> Hi,
> 
> Yui NARUSE wrote:
>> Additional to say, 2.5e-22 express the range
>> from 0.0000000000000000000002499999999999999534
>> to__ 0.0000000000000000000002500000000000000003
>>
>> The center of them is 0.0000000000000000000002499999999999999769.
>> So of course 0.0000000000000000000002_499999999999999769.round(22) will be 2.0e-22.
> 
> That's a good point.
> 
> This doesn't make the other examples right though (e.g. 3.0e-31.round(31) should be equal to itself, not to 3.0000000000000003e-31)

irb(main):017:0> 3.0/10**31
=> 3.0000000000000003e-31

This is in short, use BigDecimal.

-- 
NARUSE, Yui  <naruse@airemix.jp>