From f8065763927e24e30d7e22b93a15fab02f25ce14 Mon Sep 17 00:00:00 2001 From: Luc Maisonobe Date: Sun, 23 Jan 2011 10:28:44 +0000 Subject: [PATCH] added getExponent methods to FastMath JIRA: MATH-497 git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1062368 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/commons/math/util/FastMath.java | 29 +++++++++++++++++++ src/site/xdoc/changes.xml | 6 +++- 2 files changed, 34 insertions(+), 1 deletion(-) 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 * * @version $Revision$ $Date$ @@ -3760,4 +3762,31 @@ public class FastMath { } return -magnitude; // flip sign } + + /** + * Return the exponent of a double number, removing the bias. + *

+ * 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 type attribute can be add,update,fix,remove. + + FastMath is not an exact replacement for StrictMath + (partially fixed) Add getExponent(double), getExponent(float) + FastMath is not an exact replacement for StrictMath - (partially fixed) Add copySign(float), copySign(float) + (partially fixed) Add copySign(double), copySign(float) separate discrete event detection from adaptive step size handling in ODE solvers,