1 Replies - 1671 Views - Last Post: 16 November 2013 - 02:57 AM

#1 Lemur   User is offline

  • Pragmatism over Dogma
  • member icon


Reputation: 1453
  • View blog
  • Posts: 3,633
  • Joined: 28-November 09

Euler's #, with precision

Posted 15 November 2013 - 03:16 PM

Description: Usage : puts euler(p) Refactor of http://www.dreaminco...snippet1660.htm Original Credit to: MitkOkReturn Euler's Number with p digits of precision Refactor of http://www.dreaminco...snippet1660.htm
require 'bigdecimal'

def euler(p)
  BigDecimal.limit(p+1)  
  f = BigDecimal.new 1  
  one = BigDecimal.new 1
  (2..150).reduce(2) { |e, i| e += one / (f *= i) }.to_s 'f'
end


Is This A Good Question/Topic? 0
  • +

Replies To: Euler's #, with precision

#2 Lemur   User is offline

  • Pragmatism over Dogma
  • member icon


Reputation: 1453
  • View blog
  • Posts: 3,633
  • Joined: 28-November 09

Re: Euler's #, with precision

Posted 16 November 2013 - 02:57 AM

In Ruby, EVERYTHING returns a value. Use it to your advantage.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1