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 `<main>'

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)
 => #<BigDecimal:9be2ce8,'0.2008553692E2',18(72)> 
1.9.3p260 :010 > BigMath.exp(-3, 10)
 => #<BigDecimal:9bd8e50,'0.2008553692E2',18(45)>

Converting the exponent parameter to BigDecimal solves the problem:
1.9.3p260 :011 > BigMath.exp(BigDecimal(-3), 10)
 => #<BigDecimal:9bd1420,'0.4978706837E-1',18(45)> 





-- 
http://bugs.ruby-lang.org/