From 5b20a1398befac93116d69112e12c21533667927 Mon Sep 17 00:00:00 2001 From: nobu Date: Wed, 12 May 2010 06:04:59 +0000 Subject: [PATCH] * 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 --- ChangeLog | 5 +++++ ext/bigdecimal/lib/bigdecimal/math.rb | 6 ++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5f0688b88d..def8de8d0f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Wed May 12 15:04:57 2010 Nobuyoshi Nakada + + * ext/bigdecimal/lib/bigdecimal/math.rb (BigMath#log): improved + precision and performance. [ruby-dev:41295] + Wed May 12 11:39:10 2010 NAKAMURA Usaku * 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