(As reported by Hans Boehm (boehm@acm.org))
Math.hypot says:
"""The computed result must be within 1 ulp of the exact result."""
This means that if the exact result is between adjacent floating point numbers f1 and f2, then the result must be either f1 or f2. I can exhibit a pair of doubles for which this is not the case under OpenJDK 8 through 14.. It's only off by a little.
public class BasicHypotBug {
public static void main(String[] args) {
double arg1 = 2.6718173667255144E-307;
double arg2 = 1.1432573432387167E-308; // Slightly denormal
// Actual result:
// 2.6742622187558112649563688387773761534655742E-307
double resultUpperBound = 2.6742622187558113E-307;
// Actual value of resultUpperBound:
// 2.6742622187558112997755783398169632667381058E-307
double result = Math.hypot(arg1, arg2);
if (result > resultUpperBound) {
System.out.println(
"Result too large: " + result + " > " + resultUpperBound);
}
}
}
=>
Result too large: 2.6742622187558117E-307 > 2.6742622187558113E-307
Math.hypot says:
"""The computed result must be within 1 ulp of the exact result."""
This means that if the exact result is between adjacent floating point numbers f1 and f2, then the result must be either f1 or f2. I can exhibit a pair of doubles for which this is not the case under OpenJDK 8 through 14.. It's only off by a little.
public class BasicHypotBug {
public static void main(String[] args) {
double arg1 = 2.6718173667255144E-307;
double arg2 = 1.1432573432387167E-308; // Slightly denormal
// Actual result:
// 2.6742622187558112649563688387773761534655742E-307
double resultUpperBound = 2.6742622187558113E-307;
// Actual value of resultUpperBound:
// 2.6742622187558112997755783398169632667381058E-307
double result = Math.hypot(arg1, arg2);
if (result > resultUpperBound) {
System.out.println(
"Result too large: " + result + " > " + resultUpperBound);
}
}
}
=>
Result too large: 2.6742622187558117E-307 > 2.6742622187558113E-307
- relates to
-
JDK-8316688 Widen allowable error bound of Math.hypot
- Resolved
-
JDK-8316708 Augment WorstCaseTests with more cases
- Resolved
- links to