Le 26/03/2013 16:08, sebb a écrit :
> On 26 March 2013 14:56, <[email protected]> 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.
You are right.
I have fixed that with new constants (see r1461283).
Thanks for the hint
Luc
>
>> }
>>
>> /**
>> @@ -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: [email protected]
> For additional commands, e-mail: [email protected]
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]