Bug #6862
closedBigMath.exp negative exponent
Description
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)
Updated by phasis68 (Heesob Park) over 12 years ago
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;
Updated by naruse (Yui NARUSE) over 12 years ago
- Status changed from Open to Assigned
- Assignee set to mrkn (Kenta Murata)
Updated by naruse (Yui NARUSE) almost 12 years ago
- Target version changed from 1.9.3 to 2.6
Updated by phasis68 (Heesob Park) over 11 years ago
This issue was solved with changeset r41623.
BTW, my patch is same to Garth Snyder's and it is 11 months old.
Updated by nagachika (Tomoyuki Chikanaga) over 11 years ago
- Backport set to 1.9.3: REQUIRED, 2.0.0: REQUIRED
Updated by mrkn (Kenta Murata) over 11 years ago
- Status changed from Assigned to Closed
- % Done changed from 0 to 100
This issue was solved with changeset r41723.
Földes, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.
Additionally mention Heesob Park for his patch to [Bug #6862]
Updated by mrkn (Kenta Murata) over 11 years ago
phasis68 (Heesob Park) wrote:
This issue was solved with changeset r41623.
BTW, my patch is same to Garth Snyder's and it is 11 months old.
I'm sorry I missed this issue and your patch.
I added your name in ChangeLog at r41723.
Updated by mame (Yusuke Endoh) over 11 years ago
So phasis68 should have a commit bit, as I said. ;-)
--
Yusuke Endoh mame@tsg.ne.jp
Updated by nagachika (Tomoyuki Chikanaga) over 11 years ago
- Backport changed from 1.9.3: REQUIRED, 2.0.0: REQUIRED to 1.9.3: REQUIRED, 2.0.0: DONE
Updated by mrkn (Kenta Murata) over 11 years ago
mame (Yusuke Endoh) wrote:
So phasis68 should have a commit bit, as I said. ;-)
+1
Updated by usa (Usaku NAKAMURA) over 11 years ago
- Backport changed from 1.9.3: REQUIRED, 2.0.0: DONE to 1.9.3: DONE, 2.0.0: DONE