You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by se...@apache.org on 2011/01/21 04:23:13 UTC
svn commit: r1061608 -
/commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/util/FastMath.java
Author: sebb
Date: Fri Jan 21 03:23:13 2011
New Revision: 1061608
URL: http://svn.apache.org/viewvc?rev=1061608&view=rev
Log:
Fix overflows in acos calculation
Modified:
commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/util/FastMath.java
Modified: commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/util/FastMath.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/util/FastMath.java?rev=1061608&r1=1061607&r2=1061608&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/util/FastMath.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/util/FastMath.java Fri Jan 21 03:23:13 2011
@@ -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;