Correctly pretty print negative floats

This commit is contained in:
Tomáš Polomský 2014-03-16 21:50:06 +01:00 committed by nikic
parent 8c59f41d02
commit c8c233f900
2 changed files with 37 additions and 2 deletions

View File

@ -98,7 +98,7 @@ class Standard extends PrettyPrinterAbstract
$stringValue = (string) $node->value;
// ensure that number is really printed as float
return ctype_digit($stringValue) ? $stringValue . '.0' : $stringValue;
return preg_match('/^-?[0-9]+$/', $stringValue) ? $stringValue . '.0' : $stringValue;
}
// Assignments

View File

@ -0,0 +1,35 @@
Number literals
-----
<?php
0;
+0;
-0;
0.0;
-0.0;
42;
-42;
42.0;
-42.0;
42.5;
-42.5;
1e42;
-1e42;
1e1000;
-1e1000;
-----
0;
+0;
-0;
0.0;
-0.0;
42;
-42;
42.0;
-42.0;
42.5;
-42.5;
1.0E+42;
-1.0E+42;
INF;
-INF;