aboutsummaryrefslogtreecommitdiffstats
path: root/xpath.c
diff options
context:
space:
mode:
authorDaniel Veillard <veillard@src.gnome.org>2002-03-22 14:14:43 +0000
committerDaniel Veillard <veillard@src.gnome.org>2002-03-22 14:14:43 +0000
commit56cd18b977006c28eaae715ac6590e6ad48186da (patch)
tree380f3a893da5f599ae39503a245fccb2020cd006 /xpath.c
parent4e2df54bb17645ef0d3f28b9665b2d2dde4b47a3 (diff)
downloadandroid_external_libxml2-56cd18b977006c28eaae715ac6590e6ad48186da.tar.gz
android_external_libxml2-56cd18b977006c28eaae715ac6590e6ad48186da.tar.bz2
android_external_libxml2-56cd18b977006c28eaae715ac6590e6ad48186da.zip
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
Diffstat (limited to 'xpath.c')
-rw-r--r--xpath.c43
1 files changed, 27 insertions, 16 deletions
diff --git a/xpath.c b/xpath.c
index 7018ce25..7f6dd6f9 100644
--- a/xpath.c
+++ b/xpath.c
@@ -6483,15 +6483,19 @@ xmlXPathSumFunction(xmlXPathParserContextPtr ctxt, int nargs) {
*/
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 @@ xmlXPathCeilingFunction(xmlXPathParserContextPtr ctxt, int nargs) {
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 @@ xmlXPathRoundFunction(xmlXPathParserContextPtr ctxt, int nargs) {
(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;
+ }
}
/************************************************************************