Project

General

Profile

Actions

Bug #6862

closed

BigMath.exp negative exponent

Bug #6862: BigMath.exp negative exponent

Added by karatedog (Földes László) about 13 years ago. Updated about 12 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)

Updated by phasis68 (Heesob Park) about 13 years ago Actions #1 [ruby-core:47151]

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) about 13 years ago Actions #2 [ruby-core:47245]

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

Updated by naruse (Yui NARUSE) over 12 years ago Actions #3

  • Target version changed from 1.9.3 to 2.6

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

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 12 years ago Actions #5 [ruby-core:55651]

  • Backport set to 1.9.3: REQUIRED, 2.0.0: REQUIRED

Updated by mrkn (Kenta Murata) over 12 years ago Actions #6

  • 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 12 years ago Actions #7 [ruby-core:55726]

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 12 years ago Actions #8 [ruby-core:55727]

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

--
Yusuke Endoh

Updated by nagachika (Tomoyuki Chikanaga) over 12 years ago Actions #9 [ruby-core:55742]

  • 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 12 years ago Actions #10 [ruby-core:55781]

mame (Yusuke Endoh) wrote:

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

+1

Updated by usa (Usaku NAKAMURA) about 12 years ago Actions #11 [ruby-core:56336]

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

Also available in: PDF Atom