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
This commit is contained in:
Daniel Veillard 2002-03-22 14:14:43 +00:00
parent 4e2df54bb1
commit 56cd18b977
2 changed files with 32 additions and 16 deletions

View File

@ -1,3 +1,8 @@
Fri Mar 22 15:13:49 CET 2002 Daniel Veillard <daniel@veillard.com>
* xpath.c: Richard Jinks also raised some rounding problems
this tries to fix them
Fri Mar 22 13:22:09 CET 2002 Daniel Veillard <daniel@veillard.com> Fri Mar 22 13:22:09 CET 2002 Daniel Veillard <daniel@veillard.com>
* xpath.c: Richard Jinks spotted an incoherent memory allocation * xpath.c: Richard Jinks spotted an incoherent memory allocation

43
xpath.c
View File

@ -6483,15 +6483,19 @@ xmlXPathSumFunction(xmlXPathParserContextPtr ctxt, int nargs) {
*/ */
void void
xmlXPathFloorFunction(xmlXPathParserContextPtr ctxt, int nargs) { xmlXPathFloorFunction(xmlXPathParserContextPtr ctxt, int nargs) {
double f;
CHECK_ARITY(1); CHECK_ARITY(1);
CAST_TO_NUMBER; CAST_TO_NUMBER;
CHECK_TYPE(XPATH_NUMBER); CHECK_TYPE(XPATH_NUMBER);
#if 0
ctxt->value->floatval = floor(ctxt->value->floatval); f = (double)((int) ctxt->value->floatval);
#else if (f != ctxt->value->floatval) {
/* floor(0.999999999999) => 1.0 !!!!!!!!!!! */ if (ctxt->value->floatval > 0)
ctxt->value->floatval = (double)((int) ctxt->value->floatval); ctxt->value->floatval = f;
#endif else
ctxt->value->floatval = f - 1;
}
} }
/** /**
@ -6516,8 +6520,12 @@ xmlXPathCeilingFunction(xmlXPathParserContextPtr ctxt, int nargs) {
ctxt->value->floatval = ceil(ctxt->value->floatval); ctxt->value->floatval = ceil(ctxt->value->floatval);
#else #else
f = (double)((int) ctxt->value->floatval); f = (double)((int) ctxt->value->floatval);
if (f != ctxt->value->floatval) if (f != ctxt->value->floatval) {
ctxt->value->floatval = f + 1; if (ctxt->value->floatval > 0)
ctxt->value->floatval = f + 1;
else
ctxt->value->floatval = f;
}
#endif #endif
} }
@ -6546,15 +6554,18 @@ xmlXPathRoundFunction(xmlXPathParserContextPtr ctxt, int nargs) {
(ctxt->value->floatval == 0.0)) (ctxt->value->floatval == 0.0))
return; return;
#if 0
f = floor(ctxt->value->floatval);
#else
f = (double)((int) ctxt->value->floatval); f = (double)((int) ctxt->value->floatval);
#endif if (ctxt->value->floatval < 0) {
if (ctxt->value->floatval < f + 0.5) if (ctxt->value->floatval < f - 0.5)
ctxt->value->floatval = f; ctxt->value->floatval = f - 1;
else else
ctxt->value->floatval = f + 1; ctxt->value->floatval = f;
} else {
if (ctxt->value->floatval < f + 0.5)
ctxt->value->floatval = f;
else
ctxt->value->floatval = f + 1;
}
} }
/************************************************************************ /************************************************************************