1
0
mirror of https://github.com/danog/PHP-Parser.git synced 2024-11-26 20:04:48 +01:00

Try .17G print if .16G is not enough

This should be enough for all cases, because: A double has 53 bits
of mantissa (including the implicit 1 bit), which is 53*ln(2)/ln(10)
= 15.95 decimal digits. However the leading decimal digit may encode
less than the usual 3.32 bits, which will push this over the edge to
requiring 17 decimal digits.
This commit is contained in:
Nikita Popov 2015-05-02 11:48:55 +02:00
parent 9caa51b3a5
commit 8b64195cf2
2 changed files with 5 additions and 0 deletions

View File

@ -97,6 +97,9 @@ class Standard extends PrettyPrinterAbstract
public function pScalar_DNumber(Scalar\DNumber $node) {
$stringValue = sprintf('%.16G', $node->value);
if ($node->value !== (double) $stringValue) {
$stringValue = sprintf('%.17G', $node->value);
}
// ensure that number is really printed as float
return preg_match('/^-?[0-9]+$/', $stringValue) ? $stringValue . '.0' : $stringValue;

View File

@ -38,6 +38,7 @@ FALSE;
1E-100;
1000000000000000000000000000000000000000000000000000000000000000000000000000000000000;
378282246310005.0;
10000000000000002.0;
// strings (normalized to single quoted)
'a';
@ -114,6 +115,7 @@ INF;
1.0E-100;
1.0E+84;
378282246310005.0;
10000000000000002.0;
// strings (normalized to single quoted)
'a';
'a