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 6228bd667..1a5115208 100644 --- a/src/main/java/org/apache/commons/math/util/FastMath.java +++ b/src/main/java/org/apache/commons/math/util/FastMath.java @@ -29,9 +29,11 @@ package org.apache.commons.math.util; * The following methods are found in StrictMath since 1.6 only *
+ * For double numbers of the form 2x, the unbiased + * exponent is exactly x. + *
+ * @param d number from which exponent is requested + * @return exponent for d in IEEE754 representation, without bias + */ + public static int getExponent(final double d) { + return (int) ((Double.doubleToLongBits(d) >>> 52) & 0x7ff) - 1023; + } + + /** + * Return the exponent of a float number, removing the bias. + *+ * For float numbers of the form 2x, the unbiased + * exponent is exactly x. + *
+ * @param f number from which exponent is requested + * @return exponent for d in IEEE754 representation, without bias + */ + public static int getExponent(final float f) { + return (int) ((Float.floatToIntBits(f) >>> 23) & 0xff) - 127; + } + } diff --git a/src/site/xdoc/changes.xml b/src/site/xdoc/changes.xml index 011c31755..98d244d57 100644 --- a/src/site/xdoc/changes.xml +++ b/src/site/xdoc/changes.xml @@ -183,9 +183,13 @@ The