On Tue, Feb 21, 2012 at 4:18 PM, Bob Burger <burge...@gmail.com> wrote:
> On 1 Nov 2011, Richard Hipp wrote: > > Floating-point numbers are approximations. There is no way to represent > > 290.08 or 6.97 or 283.11 in binary. The closest you can get to these > > numbers using IEEE doubles is: > > > 290.07999999999998408384271897375583648681640625 > > 6.96999999999999975131004248396493494510650634765625 > > 283.1100000000000136424205265939235687255859375 > > > And to compound the difficulty, SQLite does not attempt to get that > close, > > as doing so requires infinite-precision integer math in the worst case > and > > a noticeable performance hit. SQLite, therefore, goes for a rougher > > approximation and settles for 14 significant digits. > > Are you familiar with David Gay's fast, accurate & free strtod > implementation (http://www.netlib.org/fp/dtoa.c)? It should be as fast > as the SQLite implementation in util.c for strings with fewer than 9 > digits, and it will always return the correctly rounded result. > The license for David Gay's dtoa.c is not compatible with SQLite. > > Having the text parser accurately handle floating-point input is > important to my company. If you need extreme accuracy in handling floating point numbers, you should skip the parser all together. Use a parameter<http://www.sqlite.org/lang_expr.html#varparam>such as ? or $value in the SQL, then bind your floating point value to it using sqlite3_bind_double() <http://www.sqlite.org/c3ref/bind_blob.html>. That will be both faster and more accurate than even David Gay's implementation. > I have permission to donate my time to > integrate his code and provide a suite of test cases, if you're > interested. > > Sincerely, > Bob Burger > _______________________________________________ > sqlite-users mailing list > sqlite-users@sqlite.org > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users > -- D. Richard Hipp d...@sqlite.org _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users