In doc '21.19 Solving Problems with No Matching Rows' item 5 states.

> 5.If you are comparing FLOAT or DOUBLE columns with numbers that have decimals, you 
>can't use =! This problem is common in > most
computer languages because floating-point values are
>      not exact values:
>
 >     mysql> SELECT * FROM table_name WHERE float_column=3.5;
>         ->
>      mysql> SELECT * FROM table_name WHERE float_column between 3.45 and 3.55;
>
>     In most cases, changing the FLOAT to a DOUBLE will fix this!

This is just plain wrong. Floating point values are precise and since the advent of 
the IEEE standard
are generally the same across platforms. The following example fails and is a bug not 
a problem
with "the language" or the hardware.

CREATE TABLE bug1 (
  floatType float default NULL
) TYPE=MyISAM;
DESCRIBE bug1;
INSERT INTO bug1 VALUES (0.0);
INSERT INTO bug1 VALUES (1.0);
INSERT INTO bug1 VALUES (1.23);
INSERT INTO bug1 VALUES (1.5);
SELECT * FROM bug1 ;
SELECT * FROM bug1 WHERE floatType=0.0 ;
SELECT * FROM bug1 WHERE floatType=1.0 ;
SELECT * FROM bug1 WHERE floatType=1.23 ; /* no record returned */
SELECT * FROM bug1 WHERE floatType=1.5 ;

(The above test was run with an HP client and sever, I haven't run other combinations)

There are three possible source for the error.
1) The hardware if a floating point processor is being used (not very likely).
2) The OS encode/decode statement if no fpp is being used (I've seen this problem in 
the past but
it is not very likely today).
3) Encode/decode routines used within MySQL. I don't know the design of MySQL so I
don't know if this is possible but if and attempt is made to standardize the bit 
pattern stored
on disk for float values then it is the most likely cause of the problem.

BTW: The solution proposed in the documentation is completely unacceptable when you 
are trying to
update a record based on its value. If you used the suggested procedure then you would 
update all
the records between 3.45 and 3.55 which is not acceptable.

Regards,
Tom Krehbiel


---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to