Richard Jinks also raised some rounding problems this tries to fix them
* xpath.c: Richard Jinks also raised some rounding problems
this tries to fix them
Daniel
diff --git a/xpath.c b/xpath.c
index 7018ce2..7f6dd6f 100644
--- a/xpath.c
+++ b/xpath.c
@@ -6483,15 +6483,19 @@
*/
void
xmlXPathFloorFunction(xmlXPathParserContextPtr ctxt, int nargs) {
+ double f;
+
CHECK_ARITY(1);
CAST_TO_NUMBER;
CHECK_TYPE(XPATH_NUMBER);
-#if 0
- ctxt->value->floatval = floor(ctxt->value->floatval);
-#else
- /* floor(0.999999999999) => 1.0 !!!!!!!!!!! */
- ctxt->value->floatval = (double)((int) ctxt->value->floatval);
-#endif
+
+ f = (double)((int) ctxt->value->floatval);
+ if (f != ctxt->value->floatval) {
+ if (ctxt->value->floatval > 0)
+ ctxt->value->floatval = f;
+ else
+ ctxt->value->floatval = f - 1;
+ }
}
/**
@@ -6516,8 +6520,12 @@
ctxt->value->floatval = ceil(ctxt->value->floatval);
#else
f = (double)((int) ctxt->value->floatval);
- if (f != ctxt->value->floatval)
- ctxt->value->floatval = f + 1;
+ if (f != ctxt->value->floatval) {
+ if (ctxt->value->floatval > 0)
+ ctxt->value->floatval = f + 1;
+ else
+ ctxt->value->floatval = f;
+ }
#endif
}
@@ -6546,15 +6554,18 @@
(ctxt->value->floatval == 0.0))
return;
-#if 0
- f = floor(ctxt->value->floatval);
-#else
f = (double)((int) ctxt->value->floatval);
-#endif
- if (ctxt->value->floatval < f + 0.5)
- ctxt->value->floatval = f;
- else
- ctxt->value->floatval = f + 1;
+ if (ctxt->value->floatval < 0) {
+ if (ctxt->value->floatval < f - 0.5)
+ ctxt->value->floatval = f - 1;
+ else
+ ctxt->value->floatval = f;
+ } else {
+ if (ctxt->value->floatval < f + 0.5)
+ ctxt->value->floatval = f;
+ else
+ ctxt->value->floatval = f + 1;
+ }
}
/************************************************************************