diff --git a/src/main/java/org/apache/commons/math/util/FastMath.java b/src/main/java/org/apache/commons/math/util/FastMath.java index cf3650677..2be206df9 100644 --- a/src/main/java/org/apache/commons/math/util/FastMath.java +++ b/src/main/java/org/apache/commons/math/util/FastMath.java @@ -18,6 +18,17 @@ package org.apache.commons.math.util; /** * Faster, more accurate, portable alternative to StrictMath. + *

+ * Additionally implements the following methods: + *

* @version $Revision$ $Date$ * @since 2.2 */ @@ -161,7 +172,7 @@ public class FastMath { 1.2599210498948732, 1.5874010519681994 }; - /** + /** * 0x40000000 - used to split a double into two parts, both with the low order bits cleared. */ private static final double HEX_40000000 = 1073741824.0; @@ -3150,7 +3161,7 @@ public class FastMath { } if (abs(r) < Double.MAX_VALUE/HEX_40000000){ // is it safe to split r ? - temp = r * HEX_40000000; + temp = r * HEX_40000000; } else { temp = 0.0; } @@ -3654,4 +3665,44 @@ public class FastMath { return (a <= b) ? b : (Double.isNaN(a + b) ? Double.NaN : a); } + /** + * Returns the hypotenuse of a triangle with sides {@code x} and {@code y} + * - sqrt(x2 +y2)
+ * avoiding intermediate overflow or underflow. + * + * + * + * @param x a value + * @param y a value + * @return sqrt(x2 +y2) + */ + public static double hypot(double x, double y) { + return StrictMath.hypot(x, y); // TODO provide our own implementation + } + /** + * Computes the remainder as prescribed by the IEEE 754 standard. + * The remainder value is mathematically equal to {@code x - y*n} + * where {@code n} is the mathematical integer closest to the exact mathematical value + * of the quotient {@code x/y}. + * If two mathematical integers are equally close to {@code x/y} then + * {@code n} is the integer that is even. + *

+ *

+ * @param dividend the number to be divided + * @param divisor the number by which to divide + * @return the remainder, rounded + */ + public static double IEEEremainder(double dividend, double divisor) { + return StrictMath.IEEEremainder(dividend, divisor); // TODO provide our own implementation + } + }