I don't see your "problem". 22.35 cannot be accurately represented in floating point. It's just some display systems will hide it from you.
What exactly is it that you can't do or that is coming out wrong? Stop trying to make sense out of comparing floats -- it's a bad idea. main() { float f=(5.45f+16.9f); double d=(5.45+16.9); printf("%g\n",f); printf("%g\n",d); printf("%15e\n",f); printf("%15e\n",d); } (gdb) p f $1 = 22.3499985 (gdb) p d $2 = 22.349999999999998 (gdb) cont Continuing. 22.35 22.35 2.235000e+001 2.235000e+001 -----Original Message----- From: sqlite-users-boun...@sqlite.org [mailto:sqlite-users-boun...@sqlite.org] On Behalf Of Israel Lins Albuquerque Sent: Friday, March 08, 2013 12:07 PM To: General Discussion of SQLite Database Subject: Re: [sqlite] Bug on real operations 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; SELECT a FROM tb; Gives visually right answer: 22.35 But putting on a double variable gives me 22.3499948593433 (something like that) and when declaring double a = 22.35 => gdb give me 22.3499999999999 Em 08/03/2013, às 14:11, Michael Black <mdblac...@yahoo.com> escreveu: > Nobody should expect float comparisons like that to work. > If they do they're asking for trouble. > All you're seeing is what the database is letting you see. Their "0" is not > really "0". > > Try this in your friendly C compiler > main() > { > double d = 22.35-(5.45+16.9); > printf("%f\n",d); > printf("%g\n",d); > printf("%e\n",d); > } > On both MS Visual C and gcc on a Linux system: > 0.000000 > 3.55271e-015 > 3.552714e-015 > > -----Original Message----- > From: sqlite-users-boun...@sqlite.org > [mailto:sqlite-users-boun...@sqlite.org] On Behalf Of Israel Lins > Albuquerque > Sent: Thursday, March 07, 2013 12:04 PM > To: sqlite-users@sqlite.org > Subject: [sqlite] Bug on real operations > > An example speaks more than words: > > Execute this: > SELECT 22.35 - (5.45 + 16.9), 22.35 = (5.45 + 16.9), (5.45 + 16.9) - 22.35; > > The expected result on almost databases is: > 0.0, true or 1, 0.0 > > But in sqlite for some reason they are: > 3.5527136788005e-15, 0, -3.5527136788005e-15 > > I thing this can be a bug on calculation of doubles. > > Regards, > Israel Lins Albuquerque > _______________________________________________ > 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 _______________________________________________ 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