Project

General

Profile

Bug #6862

BigMath.exp negative exponent

Added by karatedog (Földes László) over 4 years ago. Updated over 3 years ago.

Status:
Closed
Priority:
Normal
Target version:
ruby -v:
ruby 1.9.3p260 (2012-08-09 revision 36669) [i686-linux]
[ruby-core:47145]

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

Associated revisions

Revision 41723
Added by mrkn (Kenta Murata) almost 4 years ago

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

Revision 41723
Added by mrkn (Kenta Murata) almost 4 years ago

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

Revision 41723
Added by mrkn (Kenta Murata) almost 4 years ago

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

Revision 41723
Added by mrkn (Kenta Murata) almost 4 years ago

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

History

#1 [ruby-core:47151] Updated by phasis68 (Heesob Park) over 4 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;

#2 [ruby-core:47245] Updated by naruse (Yui NARUSE) over 4 years ago

  • Status changed from Open to Assigned
  • Assignee set to mrkn (Kenta Murata)

#3 Updated by naruse (Yui NARUSE) about 4 years ago

  • Target version changed from 1.9.3 to next minor

#4 [ruby-core:55649] Updated by phasis68 (Heesob Park) almost 4 years ago

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

#5 [ruby-core:55651] Updated by nagachika (Tomoyuki Chikanaga) almost 4 years ago

  • Backport set to 1.9.3: REQUIRED, 2.0.0: REQUIRED

#6 Updated by mrkn (Kenta Murata) almost 4 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]

#7 [ruby-core:55726] Updated by mrkn (Kenta Murata) almost 4 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.

#8 [ruby-core:55727] Updated by mame (Yusuke Endoh) almost 4 years ago

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

--
Yusuke Endoh mame@tsg.ne.jp

#9 [ruby-core:55742] Updated by nagachika (Tomoyuki Chikanaga) almost 4 years ago

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

#10 [ruby-core:55781] Updated by mrkn (Kenta Murata) almost 4 years ago

mame (Yusuke Endoh) wrote:

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

+1

#11 [ruby-core:56336] Updated by usa (Usaku NAKAMURA) over 3 years 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