From: "phasis68 (Heesob Park)" Date: 2012-08-13T23:38:44+09:00 Subject: [ruby-core:47151] [ruby-trunk - Bug #6862] BigMath.exp negative exponent Issue #6862 has been updated by phasis68 (Heesob Park). BigMath.exp cannot handle floating point value too. C:\Users\phasis>ruby -rbigdecimal -e 'p BigMath.exp(3.0,10)' -e:1:in `exp': Float can't be coerced into BigDecimal without a precision (ArgumentError) from -e:1:in `
' And Here is a patch. diff --git a/bigdecimal.c b/bigdecimal.c.new index 866ce34..f0dc9bd 100644 --- a/bigdecimal.c +++ b/bigdecimal.c.new @@ -2546,6 +2546,7 @@ BigMath_s_exp(VALUE klass, VALUE x, VALUE vprec) if (negative) { VpSetSign(vx, 1); } + x = ToValue(vx); RB_GC_GUARD(one) = ToValue(VpCreateRbObject(1, "1")); RB_GC_GUARD(x1) = one; ---------------------------------------- Bug #6862: BigMath.exp negative exponent https://bugs.ruby-lang.org/issues/6862#change-28832 Author: karatedog (F��ldes L��szl��) Status: Open Priority: Normal Assignee: Category: Target version: 1.9.3 ruby -v: ruby 1.9.3p260 (2012-08-09 revision 36669) [i686-linux] Ruby 1.9.3 BigMath.exp accepts Fixnum for exponent but silently treats negative exponents as positive: 1.9.3p260 :009 > BigMath.exp(3, 10) => # 1.9.3p260 :010 > BigMath.exp(-3, 10) => # Converting the exponent parameter to BigDecimal solves the problem: 1.9.3p260 :011 > BigMath.exp(BigDecimal(-3), 10) => # -- http://bugs.ruby-lang.org/