GNOME Bugzilla – Bug 301162
round, ceil and floor does not work correctly with large numbers
Last modified: 2017-06-08 11:14:38 UTC
Please describe the problem: When trying to apply round, ceil or floor to the number like 2353231086, the result is -1941736209 Steps to reproduce: 1. <xsl:value-of select="round(2353231086)"/> Actual results: The result is wrong Expected results: Nothing should be done for the number like that Does this happen every time? Yes Other information: Maybe, the problem is in the xmlXPathFloorFunction, xmlXPathCeilingFunction and xmlXPathRoundFunction functions where the actual value ctxt->value->floatval is being casted to the int (4 bytes) and then back to the double (8 bytes) (f = (double)((int) ctxt->value->floatval)) when the initial value is double (8 bytes).
Your analysis is completely correct. I have put some code into xpath.c which avoids the problem, but I'm not sure it's the "best" solution so I'm going to leave the bug open until I can discuss it further with Daniel. Since there is a fix, I'm changing the severity to 'enhancement' until we decide whether there's a better way. Fixed code is in CVS - thanks for the report and for the work you did in tracing the problem! Bill
This was fixed long ago and improved with the following commit: https://git.gnome.org/browse/libxml2/commit/?id=4bebb030db2100fce5b43fbbae413d372ee70497