Tuesday, December 13, 2011

BigMath

Since Ruby 1.9.3, bigdecimal library has powered up. Especially, BigMath module is so.

irb(main):001:0> require 'bigdecimal/math'
=> true
irb(main):002:0> prec = 10
=> 10
irb(main):003:0> (-BigMath::PI(prec)).to_s
=> "-0.3141592653589793238462643388813853786957412E1"
irb(main):004:0> BigMath::exp(-BigMath::PI(prec), prec).to_s
=> "0.4321391826E-1"

But, unfortunately, bigdecimal library now does not support complex calculations:
irb(main):005:0> BigMath::exp(Complex(0, -BigMath::PI(prec)), prec)
ArgumentError: Complex can't be coerced into BigDecimal
        from (irb):5:in `exp'
        from (irb):5
        from c:/ruby-1.9.3/bin/irb:12:in `<main>'

No comments:

Post a Comment