Bug #4284 user variable problem
Submitted: 25 Jun 2004 11:09 Modified: 28 Jun 2004 13:12
Reporter: CW WAN Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:4.0.20a OS:Windows (windows 2000)
Assigned to: Sergei Golubchik CPU Architecture:Any

[25 Jun 2004 11:09] CW WAN
Description:
i have table name test1
here is sample data inside this table

SELECT *
FROM `test1`

+---------+--------+---------+
| dat_1   | dat_2  | dat_3   |
+---------+--------+---------+
| 10.0000 | 4.5000 | 55.0000 |
| 13.0000 | 4.5000 | 31.0000 |
| 12.0000 | 3.7000 | 51.0000 |
| 10.0000 | 4.5000 | 55.0000 |
+---------+--------+---------+

but when execute this statement
set @c:=0,@d:=0;
SELECT *, @c:=1-(dat_3/100), @d:=dat_2/@c, @c:=dat_1-@d FROM test1;

+---------+--------+---------+-------------------+-----------------+-----------------------+
| dat_1   | dat_2  | dat_3   | @c:=1-(dat_3/100) | @d:=dat_2/@c    | @c:=dat_1-@d          |
+---------+--------+---------+-------------------+-----------------+-----------------------+
| 10.0000 | 4.5000 | 55.0000 |          0.450000 |              10 | -1.7763568394003e-015 |
| 13.0000 | 4.5000 | 31.0000 |          0.690000 | 6.5217391304348 |       6.4782608695652 |
| 12.0000 | 3.7000 | 51.0000 |          0.490000 | 7.5510204081633 |       4.4489795918367 |
| 10.0000 | 4.5000 | 55.0000 |          0.450000 |              10 | -1.7763568394003e-015 |
+---------+--------+---------+-------------------+-----------------+-----------------------+

i have try to run this statement on 4.0.16 to 4.0.20a, it return wierd result, hope someone can help me

thanks

How to repeat:
select @a:=10, @b:=4.5, @c:=1-(55/100),@d:=@b/@c, @c:=@a-@d

+--------+---------+----------------+-----------+-----------------------+
| @a:=10 | @b:=4.5 | @c:=1-(55/100) | @d:=@b/@c | @c:=@a-@d             |
+--------+---------+----------------+-----------+-----------------------+
|     10 |     4.5 |           0.45 |        10 | -1.7763568394003e-015 |
+--------+---------+----------------+-----------+-----------------------+
[28 Jun 2004 13:12] Sergei Golubchik
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:

Why do you think it's a bug ?
floating-point values are inherently inprecise. 1e-15 is the precision error one could except.