Bug #4356 Math Functions Lack Precision (e.g. SQRT())
Submitted: 1 Jul 2004 5:30 Modified: 31 Jul 2004 21:27
Reporter: Bill Adams Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:4.0.20 OS:Linux (Linux)
Assigned to: Sergei Golubchik CPU Architecture:Any

[1 Jul 2004 5:30] Bill Adams
Description:
The SQRT() and other math functions lack precision for small numbers.

How to repeat:
mysql> select 5.0e-8 * 5.0e-8;
+-----------------+
| 5.0e-8 * 5.0e-8 |
+-----------------+
|         2.5e-15 |
+-----------------+
1 row in set (0.01 sec)

mysql> select sqrt( 2.5e-15 );
+-----------------+
| sqrt( 2.5e-15 ) |
+-----------------+
|        0.000000 |
+-----------------+
1 row in set (0.06 sec)

mysql>

Suggested fix:
Edit sql/item_func.h line 298 to read:

    decimals=NOT_FIXED_DEC; max_length=float_length(decimals);

(had decimals=6) 

Result:

mysql> select sqrt( 2.5e-15 );
+-----------------+
| sqrt( 2.5e-15 ) |
+-----------------+
|           5e-08 |
+-----------------+
1 row in set (0.01 sec)

mysql> select POW( 5e-8, 2 );
+----------------+
| POW( 5e-8, 2 ) |
+----------------+
|        2.5e-15 |
+----------------+
1 row in set (0.00 sec)
[31 Jul 2004 21:27] Sergei Golubchik
Thank you for your bug report. This issue has been committed to our
source repository of that product and will be incorporated into the
next release.

If necessary, you can access the source repository and build the latest
available version, including the bugfix, yourself. More information 
about accessing the source trees is available at
    http://www.mysql.com/doc/en/Installing_source_tree.html

Additional info:

fixed in 4.0.21
Thanks for the fix!