On Fri, Mar 8, 2013 at 1:06 PM, Israel Lins Albuquerque <
israelin...@yahoo.com.br> wrote:

> The problem is not comparisons the problem is when I do something like
> this:
> CREATE TABLE tb (a REAL);
> INSERT INTO tb (a) VALUES(0);
> UPDATE tb SET a = a + 5.45;
> UPDATE tb SET a = a + 16.9;
>

The numbers 5.45 and 16.9 cannot be represented exactly using IEEE 754
floating point numbers.

This is very important to understand.  I will repeat:  The numbers 5.45 and
16.9  **CANNOT** be represented exactly using IEEE 754 floating point
numbers.  This is not a limitation of SQLite or of your hardware or of any
other software on your system.  This is an inherent limitation of IEEE 754
binary floating point numbers.

The closest you can get to 5.45 and 16.9 using 64-bit IEEE floats are
5.45000000000000017763568394002504646778106689453125 and
16.89999999999999857891452847979962825775146484375 respectively.

Furthermore, when SQLite converts these number to binary, it sometimes
picks a binary value that is not the closest possible value to the decimal.

Floating point number are approximations.  They are usually very good
approximations - more accurate than any real-world measurement.  But they
are still just approximations.  If you need an exact answer, use integers.

The previous paragraph is true of all software, not just SQLite.
-- 
D. Richard Hipp
d...@sqlite.org
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to