summaryrefslogtreecommitdiff
path: root/ext/bigdecimal/lib/bigdecimal
diff options
context:
space:
mode:
authormrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-06-17 17:38:14 +0000
committermrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-06-17 17:38:14 +0000
commitf107d1e7066fdfa6360bf4aa9986f519dcd3f175 (patch)
treefff0efb2089cbee7737ff7407b8e8baa5cc196bf /ext/bigdecimal/lib/bigdecimal
parenta489109884de316893e3e716130be3a48bb965f0 (diff)
* 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
Diffstat (limited to 'ext/bigdecimal/lib/bigdecimal')
-rw-r--r--ext/bigdecimal/lib/bigdecimal/math.rb42
1 files changed, 0 insertions, 42 deletions
diff --git a/ext/bigdecimal/lib/bigdecimal/math.rb b/ext/bigdecimal/lib/bigdecimal/math.rb
index c17841fdb96..dc557deef22 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.
#