Bug #67839 [Com]: mysqli does not handle 4-byte floats correctly
| From: | keyur_govande at yahoo dot com | Date: | Thu, 14 Aug 2014 05:40:28 +0000 |
| Subject: | Bug #67839 [Com]: mysqli does not handle 4-byte floats correctly | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-187113@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=67839&edit=1
ID: 67839
Comment by: keyur_govande at yahoo dot com
Reported by: keyur@php.net
Summary: mysqli does not handle 4-byte floats correctly
Status: Open
Type: Bug
Package: MySQLi related
Operating System: Linux
PHP Version: 5.4.31
Block user comment: N
Private report: N
New Comment:
The patch for this bug is here: https://gist.github.com/keyurdg/9c99da11848ac7589e66
Previous Comments:
------------------------------------------------------------------------
[2014-08-14 05:36:00] keyur@php.net
Description:
------------
mysqli does not handle 4-byte floats correctly. It casts it into a double which essentially
increases the "error" in the IEEE-754 FP number.
Consider the following C code:
float a = 99.99f;
double b = (double) a;
The output will be:
a = 99.9899979
b = 99.989997863769531
b will never be printed as 99.99
Test script:
---------------
On a MySQL DB, run the following queries:
CREATE TABLE test(id INT PRIMARY KEY, fp4 FLOAT, fp8 DOUBLE) ENGINE = InnoDB;
INSERT INTO test(id, fp4, fp8) VALUES (1, 9.9999, 9.9999)
Now using mysqli, SELECT the one row out:
if (!($stmt = mysqli_prepare($link, "SELECT id, fp4, fp8 FROM test"))) {
die();
}
if (!mysqli_stmt_execute($stmt)) {
die();
}
if (!($result = mysqli_stmt_get_result($stmt))) {
die();
}
$data = mysqli_fetch_assoc($result);
print $data['id'] . ": " . $data['fp4'] . ": " .
$data['fp8'] . "\n";
Expected result:
----------------
It should be:
1: 9.9999: 9.9999
Actual result:
--------------
The output will be:
1: 9.9998998641968: 9.9999
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=67839&edit=1