-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fix GH-13119: Changed to convert float and double values into strings using H
format
#13125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
--TEST-- | ||
GH-13119 (float, double value is incorrect) | ||
--EXTENSIONS-- | ||
pdo_firebird | ||
--SKIPIF-- | ||
<?php require('skipif.inc'); ?> | ||
--XLEAK-- | ||
A bug in firebird causes a memory leak when calling `isc_attach_database()`. | ||
See https://github.com/FirebirdSQL/firebird/issues/7849 | ||
--FILE-- | ||
<?php | ||
|
||
require("testdb.inc"); | ||
|
||
$dbh->exec('CREATE TABLE gh13119 (f_val FLOAT, d_val DOUBLE PRECISION)'); | ||
|
||
$dbh->exec('INSERT INTO gh13119 VALUES (0.1, 0.1)'); | ||
$dbh->exec('INSERT INTO gh13119 VALUES (0.0000000000000001, 0.0000000000000001)'); | ||
$dbh->exec('INSERT INTO gh13119 VALUES (12.000000, 12.00000000000000)'); | ||
$dbh->exec('INSERT INTO gh13119 VALUES (12.000001, 12.00000000000001)'); | ||
$dbh->exec('INSERT INTO gh13119 VALUES (12.345678, 12.34567890123456)'); | ||
$dbh->exec('INSERT INTO gh13119 VALUES (0.0000000000000000012345678, 0.000000000000000001234567890123456)'); | ||
|
||
$stmt = $dbh->query('select * from gh13119'); | ||
var_dump($stmt->fetchAll(PDO::FETCH_ASSOC)); | ||
?> | ||
--CLEAN-- | ||
<?php | ||
require 'testdb.inc'; | ||
@$dbh->exec('DROP TABLE gh13119'); | ||
unset($dbh); | ||
?> | ||
--EXPECT-- | ||
array(6) { | ||
[0]=> | ||
array(2) { | ||
["F_VAL"]=> | ||
string(3) "0.1" | ||
["D_VAL"]=> | ||
string(3) "0.1" | ||
} | ||
[1]=> | ||
array(2) { | ||
["F_VAL"]=> | ||
string(7) "1.0E-16" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder whether the use of scientific notation breaks BC somehow though, although in arithmetic they might not as they're numeric strings. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can do the calculations, so I think it's okay. |
||
["D_VAL"]=> | ||
string(7) "1.0E-16" | ||
} | ||
[2]=> | ||
array(2) { | ||
["F_VAL"]=> | ||
string(2) "12" | ||
["D_VAL"]=> | ||
string(2) "12" | ||
} | ||
[3]=> | ||
array(2) { | ||
["F_VAL"]=> | ||
string(9) "12.000001" | ||
["D_VAL"]=> | ||
string(17) "12.00000000000001" | ||
} | ||
[4]=> | ||
array(2) { | ||
["F_VAL"]=> | ||
string(9) "12.345678" | ||
["D_VAL"]=> | ||
string(17) "12.34567890123456" | ||
} | ||
[5]=> | ||
array(2) { | ||
["F_VAL"]=> | ||
string(13) "1.2345678E-18" | ||
["D_VAL"]=> | ||
string(21) "1.234567890123456E-18" | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if we need the unchecked variant now that we only pass one parameter. As I thought, the reason for the unchecked is to be able to pass the precision without the compiler freaking out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
Do you think it's better to use
zend_strpprintf
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the compiler doesn't complain, yes :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As you would expect, the compiler complained to me :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then the current PR is fine :)