Forum: Ruby-core [ruby-trunk - Bug #6862][Open] BigMath.exp negative exponent

E897c9afcfcec3fef9ed461438ad3d38?d=identicon&s=25 Földes László (karatedog)
on 2012-08-13 10:59
(Received via mailing list)
Issue #6862 has been reported by karatedog (Földes László).

----------------------------------------
Bug #6862: BigMath.exp negative exponent
https://bugs.ruby-lang.org/issues/6862

Author: karatedog (Földes László)
Status: Open
Priority: Normal
Assignee:
Category:
Target version: 1.9.3
ruby -v: ruby 1.9.3p260 (2012-08-09 revision 36669) [i686-linux]


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)>
666b4e17b4bb0e2d999037a25f65a7cb?d=identicon&s=25 Heesob Park (phasis)
on 2012-08-13 16:39
(Received via mailing list)
Issue #6862 has been updated by phasis68 (Heesob Park).


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 `<main>'

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;

----------------------------------------
Bug #6862: BigMath.exp negative exponent
https://bugs.ruby-lang.org/issues/6862#change-28832

Author: karatedog (Földes László)
Status: Open
Priority: Normal
Assignee:
Category:
Target version: 1.9.3
ruby -v: ruby 1.9.3p260 (2012-08-09 revision 36669) [i686-linux]


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)>
9361878d459f1709feec780518946ee5?d=identicon&s=25 naruse (Yui NARUSE) (Guest)
on 2012-08-20 09:55
(Received via mailing list)
Issue #6862 has been updated by naruse (Yui NARUSE).

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


----------------------------------------
Bug #6862: BigMath.exp negative exponent
https://bugs.ruby-lang.org/issues/6862#change-28937

Author: karatedog (Földes László)
Status: Assigned
Priority: Normal
Assignee: mrkn (Kenta Murata)
Category:
Target version: 1.9.3
ruby -v: ruby 1.9.3p260 (2012-08-09 revision 36669) [i686-linux]


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)>
666b4e17b4bb0e2d999037a25f65a7cb?d=identicon&s=25 Heesob Park (phasis)
on 2013-06-25 15:13
(Received via mailing list)
Issue #6862 has been updated by phasis68 (Heesob Park).


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

----------------------------------------
Bug #6862: BigMath.exp negative exponent
https://bugs.ruby-lang.org/issues/6862#change-40133

Author: karatedog (Földes László)
Status: Assigned
Priority: Normal
Assignee: mrkn (Kenta Murata)
Category:
Target version: next minor
ruby -v: ruby 1.9.3p260 (2012-08-09 revision 36669) [i686-linux]
Backport:


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)>
5cf8f058a4c094bb708174fb43e7a387?d=identicon&s=25 nagachika (Tomoyuki Chikanaga) (Guest)
on 2013-06-25 19:25
(Received via mailing list)
Issue #6862 has been updated by nagachika (Tomoyuki Chikanaga).

Backport set to 1.9.3: REQUIRED, 2.0.0: REQUIRED


----------------------------------------
Bug #6862: BigMath.exp negative exponent
https://bugs.ruby-lang.org/issues/6862#change-40136

Author: karatedog (Földes László)
Status: Assigned
Priority: Normal
Assignee: mrkn (Kenta Murata)
Category:
Target version: next minor
ruby -v: ruby 1.9.3p260 (2012-08-09 revision 36669) [i686-linux]
Backport: 1.9.3: REQUIRED, 2.0.0: REQUIRED


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)>
7cca11c5257fda526eeb4b1ada28f904?d=identicon&s=25 mrkn (Kenta Murata) (Guest)
on 2013-07-01 08:39
(Received via mailing list)
Issue #6862 has been updated by mrkn (Kenta Murata).


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.

----------------------------------------
Bug #6862: BigMath.exp negative exponent
https://bugs.ruby-lang.org/issues/6862#change-40225

Author: karatedog (Földes László)
Status: Closed
Priority: Normal
Assignee: mrkn (Kenta Murata)
Category:
Target version: next minor
ruby -v: ruby 1.9.3p260 (2012-08-09 revision 36669) [i686-linux]
Backport: 1.9.3: REQUIRED, 2.0.0: REQUIRED


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)>
F24ff61beb80aa5f13371aa22a35619c?d=identicon&s=25 mame (Yusuke Endoh) (Guest)
on 2013-07-01 09:13
(Received via mailing list)
Issue #6862 has been updated by mame (Yusuke Endoh).


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

--
Yusuke Endoh <mame@tsg.ne.jp>
----------------------------------------
Bug #6862: BigMath.exp negative exponent
https://bugs.ruby-lang.org/issues/6862#change-40227

Author: karatedog (Földes László)
Status: Closed
Priority: Normal
Assignee: mrkn (Kenta Murata)
Category:
Target version: next minor
ruby -v: ruby 1.9.3p260 (2012-08-09 revision 36669) [i686-linux]
Backport: 1.9.3: REQUIRED, 2.0.0: REQUIRED


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)>
5cf8f058a4c094bb708174fb43e7a387?d=identicon&s=25 nagachika (Tomoyuki Chikanaga) (Guest)
on 2013-07-01 20:10
(Received via mailing list)
Issue #6862 has been updated by nagachika (Tomoyuki Chikanaga).

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


----------------------------------------
Bug #6862: BigMath.exp negative exponent
https://bugs.ruby-lang.org/issues/6862#change-40240

Author: karatedog (Földes László)
Status: Closed
Priority: Normal
Assignee: mrkn (Kenta Murata)
Category:
Target version: next minor
ruby -v: ruby 1.9.3p260 (2012-08-09 revision 36669) [i686-linux]
Backport: 1.9.3: REQUIRED, 2.0.0: DONE


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)>
7cca11c5257fda526eeb4b1ada28f904?d=identicon&s=25 mrkn (Kenta Murata) (Guest)
on 2013-07-03 16:46
(Received via mailing list)
Issue #6862 has been updated by mrkn (Kenta Murata).


mame (Yusuke Endoh) wrote:
> So phasis68 should have a commit bit, as I said. ;-)

+1
----------------------------------------
Bug #6862: BigMath.exp negative exponent
https://bugs.ruby-lang.org/issues/6862#change-40276

Author: karatedog (Földes László)
Status: Closed
Priority: Normal
Assignee: mrkn (Kenta Murata)
Category:
Target version: next minor
ruby -v: ruby 1.9.3p260 (2012-08-09 revision 36669) [i686-linux]
Backport: 1.9.3: REQUIRED, 2.0.0: DONE


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)>
8cbb39dadafaf2287a83a13ee4981ec9?d=identicon&s=25 usa (Usaku NAKAMURA) (Guest)
on 2013-08-02 13:54
(Received via mailing list)
Issue #6862 has been updated by usa (Usaku NAKAMURA).

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


----------------------------------------
Bug #6862: BigMath.exp negative exponent
https://bugs.ruby-lang.org/issues/6862#change-40829

Author: karatedog (Földes László)
Status: Closed
Priority: Normal
Assignee: mrkn (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


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)>
This topic is locked and can not be replied to.