Details

Type: Bug

Status: Closed

Priority: P4

Resolution: Not an Issue

Affects Version/s: 13

Fix Version/s: None

Component/s: corelibs

Labels:

Subcomponent:
Description
ADDITIONAL SYSTEM INFORMATION :
Happens with openJDK and also with Java8.
A DESCRIPTION OF THE PROBLEM :
(positive or negative) infinity to the power of 0 is indeterminate, per mathematical definition.
However, Math.pow() is not handling this case correctly and returns 1.
As per Java pow() function documentation, this is the "expected" behavior.
https://docs.oracle.com/en/java/javase/13/docs/api/java.base/java/lang/Math.html#pow(double,double)
"Returns the value of the first argument raised to the power of the second argument. Special cases:
If the second argument is positive or negative zero, then the result is 1.0."
However, this is not right as seen in the literature:
 https://en.wikipedia.org/wiki/Indeterminate_form
 http://mathworld.wolfram.com/Indeterminate.html
Looking at openJDK's 13 source code, it seems that this is *not* being handled as a special case in the files:
 hotspot/cpu/x86/macroAssembler_x86_pow.cpp
 java.base/share/native/libfdlibm/k_standard.c
A bit unrelated references:
====================
1. If we look at ECMA 262 definition for pow() (https://www.ecmainternational.org/ecma262/5.1/#sec15.8.2.13), this special case is unfortunately not detailed.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
javac Main.java ; java Main
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED 
Double.NaN
 BEGIN SOURCE 
public class Main {
public static void main(String[] args) {
// any of the two cases should return Double.NaN (I guess) but currently returns 1
System.out.println(Math.pow(Double.POSITIVE_INFINITY,0));
System.out.println(Math.pow(Double.NEGATIVE_INFINITY,0));
}
}
 END SOURCE 
FREQUENCY : always
Happens with openJDK and also with Java8.
A DESCRIPTION OF THE PROBLEM :
(positive or negative) infinity to the power of 0 is indeterminate, per mathematical definition.
However, Math.pow() is not handling this case correctly and returns 1.
As per Java pow() function documentation, this is the "expected" behavior.
https://docs.oracle.com/en/java/javase/13/docs/api/java.base/java/lang/Math.html#pow(double,double)
"Returns the value of the first argument raised to the power of the second argument. Special cases:
If the second argument is positive or negative zero, then the result is 1.0."
However, this is not right as seen in the literature:
 https://en.wikipedia.org/wiki/Indeterminate_form
 http://mathworld.wolfram.com/Indeterminate.html
Looking at openJDK's 13 source code, it seems that this is *not* being handled as a special case in the files:
 hotspot/cpu/x86/macroAssembler_x86_pow.cpp
 java.base/share/native/libfdlibm/k_standard.c
A bit unrelated references:
====================
1. If we look at ECMA 262 definition for pow() (https://www.ecmainternational.org/ecma262/5.1/#sec15.8.2.13), this special case is unfortunately not detailed.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
javac Main.java ; java Main
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED 
Double.NaN
 BEGIN SOURCE 
public class Main {
public static void main(String[] args) {
// any of the two cases should return Double.NaN (I guess) but currently returns 1
System.out.println(Math.pow(Double.POSITIVE_INFINITY,0));
System.out.println(Math.pow(Double.NEGATIVE_INFINITY,0));
}
}
 END SOURCE 
FREQUENCY : always