Author: sebb
Date: Wed Jan 19 19:17:59 2011
New Revision: 1060911
URL: http://svn.apache.org/viewvc?rev=1060911&view=rev
Log:
MATH-480 - Fix ulp(Infinity) to return Infinity rather than NaN
MATH-478 - Adds ulp(float)
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=1060911&r1=1060910&r2=1060911&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
Wed Jan 19 19:17:59 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>