commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Phil Steitz <phil.ste...@gmail.com>
Subject Re: svn commit: r1062304 - /commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/util/FastMath.java
Date Sun, 23 Jan 2011 22:18:00 GMT
On Sun, Jan 23, 2011 at 6:57 AM, sebb <sebbaz@gmail.com> wrote:
> On 23 January 2011 09:58, Luc Maisonobe <Luc.Maisonobe@free.fr> wrote:
>> Le 23/01/2011 01:58, sebb@apache.org a écrit :
>>> Author: sebb
>>> Date: Sun Jan 23 00:58:07 2011
>>> New Revision: 1062304
>>>
>>> URL: http://svn.apache.org/viewvc?rev=1062304&view=rev
>>> Log:
>>> MATH-496 Create FastMath copySign methods
>>
>> I was also creating these methods.
>> I have created all the missing ones and implemented hypot directly, so
>> don't bother doing it too.
>
> OK.
>
> I've mainly been working in Math trunk, and porting back to 2.2, so
> I'll add your new methods back to trunk.
> I'll also merge my fixes to nextAfter.
>
> FastMath and FastMathTest should be the same in both.
>
> Apart from the @since marker in FastMath - perhaps we can use @since
> 2.2, 3.0 for that?

Should be @since 2.2

Lets try to get all the fixes into 2.2.

Phil

> Or if that is confusing, we just need to fix one before release.
>
>> Luc
>>
>>>
>>> Modified:
>>>     commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/util/FastMath.java
>>>
>>> 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=1062304&r1=1062303&r2=1062304&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 00:58:07 2011
>>> @@ -247,18 +247,6 @@ public class FastMath {
>>>      // Generic helper methods
>>>
>>>      /**
>>> -     * Get the sign information (works even for 0).
>>> -     *
>>> -     * @param d the value to check
>>> -     *
>>> -     * @return +1.0 or -1.0, never 0.0
>>> -     */
>>> -    private static double getSign(double d){ // TODO perhaps move to MathUtils?
>>> -        long l = Double.doubleToLongBits(d);
>>> -        return l < 0 ? -1.0 : 1.0;
>>> -    }
>>> -
>>> -    /**
>>>       * Get the high order bits from the mantissa.
>>>       * Equivalent to adding and subtracting HEX_40000 but also works for
very large numbers
>>>       *
>>> @@ -2798,7 +2786,7 @@ public class FastMath {
>>>          int idx;
>>>
>>>          if (xa == 0.0) { // Matches +/- 0.0; return correct sign
>>> -            return leftPlane ? getSign(xa) * Math.PI : xa;
>>> +            return leftPlane ? copySign(Math.PI, xa) : xa;
>>>          }
>>>
>>>          if (xa < 0) {
>>> @@ -2957,7 +2945,7 @@ public class FastMath {
>>>                  if (x > 0) {
>>>                      return y; // return +/- 0.0
>>>                  } else {
>>> -                    return getSign(y) * Math.PI;
>>> +                    return copySign(Math.PI, y);
>>>                  }
>>>              }
>>>
>>> @@ -3737,4 +3725,37 @@ public class FastMath {
>>>          return StrictMath.IEEEremainder(dividend, divisor); // TODO provide
our own implementation
>>>      }
>>>
>>> +    /**
>>> +     * Returns the first argument with the sign of the second argument.
>>> +     * A NaN {@code sign} argument is treated as positive.
>>> +     *
>>> +     * @param magnitude the value to return
>>> +     * @param sign the sign for the returned value
>>> +     * @return the magnitude with the same sign as the {@code sign} argument
>>> +     */
>>> +    public static double copySign(double magnitude, double sign){
>>> +        long m = Double.doubleToLongBits(magnitude);
>>> +        long s = Double.doubleToLongBits(sign);
>>> +        if ((m >= 0 && s >= 0) || (m < 0 && s <
0)) { // Sign is currently OK
>>> +            return magnitude;
>>> +        }
>>> +        return -magnitude; // flip sign
>>> +    }
>>> +
>>> +    /**
>>> +     * Returns the first argument with the sign of the second argument.
>>> +     * A NaN {@code sign} argument is treated as positive.
>>> +     *
>>> +     * @param magnitude the value to return
>>> +     * @param sign the sign for the returned value
>>> +     * @return the magnitude with the same sign as the {@code sign} argument
>>> +     */
>>> +    public static float copySign(float magnitude, float sign){
>>> +        int m = Float.floatToIntBits(magnitude);
>>> +        int s = Float.floatToIntBits(sign);
>>> +        if ((m >= 0 && s >= 0) || (m < 0 && s <
0)) { // Sign is currently OK
>>> +            return magnitude;
>>> +        }
>>> +        return -magnitude; // flip sign
>>> +    }
>>>  }
>>>
>>>
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>> For additional commands, e-mail: dev-help@commons.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>

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


Mime
View raw message