commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sebb <seb...@gmail.com>
Subject Re: svn commit: r1461159 - /commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/FastMath.java
Date Tue, 26 Mar 2013 15:08:42 GMT
On 26 March 2013 14:56,  <luc@apache.org> wrote:
> Author: luc
> Date: Tue Mar 26 14:56:01 2013
> New Revision: 1461159
>
> URL: http://svn.apache.org/r1461159
> Log:
> FastMath.abs() without branching for float and double primitive types.
>
> JIRA: MATH-954
>
> Modified:
>     commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/FastMath.java
>
> Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/FastMath.java
> URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/FastMath.java?rev=1461159&r1=1461158&r2=1461159&view=diff
> ==============================================================================
> --- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/FastMath.java
(original)
> +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/FastMath.java
Tue Mar 26 14:56:01 2013
> @@ -3011,10 +3011,7 @@ public class FastMath {
>       * @return abs(x)
>       */
>      public static float abs(final float x) {
> -        if ((Float.floatToRawIntBits(x) & Integer.MIN_VALUE) == 0) {
> -            return x;
> -        }
> -        return -x;
> +        return Float.intBitsToFloat(Integer.MAX_VALUE & Float.floatToRawIntBits(x));

It looks wrong using MAX_VALUE as a mask (even though the value is correct).
Is there a no better constant?

If not, it would be better to create one with appropriate Javadoc.

>      }
>
>      /**
> @@ -3023,10 +3020,7 @@ public class FastMath {
>       * @return abs(x)
>       */
>      public static double abs(double x) {
> -        if ((Double.doubleToRawLongBits(x) & Long.MIN_VALUE) == 0) {
> -            return x;
> -        }
> -        return -x;
> +        return Double.longBitsToDouble(Long.MAX_VALUE & Double.doubleToRawLongBits(x));
>      }
>
>      /**
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Mime
View raw message