summaryrefslogtreecommitdiff
path: root/ext/bigdecimal/lib
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-05-12 06:04:59 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-05-12 06:04:59 +0000
commit5b20a1398befac93116d69112e12c21533667927 (patch)
tree119b93b0b26ff51b4758589ce711616ce7ca4e46 /ext/bigdecimal/lib
parent851a023843ac4db27c3fb4dc2c4e1a523e0d3831 (diff)
* ext/bigdecimal/lib/bigdecimal/math.rb (BigMath#log): improved
precision and performance. [ruby-dev:41295] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27747 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/bigdecimal/lib')
-rw-r--r--ext/bigdecimal/lib/bigdecimal/math.rb6
1 files changed, 4 insertions, 2 deletions
diff --git a/ext/bigdecimal/lib/bigdecimal/math.rb b/ext/bigdecimal/lib/bigdecimal/math.rb
index 07efcbe..41fc69f 100644
--- a/ext/bigdecimal/lib/bigdecimal/math.rb
+++ b/ext/bigdecimal/lib/bigdecimal/math.rb
@@ -190,8 +190,10 @@ module BigMath
one = BigDecimal("1")
two = BigDecimal("2")
n = prec + BigDecimal.double_fig
- if (expo = x.exponent) < 0
+ 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)
@@ -206,7 +208,7 @@ module BigMath
y += d
end
y *= two
- if expo < 0
+ if expo
y += log(BigDecimal("10"),prec) * BigDecimal(expo.to_s)
end
y