This is an automated email from the ASF dual-hosted git repository.
pjfanning pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/poi.git
The following commit(s) were added to refs/heads/trunk by this push:
new ac87dd6af8 Add a regression test for bug 69892: SQRT(x)*SQRT(x) (#1423)
ac87dd6af8 is described below
commit ac87dd6af8328b4da040bf79bb415261f91d240f
Author: PJ Fanning <[email protected]>
AuthorDate: Fri Oct 16 22:31:05 2026 +0100
Add a regression test for bug 69892: SQRT(x)*SQRT(x) (#1423)
Since 5.2.1, multiplication rounded its operands to 15 significant digits,
so SQRT(666)*SQRT(666) evaluated to 666.000000000001 instead of 666.
Trunk multiplies the doubles, as Excel does, since #1275.
Co-authored-by: Claude Opus 5.5 <[email protected]>
---
.../poi/ss/formula/eval/TestFormulaBugs.java | 29 ++++++++++++++++++++++
1 file changed, 29 insertions(+)
diff --git
a/poi/src/test/java/org/apache/poi/ss/formula/eval/TestFormulaBugs.java
b/poi/src/test/java/org/apache/poi/ss/formula/eval/TestFormulaBugs.java
index 6692fc81b4..949a5b4563 100644
--- a/poi/src/test/java/org/apache/poi/ss/formula/eval/TestFormulaBugs.java
+++ b/poi/src/test/java/org/apache/poi/ss/formula/eval/TestFormulaBugs.java
@@ -269,4 +269,33 @@ final class TestFormulaBugs {
assertEquals("0h 15m", value.getStringValue());
}
}
+
+ /**
+ * Bug 69892: multiplication rounded its operands to 15 significant digits
(since 5.2.1),
+ * so SQRT(666)*SQRT(666) was 666.000000000001. Excel multiplies the
doubles.
+ */
+ @Test
+ void test69892() throws IOException {
+ try (Workbook wb = new HSSFWorkbook()) {
+ FormulaEvaluator eval =
wb.getCreationHelper().createFormulaEvaluator();
+ Row row = wb.createSheet("test").createRow(0);
+ row.createCell(0).setCellValue(666);
+ Cell root = row.createCell(1);
+ root.setCellFormula("SQRT(A1)");
+ Cell cell = row.createCell(2);
+
+ cell.setCellFormula("SQRT(A1)*SQRT(A1)");
+ assertEquals(666.0, eval.evaluate(cell).getNumberValue());
+ cell.setCellFormula("B1*B1");
+ eval.clearAllCachedResultValues();
+ assertEquals(666.0, eval.evaluate(cell).getNumberValue());
+ cell.setCellFormula("SQRT(666)*SQRT(666)");
+ eval.clearAllCachedResultValues();
+ assertEquals(666.0, eval.evaluate(cell).getNumberValue());
+ // the IEEE 754 product, as in Excel, where SQRT(2)*SQRT(2)-2 is
4.44E-16
+ cell.setCellFormula("SQRT(2)*SQRT(2)");
+ eval.clearAllCachedResultValues();
+ assertEquals(Math.sqrt(2) * Math.sqrt(2),
eval.evaluate(cell).getNumberValue());
+ }
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]