Bug #67839 [Opn->Csd]: mysqli does not handle 4-byte floats correctly

From: Date: Fri, 15 Aug 2014 23:52:48 +0000
Subject: Bug #67839 [Opn->Csd]: mysqli does not handle 4-byte floats correctly
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-187144@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 Updated by: keyur@php.net Reported by: keyur@php.net Summary: mysqli does not handle 4-byte floats correctly -Status: Open +Status: Closed Type: Bug Package: MySQLi related Operating System: Linux PHP Version: 5.4.31 -Assigned To: +Assigned To: keyur Block user comment: N Private report: N New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [2014-08-14 05:40:28] keyur_govande at yahoo dot com The patch for this bug is here: https://gist.github.com/keyurdg/9c99da11848ac7589e66 ------------------------------------------------------------------------ [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

« previous php.bugs (#187144) next »