You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ye...@apache.org on 2010/10/01 14:02:53 UTC

svn commit: r1003504 - in /poi/trunk/src: documentation/content/xdocs/status.xml java/org/apache/poi/hssf/record/formula/functions/MathX.java testcases/org/apache/poi/hssf/record/formula/functions/TestMathX.java

Author: yegor
Date: Fri Oct  1 12:02:52 2010
New Revision: 1003504

URL: http://svn.apache.org/viewvc?rev=1003504&view=rev
Log:
improved rounding in MathX.mod, see Bugzilla 50033

Modified:
    poi/trunk/src/documentation/content/xdocs/status.xml
    poi/trunk/src/java/org/apache/poi/hssf/record/formula/functions/MathX.java
    poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/functions/TestMathX.java

Modified: poi/trunk/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/status.xml?rev=1003504&r1=1003503&r2=1003504&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Fri Oct  1 12:02:52 2010
@@ -34,6 +34,7 @@
 
     <changes>
         <release version="3.7-beta4" date="2010-??-??">
+           <action dev="poi-developers" type="fix">50033 - Improved rounding in MOD</action>
            <action dev="poi-developers" type="add">Generate SHA1 hashes of distribution files, alongside existing MD5 ones</action>
         </release>
         <release version="3.7-beta3" date="2010-09-24">

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/formula/functions/MathX.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/formula/functions/MathX.java?rev=1003504&r1=1003503&r2=1003504&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/formula/functions/MathX.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/formula/functions/MathX.java Fri Oct  1 12:02:52 2010
@@ -17,6 +17,7 @@
 
 package org.apache.poi.hssf.record.formula.functions;
 
+
 /**
  * @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt;
  * This class is an extension to the standard math library
@@ -349,21 +350,15 @@ final class MathX {
             result = Double.NaN;
         }
         else if (sign(n) == sign(d)) {
-            double t = Math.abs(n / d);
-            t = t - (long) t;
-            result = sign(d) * Math.abs(t * d);
+            result = n % d;
         }
         else {
-            double t = Math.abs(n / d);
-            t = t - (long) t;
-            t = Math.ceil(t) - t;
-            result = sign(d) * Math.abs(t * d);
+            result = ((n % d) + d) % d;
         }
 
         return result;
     }
 
-
     /**
      * inverse hyperbolic cosine
      * @param d

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/functions/TestMathX.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/functions/TestMathX.java?rev=1003504&r1=1003503&r2=1003504&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/functions/TestMathX.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/functions/TestMathX.java Fri Oct  1 12:02:52 2010
@@ -292,6 +292,20 @@ public class TestMathX extends AbstractN
     }
 
     public void testMod() {
+
+        //example from Excel help
+        assertEquals(1.0, MathX.mod(3, 2));
+        assertEquals(1.0, MathX.mod(-3, 2));
+        assertEquals(-1.0, MathX.mod(3, -2));
+        assertEquals(-1.0, MathX.mod(-3, -2));
+
+        assertEquals((double) 1.4, MathX.mod(3.4, 2));
+        assertEquals((double) -1.4, MathX.mod(-3.4, -2));
+        assertEquals((double) 0.6000000000000001, MathX.mod(-3.4, 2.0));// should actually be 0.6
+        assertEquals((double) -0.6000000000000001, MathX.mod(3.4, -2.0));// should actually be -0.6
+
+        // Bugzilla 50033
+        assertEquals(1.0, MathX.mod(13, 12));
     }
 
     public void testNChooseK() {



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org