diff --git a/src/documentation/content/xdocs/changes.xml b/src/documentation/content/xdocs/changes.xml index 4411ea6f6..2549d2c28 100644 --- a/src/documentation/content/xdocs/changes.xml +++ b/src/documentation/content/xdocs/changes.xml @@ -37,6 +37,7 @@ + 47198 - Fixed formula evaluator comparison of -0.0 and 0.0 47229 - Fixed ExternalNameRecord to handle DDE links 46287 - Control of header and footer extraction in ExcelExtractor / XSSFExcelExtractor 46554 - New ant target "jar-examples" diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index b46e086a6..5486266da 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -34,6 +34,7 @@ + 47198 - Fixed formula evaluator comparison of -0.0 and 0.0 47229 - Fixed ExternalNameRecord to handle DDE links 46287 - Control of header and footer extraction in ExcelExtractor / XSSFExcelExtractor 46554 - New ant target "jar-examples" diff --git a/src/java/org/apache/poi/hssf/record/formula/eval/RelationalOperationEval.java b/src/java/org/apache/poi/hssf/record/formula/eval/RelationalOperationEval.java index 9dee4bc1e..d5eef3e26 100644 --- a/src/java/org/apache/poi/hssf/record/formula/eval/RelationalOperationEval.java +++ b/src/java/org/apache/poi/hssf/record/formula/eval/RelationalOperationEval.java @@ -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()); } } diff --git a/src/testcases/org/apache/poi/hssf/record/formula/eval/TestEqualEval.java b/src/testcases/org/apache/poi/hssf/record/formula/eval/TestEqualEval.java index 3a027bb2e..3053660b7 100644 --- a/src/testcases/org/apache/poi/hssf/record/formula/eval/TestEqualEval.java +++ b/src/testcases/org/apache/poi/hssf/record/formula/eval/TestEqualEval.java @@ -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"); + } + } }