Skip to content

Instantly share code, notes, and snippets.

@paddor
Created February 22, 2012 19:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paddor/1886856 to your computer and use it in GitHub Desktop.
Save paddor/1886856 to your computer and use it in GitHub Desktop.
require 'bigdecimal'
n = 5_000
sum = BigDecimal.new('0')
dx = BigDecimal.new('1') / n
1.upto(n) { |i| sum += dx * (dx * i) ** 2 }
puts sum
puts sum.to_s
puts sum.to_f
puts sum.to_r
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment