xmlXPathCeilingFunction() returns incorrect result on AIX due to buggy ceil() function
AIX, even in its latest iterations, has a buggy ceil()
function that does not handle negative-zero correctly. On this platform, ceil(-0.1) => 0
(wrong), instead of ceil(-0.1) => -0
(correct). This leads to some test-suite failures:
## XPath expressions regression tests
Result for ./test/XPath/expr/floats failed in result/XPath/expr/floats
File ./test/XPath/expr/floats generated an error
The following patch works around the issue, by explicitly copying the sign of the input:
diff --git a/xpath.c b/xpath.c
index 4734ecc..65a9f09 100644
--- a/xpath.c
+++ b/xpath.c
@@ -9584,7 +9584,12 @@ xmlXPathCeilingFunction(xmlXPathParserContextPtr ctxt, int nargs) {
CAST_TO_NUMBER;
CHECK_TYPE(XPATH_NUMBER);
+#ifdef _AIX
+ /* Work around buggy ceil() function on AIX */
+ ctxt->value->floatval = copysign(ceil(ctxt->value->floatval), ctxt->value->floatval);
+#else
ctxt->value->floatval = ceil(ctxt->value->floatval);
+#endif
}
/**