summaryrefslogtreecommitdiff
path: root/ext/bigdecimal/lib/bigdecimal/math.rb
diff options
context:
space:
mode:
authormrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-06-27 16:26:09 +0000
committermrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-06-27 16:26:09 +0000
commitbb6384761e6c32acd169faa337d77d7e8d1efe5e (patch)
treee5253652dc44426c9e3f46c77ad1490121fbdb2d /ext/bigdecimal/lib/bigdecimal/math.rb
parent576b44165a8f0d61f16fcc42dde4901fb0421257 (diff)
* ext/bigdecimal/bigdecimal.c (BigMath_s_log): move BigMath.log from
bigdecimal/math.rb. * ext/bigdecimal/lib/bigdecimal/math.rb: ditto. * test/bigdecimal/test_bigdecimal.rb: move test for BigMath.log from test/bigdecimal/test_bigmath.rb. * test/bigdecimal/test_bigmath.rb: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32258 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/bigdecimal/lib/bigdecimal/math.rb')
-rw-r--r--ext/bigdecimal/lib/bigdecimal/math.rb35
1 files changed, 0 insertions, 35 deletions
diff --git a/ext/bigdecimal/lib/bigdecimal/math.rb b/ext/bigdecimal/lib/bigdecimal/math.rb
index dc557deef2..03c59bfccb 100644
--- a/ext/bigdecimal/lib/bigdecimal/math.rb
+++ b/ext/bigdecimal/lib/bigdecimal/math.rb
@@ -145,41 +145,6 @@ module BigMath
y
end
- # Computes the natural logarithm of x to the specified number of digits
- # of precision.
- #
- # Returns x if x is infinite or NaN.
- #
- def log(x, prec)
- raise ArgumentError, "Zero or negative argument for log" if x <= 0 || prec <= 0
- return x if x.infinite? || x.nan?
- one = BigDecimal("1")
- two = BigDecimal("2")
- n = prec + BigDecimal.double_fig
- if (expo = x.exponent) < 0 || expo >= 3
- x = x.mult(BigDecimal("1E#{-expo}"), n)
- else
- expo = nil
- end
- x = (x - one).div(x + one,n)
- x2 = x.mult(x,n)
- y = x
- d = y
- i = one
- while d.nonzero? && ((m = n - (y.exponent - d.exponent).abs) > 0)
- m = BigDecimal.double_fig if m < BigDecimal.double_fig
- x = x2.mult(x,n)
- i += two
- d = x.div(i,m)
- y += d
- end
- y *= two
- if expo
- y += log(BigDecimal("10"),prec) * BigDecimal(expo.to_s)
- end
- y
- end
-
# Computes the value of pi to the specified number of digits of precision.
def PI(prec)
raise ArgumentError, "Zero or negative argument for PI" if prec <= 0