Hi Simon,

Thanks for your answer.

That said... the rounding error ITSELF is not the point.

The problem is: the "real" rounding error depends here on the shell (SQLite or 
JSDB) calling the SQLite library.

If I submit twice the same input (e.g. 99990.1) to the same "black box" (e.g. 
SQLite library - same compiler options etc.), I am just waiting for the same 
(fake) result. IT was determinist... so far.

Why is SQLite able to "hide" the error in one case and not in the other case? 
Because they are slightly DIFFERENT! How is it possible????? 

Regards,
Etienne



----- Original message -----
From: Simon Slavin <slav...@bigfraud.org>
To: General Discussion of SQLite Database <sqlite-users@sqlite.org>
Subject: Re: [sqlite] (shell dependent) library rounding error
Date: Thu, 14 Jun 2012 22:13:18 +0100


On 14 Jun 2012, at 9:30pm, Etienne <ejlist-sql...@yahoo.fr> wrote:

> js>var db = new SQLite();
> js>db.exec("select 99990.1", function(r){writeln(r)});
> 99990.1=99990.1000000001
> true

There's no way to store the fraction 0.1 as a binary value.  Read this:

<http://revjim.net/2003/05/07/funny-math/>

or go read any beginner's book on computer science.  SQLite, just like every 
other programming language, goes some way to fake its results but you can 
usually find some very simple operation which will make it expose the fact that 
it's all faked.  This isn't a bug in SQLite, it's a problem with pretending you 
can do the same things with binary and decimal numbers.

If you know you're going to need to store fractional values exactly, multiply 
all your numbers up until you can store integers.  For instance, if you need to 
store integer amounts of money precisely, multiply all the values by 100, store 
cents instead of Euros, and store them as INTEGER rather than REAL/FLOAT.

Simon.
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to