Bug #8048 | SQL Failed: Query Match For Float Data Type | ||
---|---|---|---|
Submitted: | 20 Jan 2005 15:37 | Modified: | 20 Jan 2005 16:51 |
Reporter: | Zhen Ou | Email Updates: | |
Status: | Not a Bug | Impact on me: | |
Category: | MySQL Server | Severity: | S3 (Non-critical) |
Version: | 4.0.21 | OS: | Unix/Window |
Assigned to: | CPU Architecture: | Any |
[20 Jan 2005 15:37]
Zhen Ou
[20 Jan 2005 15:52]
Frank Mussmann
No error. It's just the binary Version of float. :-)
[20 Jan 2005 15:57]
Frank Mussmann
float is 4 Bytes. so your range is from -3.40E+38 to 1.17E-38 double is 8 Bytes (E+308- E-308) In 4 Bytes you can just do this: 2^-1 =0,5 2^-2 =0,25 2^-3 =0,125 2^-4 =0,0625 ... When you have your floats, the CPU tries to compute a Binary for these Floats. This is not possible for many floats. When you make a query , your inputs like f1=0.2341 then the 0.2341 is interpreted as double ! :-) this is the reason, why cou can compare the double with the same double input :-)
[20 Jan 2005 16:04]
Zhen Ou
I think I have a better understanding now. Thanks. How would you change the sql to make it work? (SELECT * FROM `test` WHERE `f1` = 13.453) thanks.
[20 Jan 2005 16:12]
Zhen Ou
This sql statement would work but then how you you know f1 contains 3 decimal point to begin with. Works, but not accurate: SELECT * FROM `test` WHERE format(`f1`, 2) = format(13.45, 2) Works: SELECT * FROM `test` WHERE format(`f1`, 3) = format(13.45, 3) thx
[20 Jan 2005 16:51]
MySQL Verification Team
Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.mysql.com/documentation/ and the instructions on how to report a bug at http://bugs.mysql.com/how-to-report.php Additional info: Please, take a look at: http://dev.mysql.com/doc/mysql/en/Problems_with_float.html