]> source.dussan.org Git - poi.git/commitdiff
Bugzilla 47198 - Fixed formula evaluator comparison of -0.0 and 0.0
authorJosh Micich <josh@apache.org>
Fri, 22 May 2009 06:25:58 +0000 (06:25 +0000)
committerJosh Micich <josh@apache.org>
Fri, 22 May 2009 06:25:58 +0000 (06:25 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@777392 13f79535-47bb-0310-9956-ffa450edef68

src/documentation/content/xdocs/changes.xml
src/documentation/content/xdocs/status.xml
src/java/org/apache/poi/hssf/record/formula/eval/RelationalOperationEval.java
src/testcases/org/apache/poi/hssf/record/formula/eval/TestEqualEval.java

index 4411ea6f6e94120f1e045231586544d0655fe475..2549d2c2873b215a343aed7052df74e7f9437eee 100644 (file)
@@ -37,6 +37,7 @@
 
                <!-- Don't forget to update status.xml too! -->
         <release version="3.5-beta6" date="2009-??-??">
+           <action dev="POI-DEVELOPERS" type="add">47198 - Fixed formula evaluator comparison of -0.0 and 0.0</action>
            <action dev="POI-DEVELOPERS" type="add">47229 - Fixed ExternalNameRecord to handle DDE links</action>
            <action dev="POI-DEVELOPERS" type="add">46287 - Control of header and footer extraction in ExcelExtractor / XSSFExcelExtractor</action>
            <action dev="POI-DEVELOPERS" type="add">46554 - New ant target "jar-examples"</action>
index b46e086a671bc2cd8df75684f6f28211ac131dd0..5486266da60bc33fc6313f018d30c49928b38d76 100644 (file)
@@ -34,6 +34,7 @@
        <!-- Don't forget to update changes.xml too! -->
     <changes>
         <release version="3.5-beta6" date="2009-??-??">
+           <action dev="POI-DEVELOPERS" type="add">47198 - Fixed formula evaluator comparison of -0.0 and 0.0</action>
            <action dev="POI-DEVELOPERS" type="add">47229 - Fixed ExternalNameRecord to handle DDE links</action>
            <action dev="POI-DEVELOPERS" type="add">46287 - Control of header and footer extraction in ExcelExtractor / XSSFExcelExtractor</action>
            <action dev="POI-DEVELOPERS" type="add">46554 - New ant target "jar-examples"</action>
index 9dee4bc1e0fcb9ade31e887c1928af9b1ede913d..d5eef3e26529126d36c9ec0487c7bd0691699b27 100644 (file)
@@ -108,6 +108,10 @@ public abstract class RelationalOperationEval implements OperationEval {
                        if (vb instanceof NumberEval) {
                                NumberEval nA = (NumberEval) va;
                                NumberEval nB = (NumberEval) vb;
+                               if (nA.getNumberValue() == nB.getNumberValue()) {
+                                       // Excel considers -0.0 == 0.0 which is different to Double.compare()
+                                       return 0;
+                               }
                                return Double.compare(nA.getNumberValue(), nB.getNumberValue());
                        }
                }
index 3a027bb2e91b61fba695022388cedc99a33396c3..3053660b70105a039d38400d3917b16405d7ab8a 100644 (file)
@@ -91,4 +91,18 @@ public final class TestEqualEval extends TestCase {
                BoolEval be = (BoolEval) result;
                return be.getBooleanValue();
        }
+
+       /**
+        * Excel considers -0.0 to be equal to 0.0
+        */
+       public void testZeroEquality_bug47198() {
+               NumberEval zero = new NumberEval(0.0);
+               NumberEval mZero = (NumberEval) UnaryMinusEval.instance.evaluate(new Eval[] { zero, }, 0,
+                               (short) 0);
+               Eval[] args = { zero, mZero, };
+               BoolEval result = (BoolEval) EqualEval.instance.evaluate(args, 0, (short) 0);
+               if (!result.getBooleanValue()) {
+                       throw new AssertionFailedError("Identified bug 47198: -0.0 != 0.0");
+               }
+       }
 }