Bugzilla 47198 - Fixed formula evaluator comparison of -0.0 and 0.0

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@777392 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Josh Micich 2009-05-22 06:25:58 +00:00
parent 394445888b
commit bd15957a5b
4 changed files with 20 additions and 0 deletions

View 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>

View 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>

View 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());
}
}

View 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");
}
}
}