You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by lu...@apache.org on 2011/01/23 11:26:37 UTC
svn commit: r1062365 - in /commons/proper/math/branches/MATH_2_X/src:
main/java/org/apache/commons/math/util/FastMath.java site/xdoc/changes.xml
Author: luc
Date: Sun Jan 23 10:26:36 2011
New Revision: 1062365
URL: http://svn.apache.org/viewvc?rev=1062365&view=rev
Log:
added getExponent methods to FastMath
JIRA: MATH-497
Modified:
commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/util/FastMath.java
commons/proper/math/branches/MATH_2_X/src/site/xdoc/changes.xml
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=1062365&r1=1062364&r2=1062365&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 Sun Jan 23 10:26:36 2011
@@ -29,9 +29,11 @@ package org.apache.commons.math.util;
* The following methods are found in StrictMath since 1.6 only
* <ul>
* <li>{@link #copySign(double, double)}</li>
+ * <li>{@link #getExponent(double)}</li>
* <li>{@link #nextAfter(double,double)}</li>
* <li>{@link #nextUp(double)}</li>
* <li>{@link #copySign(float, float)}</li>
+ * <li>{@link #getExponent(float)}</li>
* <li>{@link #nextUp(float)}</li>
* </ul>
* @version $Revision$ $Date$
@@ -3760,4 +3762,31 @@ public class FastMath {
}
return -magnitude; // flip sign
}
+
+ /**
+ * Return the exponent of a double number, removing the bias.
+ * <p>
+ * For double numbers of the form 2<sup>x</sup>, the unbiased
+ * exponent is exactly x.
+ * </p>
+ * @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.
+ * <p>
+ * For float numbers of the form 2<sup>x</sup>, the unbiased
+ * exponent is exactly x.
+ * </p>
+ * @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;
+ }
+
}
Modified: commons/proper/math/branches/MATH_2_X/src/site/xdoc/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/site/xdoc/changes.xml?rev=1062365&r1=1062364&r2=1062365&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/site/xdoc/changes.xml (original)
+++ commons/proper/math/branches/MATH_2_X/src/site/xdoc/changes.xml Sun Jan 23 10:26:36 2011
@@ -52,9 +52,13 @@ The <action> type attribute can be add,u
If the output is not quite correct, check for invisible trailing spaces!
-->
<release version="2.2" date="TBD" description="TBD">
+ <action dev="luc" type="fix" issue="MATH-497">
+ FastMath is not an exact replacement for StrictMath
+ (partially fixed) Add getExponent(double), getExponent(float)
+ </action>
<action dev="sebb" type="fix" issue="MATH-496">
FastMath is not an exact replacement for StrictMath
- (partially fixed) Add copySign(float), copySign(float)
+ (partially fixed) Add copySign(double), copySign(float)
</action>
<action dev="sebb" type="fix" issue="MATH-494">
FastMath atan2 does not agree with StrictMath for special cases