There are a small number of floating point numbers which are almost always exactly testable for equality, namely those you have confidence of exact storage. Positive zero is good, although negative zero sometimes causes problems; you can't always assume they're the same number. Smallish integers multiplied or divided by smallish powers of two are probably okay, so 3.25 is probably okay while 3.250000000001 and 52.3 are definitely not. In most programming languages, if you want to check (near) equality of floating point numbers you need to think about how many significant bits you might have in the relevant mantissa, and check the absolute value of the difference between what you have and what you're looking for, possibly scaled for the exponent concerned.
On Tue, Mar 4, 2014 at 3:20 PM, Richard Hipp <d...@sqlite.org> wrote: > On Mon, Mar 3, 2014 at 11:14 PM, Donald Shepherd > <donald.sheph...@gmail.com>wrote: > > > It appears that using equals on floating point (REAL) data in WHERE > clauses > > doesn't necessarily work, presumably because of rounding errors - see > below > > for an example. Is this the case? Do I need to use BETWEEN instead of = > > as I expect to be the case? > > > > Never (well, almost never) use == with floating point numbers. This rule > applies to all systems, 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 > -- Christopher Vance _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users