php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #68657 Reading 4 byte floats with Mysqli and libmysqlclient has rounding errors
Submitted: 2014-12-26 21:55 UTC Modified: 2015-01-07 23:25 UTC
From: keyur@php.net Assigned: keyur
Status: Closed Package: MySQLi related
PHP Version: 5.5.20 OS: Any
Private report: No CVE-ID:
 [2014-12-26 21:55 UTC] keyur@php.net
Description:
------------
This is similar to the bug 67839.

The patch for that was only done to the mysqlnd driver and needs to be reapplied to the libmysqlclient driver as well.

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:
        $id = null;
        $fp4 = null;
        $fp8 = null;

        $stmt = mysqli_prepare($link, "SELECT * FROM test");
        mysqli_stmt_bind_result($stmt, $id, $fp4, $fp8);
        mysqli_stmt_execute($stmt);
        mysqli_stmt_fetch($stmt);

        $test = array($id, $fp4, $fp8);

        var_dump($test);


Expected result:
----------------
It should be:
array(3) {
  [0]=>
  int(1)
  [1]=>
  float(9.9999)
  [2]=>
  float(9.9999)
}

Actual result:
--------------
The output will be:
array(3) {
  [0]=>
  int(1)
  [1]=>
  float(9.9998998642)
  [2]=>
  float(9.9999)
}

Patches

Add a Patch

Pull Requests

Pull requests:

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-12-26 21:56 UTC] keyur@php.net
-Assigned To: +Assigned To: keyur
 [2015-01-07 23:25 UTC] keyur@php.net
-Status: Assigned +Status: Closed
 [2015-01-07 23:25 UTC] keyur@php.net
The fix for this bug has been committed.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Mon Apr 24 16:01:44 2017 UTC