commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1060910 - /commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/FastMath.java
Date Wed, 19 Jan 2011 19:17:31 GMT
Author: sebb
Date: Wed Jan 19 19:17:31 2011
New Revision: 1060910

URL: http://svn.apache.org/viewvc?rev=1060910&view=rev
Log:
MATH-480 - Fix ulp(Infinity) to return Infinity rather than NaN
MATH-478 - Adds ulp(float)

Modified:
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/FastMath.java

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/FastMath.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/FastMath.java?rev=1060910&r1=1060909&r2=1060910&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/FastMath.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/FastMath.java Wed
Jan 19 19:17:31 2011
@@ -3270,12 +3270,26 @@ public class FastMath {
      * @param x number from which ulp is requested
      * @return ulp(x)
      */
-
     public static double ulp(double x) {
+        if (Double.isInfinite(x)) {
+            return Double.POSITIVE_INFINITY;
+        }
         return abs(x - Double.longBitsToDouble(Double.doubleToLongBits(x) ^ 1));
     }
 
     /**
+     * Compute least significant bit (Unit in Last Position) for a number.
+     * @param x number from which ulp is requested
+     * @return ulp(x)
+     */
+    public static float ulp(float x) {
+        if (Float.isInfinite(x)) {
+            return Float.POSITIVE_INFINITY;
+        }
+        return abs(x - Float.intBitsToFloat(Float.floatToIntBits(x) ^ 1));
+    }
+
+    /**
      * Get the next machine representable number after a number, moving
      * in the direction of another number.
      * <p>



Mime
View raw message