Skip to content

Instantly share code, notes, and snippets.

@german
Created December 8, 2010 10:53
Show Gist options
  • Save german/733137 to your computer and use it in GitHub Desktop.
Save german/733137 to your computer and use it in GitHub Desktop.
bug in ruby 1.8.7 / ruby 1.9.2 preview 1 (wrong rounding)
$ ruby -v
ruby 1.8.7 (2010-06-23 patchlevel 299) [i686-linux]
$irb
ruby-1.8.7-p299 > a = (125.33 - (125.33/100.0*50.0))
=> 62.665
ruby-1.8.7-p299 > b = 62.665
=> 62.665
ruby-1.8.7-p299 > (a*100).round
=> 6266
ruby-1.8.7-p299 > (b*100).round
=> 6267
$ ruby -v
ruby 1.9.2dev (2009-07-18 trunk 24186) [i686-linux]
$ irb
ruby-1.9.2-preview1 > a = (125.33 - (125.33/100.0*50.0))
=> 62.66499999999999 # which is obviously wrong as well
ruby-1.9.2-preview1 > b = 62.665
=> 62.665
ruby-1.9.2-preview1 > (a*100).round
=> 6266
ruby-1.9.2-preview1 > (b*100).round
=> 6267
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment