mirror of
https://github.com/phabelio/PHP-Parser.git
synced 2024-11-30 04:29:15 +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:
parent
9caa51b3a5
commit
8b64195cf2
@ -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;
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user