MarcoGervasoni / gwt-math

Automatically exported from code.google.com/p/gwt-math
0 stars 0 forks source link

pow function #16

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. (new BigDecimal("2")).pow(new BigDecimal("3")); 

What is the expected output? What do you see instead?
I expect 8. 1 is returned.

What version of the product are you using? On what operating system?
The latest 2.0.3

Please provide any additional information below.
I guess your pow method isn't functionnal.

Thank you. Your library is the best I've seen.

Original issue reported on code.google.com by twekst...@gmail.com on 22 Mar 2009 at 6:27

GoogleCodeExporter commented 9 years ago
Fixed in 2.1 but the right method is pow(int) ....

Original comment by marco.ge...@gmail.com on 6 Aug 2009 at 9:50

GoogleCodeExporter commented 9 years ago
Marco, from what I can tell this is actually not fixed in the 2.1 release. 
BigDecimal
is a port from the Java class of the same name. However the power function 
depends
upon an integer overflow which will not occur in javascript:

2405   n=n+n; // shift left 1 bit
2406   if (n<0)

I got in touch with the original author, he provided the fix below:
2405   n<<=1; // shift left 1 bit
2406   if (n<0)

Hope this helps,
Matt

Original comment by mbaker....@gmail.com on 15 Oct 2009 at 10:28