PHP float to int cast erratic behavior -
at least on machine:
$var = php_int_max; var_dump($var); $var++; var_dump((int)$var); $var += 10; var_dump((int)$var); $var += 10000; var_dump((int)$var);
results:
int(9223372036854775807) int(-9223372036854775808) int(-9223372036854775808) int(-9223372036854765568)
why behavior crazy? understand returing php_min_int every time, if add numbers changes?
i these results when run code here:
it's undefined, float doesn't fit in integer. can happen. it's php, quirks. operation of casting implemented using (long)
cast operation in c, undefined in case, shouldn't depend on particular behavior (in fact, on platforms, mips64, cause cpu exception, stop php).
source: http://www.php.net/manual/en/language.types.integer.php#language.types.integer.casting.from-float
Comments
Post a Comment