Project

General

Profile

Actions

Bug #6862

closed

BigMath.exp negative exponent

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

Status:
Closed
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)
=> #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)


Related issues 2 (0 open2 closed)

Related to Backport200 - Backport #8587: Back porting r41623Closednagachika (Tomoyuki Chikanaga)06/25/2013Actions
Related to Backport193 - Backport #8603: Back porting r41623Closedusa (Usaku NAKAMURA)06/25/2013Actions

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)
Actions #3

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
Actions #6

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

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
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0