Skip to content

Instantly share code, notes, and snippets.

@yancya
Created November 25, 2013 06:53
Show Gist options
  • Save yancya/7637332 to your computer and use it in GitHub Desktop.
Save yancya/7637332 to your computer and use it in GitHub Desktop.
Float と BigDecimal の誤差の出方を比較
[1] pry(main)> (1000.times.inject(0){|sum| sum += 0.0000001})
#=> 0.00010000000000000159
[2] pry(main)> require 'bigdecimal'
#=> true
[3] pry(main)> (1000.times.inject(0){|sum| sum += BigDecimal.new("0.0000001")}).to_f
#=> 0.0001
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment