Hi Sebastian,

Le 23/01/2011 13:07, sebb a écrit :
> On 23 January 2011 11:57, sebb <seb...@gmail.com> wrote:
>> On 23 January 2011 09:58, Luc Maisonobe <luc.maison...@free.fr> wrote:
>>> Le 23/01/2011 01:58, s...@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.
> 
> Too late - I see you have already done this.
> 
> But I also made some other (Javadoc) changes which I've not yet committed.
> 
> And I'm working on changing FastMathTest to check all StrictMath
> methods (even mixed parameter ones).

Fine. I used an hacked version of your test framework to deal with
getExponent (which returns an int) and scalb (which uses an int as
second argument). However, my hack is really ugly so I won't commit it.
I will not attempt to fix my hack and will use your updated version. In
my tests, I used a loop for the input integers in scalb, I needed to use
values from -2048 to +2048 to really push the system to limits (for
example going from POSITIVE_INFINITY to +0 by scaling down).

For now, I am trying to get scalb work on all type of inputs. It is
rather tricky for subnormals as a subnormal can become a normal number
if scale factor is large and the reverse is also possible if the scale
factor is sufficiently negative.

I first tried to simply build a number of the form 2^n, but it is not
sufficient. For example it should be possible to scale Double.MIN_VALUE
up to max exponent, but in this case 2 cannot be represented as a
number, it is too large. So I have to rely on bits magics ...

I hope I will have a reliable version of scalb in the next few hours.

Once scalb is ready, I will also commit hypot. It is already coded and
teste, but it relies on scalb to avoid overflow/underflow (and in fact
it helps me testing scalb).

best regards,
Luc


> The reflection test anyway needs to be fixed so it only allows ULP=1
> differences in methods that are not exact.
> 
>> 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?
>> 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-unsubscr...@commons.apache.org
>>> For additional commands, e-mail: dev-h...@commons.apache.org
>>>
>>>
>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org
> For additional commands, e-mail: dev-h...@commons.apache.org
> 
> 


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

Reply via email to