News for hackers. Stuff that matters.
Re:1.15 * 100 = 149.99999999999999 except in Ruby by kungfooguru on Friday December 16, 2011 @11:46AM (#3361170)
Weird, I'm on

  $ irb --version
  irb 0.9.5(05/04/13)
and it gives 115.0: http://i.imgur.com/gGLAd.png
Re:1.15 * 100 = 149.99999999999999 except in Ruby by Jacquass12321 on Friday December 16, 2011 @11:56AM (#3361214)

  C:\Projects>irb -v
  irb 0.9.6(09/06/30)

  C:\Projects>irb
  irb(main):001:0> 1.15*100
  => 114.99999999999999
I don't believe it's a standards issue so much as it is just a facet of floating point math in binary. Since you can't actually store 1.15, you can just store your series of fractions which sum up to something very close to 1.15, I don't have much knowledge of floating point but I'd assume it stops at some value within epsilon of 1.15. When you multiply that value by 100 that sub epsilon value is now large enough to no longer allow the language to automatically round it for display.

  irb(main):020:0> 1.15*100 > 115-Float::EPSILON
  => false
  irb(main):021:0> 1.15*100 > 115-(Float::EPSILON*100)
  => true
I'm assuming older IRB just had a wider acceptance range than epsilon perhaps.
Re:1.15 * 100 = 149.99999999999999 except in Ruby by goshakkk on Friday December 16, 2011 @11:56AM (#3361218)
Mine are Ruby 1.9.3-p0, irb 0.9.6 http://cl.ly/2p1F1Z1Q1N1a38000f1s