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

svn commit: r1103182 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math/util/MathUtils.java test/java/org/apache/commons/math/util/MathUtilsTest.java

Author: psteitz
Date: Sat May 14 18:51:26 2011
New Revision: 1103182

URL: http://svn.apache.org/viewvc?rev=1103182&view=rev
Log:
Improved javadoc and added infinite/NaN argument tests for reduce.

Modified:
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/MathUtils.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/MathUtilsTest.java

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/MathUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/MathUtils.java?rev=1103182&r1=1103181&r2=1103182&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/MathUtils.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/MathUtils.java Sat May 14 18:51:26 2011
@@ -1282,12 +1282,19 @@ public final class MathUtils {
      }
 
     /**
-     * Reduce to the primary interval {@code [0 period)}.
+     * <p>Reduce {@code |a - offset|} to the primary interval 
+     * {@code [0, |period|)}.</p>
+     * 
+     * <p>Specifically, the value returned is <br/>
+     * {@code a - |period| * floor((a - offset) / |period|) - offset}.</p>
+     * 
+     * <p>If any of the parameters are {@code NaN} or infinite, the result is
+     * {@code NaN}.</p>
      *
      * @param a Value to reduce.
      * @param period Period.
      * @param offset Value that will be mapped to {@code 0}.
-     * @return the value, within the interval {@code [0 period)},
+     * @return the value, within the interval {@code [0 |period|)},
      * that corresponds to {@code a}.
      */
     public static double reduce(double a,

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/MathUtilsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/MathUtilsTest.java?rev=1103182&r1=1103181&r2=1103182&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/MathUtilsTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/MathUtilsTest.java Sat May 14 18:51:26 2011
@@ -1086,6 +1086,24 @@ public final class MathUtilsTest {
         Assert.assertEquals(expected,
                             MathUtils.reduce(orig, -period, offset),
                             1e-6);
+        
+        Assert.assertTrue(Double.isNaN(MathUtils.reduce(orig, Double.NaN, offset)));
+        Assert.assertTrue(Double.isNaN(MathUtils.reduce(Double.NaN, period, offset)));
+        Assert.assertTrue(Double.isNaN(MathUtils.reduce(orig, period, Double.NaN)));
+        Assert.assertTrue(Double.isNaN(MathUtils.reduce(orig, period,
+                Double.POSITIVE_INFINITY)));
+        Assert.assertTrue(Double.isNaN(MathUtils.reduce(Double.POSITIVE_INFINITY,
+                period, offset)));
+        Assert.assertTrue(Double.isNaN(MathUtils.reduce(orig,
+                Double.POSITIVE_INFINITY, offset)));   
+        Assert.assertTrue(Double.isNaN(MathUtils.reduce(orig,
+                Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY)));
+        Assert.assertTrue(Double.isNaN(MathUtils.reduce(Double.POSITIVE_INFINITY,
+                period, Double.POSITIVE_INFINITY)));
+        Assert.assertTrue(Double.isNaN(MathUtils.reduce(Double.POSITIVE_INFINITY,
+                Double.POSITIVE_INFINITY, offset))); 
+        Assert.assertTrue(Double.isNaN(MathUtils.reduce(Double.POSITIVE_INFINITY,
+                Double.POSITIVE_INFINITY,  Double.POSITIVE_INFINITY)));
     }
 
     @Test