You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by se...@apache.org on 2011/01/19 20:26:19 UTC

svn commit: r1060917 - /commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/util/FastMath.java

Author: sebb
Date: Wed Jan 19 19:26:19 2011
New Revision: 1060917

URL: http://svn.apache.org/viewvc?rev=1060917&view=rev
Log:
MATH-478 FastMath is not an exact replacement for StrictMath
Add signum(float)

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=1060917&r1=1060916&r2=1060917&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 Wed Jan 19 19:26:19 2011
@@ -582,6 +582,15 @@ public class FastMath {
         return (a < 0.0) ? -1.0 : ((a > 0.0) ? 1.0 : a);
     }
 
+    /** Compute the signum of a number.
+     * The signum is -1 for negative numbers, +1 for positive numbers and 0 otherwise
+     * @param a number on which evaluation is done
+     * @return -1, 0, +1 or NaN depending on sign of a
+     */
+    public static float signum(final float a) {
+        return (a < 0.0f) ? -1.0f : ((a > 0.0f) ? 1.0f : a);
+    }
+
     /** Compute next number towards positive infinity.
      * @param a number to which neighbor should be computed
      * @return neighbor of a towards positive infinity



Re: svn commit: r1060917 - /commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/util/FastMath.java

Posted by Mikkel Meyer Andersen <mi...@mikl.dk>.
Never mind - didn't see the commit.
Den 20/01/2011 02.34 skrev "Mikkel Meyer Andersen" <mi...@mikl.dk>:
> Okay, cheers. Shouldn't the javadoc reflect the +/-0 or is that implicit?
> Den 20/01/2011 02.21 skrev "sebb" <se...@gmail.com>:
>> On 20 January 2011 01:16, Mikkel Meyer Andersen <mi...@mikl.dk> wrote:
>>> Hi,
>>>
>>> Just a quick question: when a == 0.0f or NA, then a is returned. Why not
>>> just put a special isNA() in the beginning and 0.0f in the existing
code?
>>
>> Because we want to return -0.0 if a == -0.0 and +0.0 if a == +0.0
>>
>>> Wouldn't it save a tiny bit not loading a?
>>>
>>> Cheers, Mikkel.
>>> Den 19/01/2011 20.26 skrev <se...@apache.org>:
>>>> Author: sebb
>>>> Date: Wed Jan 19 19:26:19 2011
>>>> New Revision: 1060917
>>>>
>>>> URL: http://svn.apache.org/viewvc?rev=1060917&view=rev
>>>> Log:
>>>> MATH-478 FastMath is not an exact replacement for StrictMath
>>>> Add signum(float)
>>>>
>>>> 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=1060917&r1=1060916&r2=1060917&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
>>> Wed Jan 19 19:26:19 2011
>>>> @@ -582,6 +582,15 @@ public class FastMath {
>>>> return (a < 0.0) ? -1.0 : ((a > 0.0) ? 1.0 : a);
>>>> }
>>>>
>>>> + /** Compute the signum of a number.
>>>> + * The signum is -1 for negative numbers, +1 for positive numbers and
0
>>> otherwise
>>>> + * @param a number on which evaluation is done
>>>> + * @return -1, 0, +1 or NaN depending on sign of a
>>>> + */
>>>> + public static float signum(final float a) {
>>>> + return (a < 0.0f) ? -1.0f : ((a > 0.0f) ? 1.0f : a);
>>>> + }
>>>> +
>>>> /** Compute next number towards positive infinity.
>>>> * @param a number to which neighbor should be computed
>>>> * @return neighbor of a towards positive infinity
>>>>
>>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>> For additional commands, e-mail: dev-help@commons.apache.org
>>

Re: svn commit: r1060917 - /commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/util/FastMath.java

Posted by Mikkel Meyer Andersen <mi...@mikl.dk>.
Okay, cheers. Shouldn't the javadoc reflect the +/-0 or is that implicit?
Den 20/01/2011 02.21 skrev "sebb" <se...@gmail.com>:
> On 20 January 2011 01:16, Mikkel Meyer Andersen <mi...@mikl.dk> wrote:
>> Hi,
>>
>> Just a quick question: when a == 0.0f or NA, then a is returned. Why not
>> just put a special isNA() in the beginning and 0.0f in the existing code?
>
> Because we want to return -0.0 if a == -0.0 and +0.0 if a == +0.0
>
>> Wouldn't it save a tiny bit not loading a?
>>
>> Cheers, Mikkel.
>> Den 19/01/2011 20.26 skrev <se...@apache.org>:
>>> Author: sebb
>>> Date: Wed Jan 19 19:26:19 2011
>>> New Revision: 1060917
>>>
>>> URL: http://svn.apache.org/viewvc?rev=1060917&view=rev
>>> Log:
>>> MATH-478 FastMath is not an exact replacement for StrictMath
>>> Add signum(float)
>>>
>>> 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=1060917&r1=1060916&r2=1060917&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
>> Wed Jan 19 19:26:19 2011
>>> @@ -582,6 +582,15 @@ public class FastMath {
>>> return (a < 0.0) ? -1.0 : ((a > 0.0) ? 1.0 : a);
>>> }
>>>
>>> + /** Compute the signum of a number.
>>> + * The signum is -1 for negative numbers, +1 for positive numbers and 0
>> otherwise
>>> + * @param a number on which evaluation is done
>>> + * @return -1, 0, +1 or NaN depending on sign of a
>>> + */
>>> + public static float signum(final float a) {
>>> + return (a < 0.0f) ? -1.0f : ((a > 0.0f) ? 1.0f : a);
>>> + }
>>> +
>>> /** Compute next number towards positive infinity.
>>> * @param a number to which neighbor should be computed
>>> * @return neighbor of a towards positive infinity
>>>
>>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>

Re: svn commit: r1060917 - /commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/util/FastMath.java

Posted by sebb <se...@gmail.com>.
On 20 January 2011 01:16, Mikkel Meyer Andersen <mi...@mikl.dk> wrote:
> Hi,
>
> Just a quick question: when a == 0.0f or NA, then a is returned. Why not
> just put a special isNA() in the beginning and 0.0f in the existing code?

Because we want to return -0.0 if a == -0.0 and +0.0 if a == +0.0

> Wouldn't it save a tiny bit not loading a?
>
> Cheers, Mikkel.
> Den 19/01/2011 20.26 skrev <se...@apache.org>:
>> Author: sebb
>> Date: Wed Jan 19 19:26:19 2011
>> New Revision: 1060917
>>
>> URL: http://svn.apache.org/viewvc?rev=1060917&view=rev
>> Log:
>> MATH-478 FastMath is not an exact replacement for StrictMath
>> Add signum(float)
>>
>> 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=1060917&r1=1060916&r2=1060917&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
> Wed Jan 19 19:26:19 2011
>> @@ -582,6 +582,15 @@ public class FastMath {
>> return (a < 0.0) ? -1.0 : ((a > 0.0) ? 1.0 : a);
>> }
>>
>> + /** Compute the signum of a number.
>> + * The signum is -1 for negative numbers, +1 for positive numbers and 0
> otherwise
>> + * @param a number on which evaluation is done
>> + * @return -1, 0, +1 or NaN depending on sign of a
>> + */
>> + public static float signum(final float a) {
>> + return (a < 0.0f) ? -1.0f : ((a > 0.0f) ? 1.0f : a);
>> + }
>> +
>> /** Compute next number towards positive infinity.
>> * @param a number to which neighbor should be computed
>> * @return neighbor of a towards positive infinity
>>
>>
>

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


Re: svn commit: r1060917 - /commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/util/FastMath.java

Posted by Mikkel Meyer Andersen <mi...@mikl.dk>.
Hi,

Just a quick question: when a == 0.0f or NA, then a is returned. Why not
just put a special isNA() in the beginning and 0.0f in the existing code?
Wouldn't it save a tiny bit not loading a?

Cheers, Mikkel.
Den 19/01/2011 20.26 skrev <se...@apache.org>:
> Author: sebb
> Date: Wed Jan 19 19:26:19 2011
> New Revision: 1060917
>
> URL: http://svn.apache.org/viewvc?rev=1060917&view=rev
> Log:
> MATH-478 FastMath is not an exact replacement for StrictMath
> Add signum(float)
>
> 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=1060917&r1=1060916&r2=1060917&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
Wed Jan 19 19:26:19 2011
> @@ -582,6 +582,15 @@ public class FastMath {
> return (a < 0.0) ? -1.0 : ((a > 0.0) ? 1.0 : a);
> }
>
> + /** Compute the signum of a number.
> + * The signum is -1 for negative numbers, +1 for positive numbers and 0
otherwise
> + * @param a number on which evaluation is done
> + * @return -1, 0, +1 or NaN depending on sign of a
> + */
> + public static float signum(final float a) {
> + return (a < 0.0f) ? -1.0f : ((a > 0.0f) ? 1.0f : a);
> + }
> +
> /** Compute next number towards positive infinity.
> * @param a number to which neighbor should be computed
> * @return neighbor of a towards positive infinity
>
>