diff options
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | ext/bigdecimal/lib/bigdecimal/math.rb | 6 |
2 files changed, 9 insertions, 2 deletions
@@ -1,3 +1,8 @@ +Wed May 12 15:04:57 2010 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * ext/bigdecimal/lib/bigdecimal/math.rb (BigMath#log): improved + precision and performance. [ruby-dev:41295] + Wed May 12 11:39:10 2010 NAKAMURA Usaku <usa@ruby-lang.org> * ext/socket/extconf.rb: test all IPPROTO_* constants for recent Win32 diff --git a/ext/bigdecimal/lib/bigdecimal/math.rb b/ext/bigdecimal/lib/bigdecimal/math.rb index 07efcbe099..41fc69f66c 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 |