Bug #67839 [NEW]: mysqli does not handle 4-byte floats correctly
| From: | keyur@php.net | Date: | Thu, 14 Aug 2014 05:36:01 +0000 |
| Subject: | Bug #67839 [NEW]: mysqli does not handle 4-byte floats correctly | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-187112@lists.php.net to get a copy of this message | ||
From: keyur@php.net
Operating system: Linux
PHP version: 5.4.31
Package: MySQLi related
Bug Type: Bug
Bug description:mysqli does not handle 4-byte floats correctly
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 bug report at https://bugs.php.net/bug.php?id=67839&edit=1
--