SQLite Forum

change in round() function
Login
The round() function (func.c) was not changed.  It still works the same way it always did.

First the arguments are checked to see if rounding is needed.  Secondly, they are checked to see if the result will fit in a 64-bit integer and to do that if so.

If rounding still needs to be performed, then use sqlite3_mprintf to "print" the value as a character string with the requested precision.  The resulting character string is then converted back to a double using the sqlite3AtoF function.

This is done so that the grade-school (4/5) rounding result retains the same precision guarantees as are made by your platform (1 ulp for IEEE compliant platforms with half-even rounding).

The changes were made in SQLite3's "printf" code to more accurately convert floating point numbers to character strings by using IEEE compliant "half's" rather than computed half's.

In other words, where the code used to (more or less) do rounding by scaling then adding .5 then descaling, it now does not scale and adds 0.5, 0.05, 0.005, etc directly, thus maintaining 1 ulp precision.  These changes were in printf.c and apply everywhere conversion from double to text is performed.