function Standard::pScalar_Float
File
-
vendor/
nikic/ php-parser/ lib/ PhpParser/ PrettyPrinter/ Standard.php, line 229
Class
Namespace
PhpParser\PrettyPrinterCode
protected function pScalar_Float(Scalar\Float_ $node) : string {
if (!is_finite($node->value)) {
if ($node->value === \INF) {
return '1.0E+1000';
}
if ($node->value === -\INF) {
return '-1.0E+1000';
}
else {
return '\\NAN';
}
}
// Try to find a short full-precision representation
$stringValue = sprintf('%.16G', $node->value);
if ($node->value !== (double) $stringValue) {
$stringValue = sprintf('%.17G', $node->value);
}
// %G is locale dependent and there exists no locale-independent alternative. We don't want
// mess with switching locales here, so let's assume that a comma is the only non-standard
// decimal separator we may encounter...
$stringValue = str_replace(',', '.', $stringValue);
// ensure that number is really printed as float
return preg_match('/^-?[0-9]+$/', $stringValue) ? $stringValue . '.0' : $stringValue;
}