
Error 3849 when doing SELECT on floating-point field (type adDouble)
Chris, I respect your opinions, you've been very helpful to me in the past
with your postings, I think I even have one of your books ... but I can't
agree with you here. This is a bug. It's not an issue with floating-point
representation. Keld has already gone into some of the details of the IEEE
floating-point format in a different posting so I won't belabor that here,
and besides that's not really my point.
OK, so the Microsoft docs (adoce31.chm) say:
"An error results if an SQL statement uses the equal operator (=) or the not
equal (<>) operator to compare floating-point data types.
...
Floating point comparisons are approximate. Testing for equality against
floating point values is not supported and returns an invalid field
comparison error. "
Hmm. So, it's documented, does that mean it's not a bug? Can I let
Microsoft off the hook here just because they wrote it down and said "sorry
it doesn't do that?" I don't think so.
The floating-point comparisons in the SELECTs from my original post may be a
bad idea for some values because of approximation issues, true. But, they
are still perfectly valid, well-formed SQL statements. If they fail to find
any records because of approximate representation in floating-point numbers,
so be it -- return 0 records and let me figure out why. I have to do that
on all searches, let the user know what happened, take appropriate recovery
actions etc. Normal stuff for a database app.
Raising an error, on the other hand, is entirely inappropriate. There is no
error in the SQL statement itself. I have to structure my code differently
and write a workaround each time this situation comes up. And, this same
problem does not occur in SQL Server, MS Access 97 & 2000, and probably lots
of other database platforms that implement SQL SELECT statements. They just
convert the search value to a float and do the search and return the
records, exactly as you'd expect.
So I say it's a bug. Bug bug bug bug bug bug bug. So there, Microsoft!
You have a bug!
Does Microsoft care? Does my considered opinion wound them deeply? Well,
no. They don't give a hoot. Am I bitter? Oh no, not me...
--
Terry
Terry McKiernan
pinpoint tools
www.pinpointtools.com
We Make ACT! Work Better!
Quote:
> That's assuming this is a bug, which I'm not convinced it is.
> When using floating point variables (which is the case here) equality and
> inequality operators should never be used, because of the simple nature of
> floating point numbers. As I was telling Terry offline, setting the field
> to a value of "1" does not mean that it will inherently be exactly 1. It
> will very likely be *near* the value 1, but will probably differ somewhere
> out a dozen or so decimal places.
> If you need to do comparisons against integers, use an integer field or
use
> range comparisons.
> --
> Chris Tacke, eMVP
> Windows CE Product Manager
> Applied Data Systems
> www.applieddata.net
> > > Basically, this is a known bug but it is very poorly documented,
hidden
> in
> > a
> > > note about the SELECT statement in MS's docs on ADOCE. The = and <>
> > > operators just don't work with floating-point values.
> > All I'm wondering is: Will there ever be a fix for all the known bugs?
> > Probably no, as MS wants us all to move to the .NET platform. But then
> what
> > about the bugs on that platform? Do we dare to use it as MS platforms
seem
> > to be abandoned almost as fast as they get designed?
> > Just wondering.
> > Keld Laursen