Parse number as floating-point if it doesn't fit in integer; try hard to use integer when possible though #1

Merged
m.kuleshov merged 1 commits from feature/ints_overflow into master 2024-03-21 16:04:17 +03:00
1 changed files with 8 additions and 2 deletions
Showing only changes of commit ce8fe5c99b - Show all commits

View File

@ -293,10 +293,16 @@ class jzonParser
} }
$str_num = substr($this->in, $start, $this->c - $start); $str_num = substr($this->in, $start, $this->c - $start);
$fval = floatval($str_num);
$ival = intval($str_num);
if($is_float) if($is_float)
$out = floatval($str_num); $out = $fval;
else if(($ival < PHP_INT_MAX && $ival > PHP_INT_MIN) || strval($ival) === $str_num)
$out = $ival;
else else
$out = intval($str_num); $out = $fval;
} }
private function parse_true(&$out) private function parse_true(&$out)