From: "phasis68 (Heesob Park)" Date: 2012-09-06T18:19:37+09:00 Subject: [ruby-core:47448] [ruby-trunk - Bug #6986] Inconsistent result of BigDecimal#power Issue #6986 has been updated by phasis68 (Heesob Park). Could you try "p BigDecimal('1e-10').power(1e50)" ? On Windows, the parameter higher than 1e19 returns Infinity instead of 0.0. Here is a patch of NoMemoryError on Windows. diff --git a/bigdecimal.c b/bigdecimal.c.new index e798781..976503b 100644 --- a/bigdecimal.c +++ b/bigdecimal.c.new @@ -2184,7 +2184,7 @@ retry: if (exp != NULL) { return rmpd_power_by_big_decimal(x, exp, n); } - else if (TYPE(vexp) == T_BIGNUM) { + else if (TYPE(vexp) == T_BIGNUM || FIX2INT(vexp)>=10000000) { VALUE abs_value = BigDecimal_abs(self); if (is_one(abs_value)) { return ToValue(VpCreateRbObject(n, "1")); ---------------------------------------- Bug #6986: Inconsistent result of BigDecimal#power https://bugs.ruby-lang.org/issues/6986#change-29206 Author: phasis68 (Heesob Park) Status: Assigned Priority: Normal Assignee: mrkn (Kenta Murata) Category: ext Target version: ruby -v: ruby 2.0.0dev (2012-09-05 trunk 36913) [i386-mswin32_100] I found BigDecimal#power returns incorrect result for a large value. C:\tmp>ruby -rbigdecimal -e "p BigDecimal('1e-10').power(1e7)" # C:\tmp>ruby -rbigdecimal -e "p BigDecimal('1e-10').power(1e8)" -e:1:in `power': failed to allocate memory (NoMemoryError) from -e:1:in `
' C:\tmp>ruby -rbigdecimal -e "p BigDecimal('1e-10').power(1e10)" # C:\tmp>ruby -rbigdecimal -e "p BigDecimal('1e-10').power(1e19)" # -- http://bugs.ruby-lang.org/