jwesley wrote:
> I think I've found a bug in the sprintf function:
> 
> D:\src\ruby>ruby -v
> ruby 1.8.2 (2004-12-25) [i386-mswin32]
> 
> D:\src\ruby>irb
> irb(main):001:0> sprintf("%.1f", 123456789012345678.to_f)
> => "123456789012345680.0"
> irb(main):002:0> sprintf("%.1f", 123456789012345678.to_f).to_i
> => 123456789012345680
> 
> Notice that that sprintf changed the value by an order of magnitude...
> 
> Justin
> 

FP imprecision changed the value by 2.0:

irb(main):008:0> orig = 123456789012345678
=> 123456789012345678
irb(main):009:0> sprintf("%.1f", orig.to_f).to_i - orig
=> 2

and:

irb(main):012:0> orig - 2.0 == orig
=> true
irb(main):013:0> orig + 2.0 == orig
=> true
irb(main):014:0> orig.to_f.to_i - orig
=> 2

It's not sprintf's fault.

-- 
      vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407