Math.pow(a,b) Bug  
Author Message
Thomas.Hermann





PostPosted: 2004-8-31 10:08:00 Top

java-programmer, Math.pow(a,b) Bug
--=-bch+Wpkq/6UBCHGw87bz
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

java.lang.Math.pow(a,b) incorrectly returns a positive value when a
negative value is raise to an odd integer. This occurs with the
jdk-1.4.2p6_4, which applies patchset 6. The attached file will
demonstrate the error.

The problem appears to be corrected by rebuilding the JVM with the
following correction:

--- e_pow.c.orig Mon Aug 30 21:01:45 2004
+++ e_pow.c Mon Aug 30 21:01:01 2004
@@ -173,7 +173,7 @@
}

/* (x<0)**(non-int) is NaN */
- if(((((u_int32_t)hx>>31)+1)|yisint)==0) return (x-x)/(x-x);
+ if(((((int32_t)hx>>31)+1)|yisint)==0) return (x-x)/(x-x);

/* |y| is huge */
if(iy>0x41e00000) { /* if |y| > 2**31 */

Furthermore, examining the experimental patchset, it appears that the
following patch also corrects the error:

2004-07-08 Thursday 20:09 glewis

* j2se/src/share/native/java/lang/fdlibm/src/e_pow.c:

. Merge in a fix recently added to FreeBSD's math library (taken
from
fdlibm-5.3):

"Fixed the sign of the result in some overflow and underflow cases
(ones
where the exponent is an odd integer and the base is negative)."

I've not yet run this through the compatibility test suite, so
this
change may be backed out if the suite relies on the broken
behaviour.



If I had the compatibility test suite, I would be willing to apply the
experimental patchset and perform the test. At the moment, I am not
willing to apply the patchset without being able to test the results.

Please email me with any questions or suggestions.

Best regards,

Tom H.

--
---------------------------------
-- Thomas M. Hermann
-- Thomas.Hermann AT cox DOT net
---------------------------------

--=-bch+Wpkq/6UBCHGw87bz
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
email***@***.com mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-java
To unsubscribe, send any mail to "email***@***.com"

--=-bch+Wpkq/6UBCHGw87bz--