Bug #6862

BigMath.exp negative exponent

Added by Földes László over 1 year ago. Updated 9 months ago.

[ruby-core:47145]
Status:Closed
Priority:Normal
Assignee:Kenta Murata
Category:-
Target version:next minor
ruby -v:ruby 1.9.3p260 (2012-08-09 revision 36669) [i686-linux] Backport:1.9.3: DONE, 2.0.0: DONE

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)
=> #
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)
=> #


Related issues

Related to Backport200 - Backport #8587: Back porting r41623 Closed 06/25/2013
Related to Backport93 - Backport #8603: Back porting r41623 Closed 06/25/2013

Associated revisions

Revision 41723
Added by Kenta Murata 10 months ago

Additionally mention Heesob Park for his patch to [Bug #6862]

History

#1 Updated by Heesob Park over 1 year 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 @@ BigMathsexp(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;

#2 Updated by Yui NARUSE over 1 year ago

  • Status changed from Open to Assigned
  • Assignee set to Kenta Murata

#3 Updated by Yui NARUSE about 1 year ago

  • Target version changed from 1.9.3 to next minor

#4 Updated by Heesob Park 10 months ago

This issue was solved with changeset r41623.
BTW, my patch is same to Garth Snyder's and it is 11 months old.

#5 Updated by Tomoyuki Chikanaga 10 months ago

  • Backport set to 1.9.3: REQUIRED, 2.0.0: REQUIRED

#6 Updated by Kenta Murata 10 months 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]

#7 Updated by Kenta Murata 10 months 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.

#8 Updated by Yusuke Endoh 10 months ago

So phasis68 should have a commit bit, as I said. ;-)

Yusuke Endoh mame@tsg.ne.jp

#9 Updated by Tomoyuki Chikanaga 10 months ago

  • Backport changed from 1.9.3: REQUIRED, 2.0.0: REQUIRED to 1.9.3: REQUIRED, 2.0.0: DONE

#10 Updated by Kenta Murata 10 months ago

mame (Yusuke Endoh) wrote:

So phasis68 should have a commit bit, as I said. ;-)

+1

#11 Updated by Usaku NAKAMURA 9 months ago

  • Backport changed from 1.9.3: REQUIRED, 2.0.0: DONE to 1.9.3: DONE, 2.0.0: DONE

Also available in: Atom PDF