MATH-489 Fix overflows in acos calculation

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1061609 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Sebastian Bazley 2011-01-21 03:24:14 +00:00
parent 0e90dd494b
commit 81ba9842e5
1 changed files with 12 additions and 1 deletions

View File

@ -3135,7 +3135,18 @@ public class FastMath {
// Compute ratio r = y/x
double r = y/x;
temp = r * 1073741824.0;
// Did r overflow?
if (Double.isInfinite(r)) { // x is effectively zero
return Math.PI/2; // so return the appropriate value
}
if (abs(r) < Double.MAX_VALUE/1073741824.0){ // is it safe to split r ?
temp = r * 1073741824.0;
} else {
temp = 0.0;
}
double ra = r + temp - temp;
double rb = r - ra;