Skip to content

Instantly share code, notes, and snippets.

@hipertracker
Created January 7, 2009 10:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hipertracker/44238 to your computer and use it in GitHub Desktop.
Save hipertracker/44238 to your computer and use it in GitHub Desktop.
<?php
# PHP does not recognize long int.
# It recognize only signed int32.
var_dump(is_float(pow(2,30))); # false
var_dump(is_float(pow(2,31))); # true (sic!)
# Even if PHP keep long int internaly as floats,
# it displays them in inconsistent way:
print pow(2,31)."\n"; # 2147483648
var_dump(pow(2,31));
print pow(2,39)."\n"; # 549755813888 ... WTF?
var_dump(pow(2,39)); # float(549755813888)
print pow(2,40)."\n"; # 1.09951162778E+12
var_dump(pow(2,40)); # float(1.09951162778E+12)
# But do really floats are always floats? It depends :P
var_dump(-2147483648); # float(-2147483648)
# but
var_dump(-2147483647 - 1); # int(-2147483648)
var_dump(-PHP_INT_MAX -1); # int(-2147483648)
# so THE SAME number may be int or float. If it is not schizofrenic,
# it is maybe php fuzzy logic :P
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment