From f107d1e7066fdfa6360bf4aa9986f519dcd3f175 Mon Sep 17 00:00:00 2001 From: mrkn Date: Fri, 17 Jun 2011 17:38:14 +0000 Subject: * ext/bigdecimal/bigdecimal.c (BigMath_s_exp): move BigMath.exp from bigdecimal/math.rb. * ext/bigdecimal/lib/bigdecimal/math.rb: ditto. * test/bigdecimal/test_bigdecimal.rb: move test for BigMath.exp from test/bigdecimal/test_bigmath.rb. * test/bigdecimal/test_bigmath.rb: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32150 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/bigdecimal/lib/bigdecimal/math.rb | 42 ----------------------------------- 1 file changed, 42 deletions(-) (limited to 'ext/bigdecimal/lib/bigdecimal/math.rb') diff --git a/ext/bigdecimal/lib/bigdecimal/math.rb b/ext/bigdecimal/lib/bigdecimal/math.rb index c17841fdb9..dc557deef2 100644 --- a/ext/bigdecimal/lib/bigdecimal/math.rb +++ b/ext/bigdecimal/lib/bigdecimal/math.rb @@ -7,7 +7,6 @@ require 'bigdecimal' # sin (x, prec) # cos (x, prec) # atan(x, prec) Note: |x|<1, x=0.9999 may not converge. -# exp (x, prec) # log (x, prec) # PI (prec) # E (prec) == exp(1.0,prec) @@ -146,47 +145,6 @@ module BigMath y end - # Computes the value of e (the base of natural logarithms) raised to the - # power of x, to the specified number of digits of precision. - # - # If x is infinite or NaN, returns NaN. - # - # BigMath::exp(BigDecimal.new('1'), 10).to_s - # -> "0.271828182845904523536028752390026306410273E1" - def exp(x, prec) - raise ArgumentError, "Zero or negative precision for exp" if prec <= 0 - if x.infinite? - if x < 0 - return BigDecimal("0", prec) - else - return BigDecimal("+Infinity", prec) - end - elsif x.nan? - return BigDecimal("NaN", prec) - end - n = prec + BigDecimal.double_fig - one = BigDecimal("1") - x = -x if neg = x < 0 - x1 = one - y = one - d = y - z = one - i = 0 - while d.nonzero? && ((m = n - (y.exponent - d.exponent).abs) > 0) - m = BigDecimal.double_fig if m < BigDecimal.double_fig - x1 = x1.mult(x,n) - i += 1 - z *= i - d = x1.div(z,m) - y += d - end - if neg - one.div(y, prec) - else - y.round(prec - y.exponent) - end - end - # Computes the natural logarithm of x to the specified number of digits # of precision. # -- cgit v1.2.3