Last active
April 7, 2017 13:49
-
-
Save mageekguy/d71e784ef046e0342d52cc5d5b6d8bd2 to your computer and use it in GitHub Desktop.
About PHP_INT_MAX
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# php --version | |
PHP 7.0.12 (cli) (built: Nov 3 2016 12:54:26) ( NTS ) | |
Copyright (c) 1997-2016 The PHP Group | |
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies | |
# php -a | |
php > var_dump((PHP_INT_MAX + 1) > PHP_INT_MAX); | |
bool(false) | |
php > var_dump((PHP_INT_MAX + 1) < PHP_INT_MAX); | |
bool(false) | |
php > var_dump((PHP_INT_MAX + 1) == PHP_INT_MAX); | |
bool(true) | |
php > var_dump((PHP_INT_MAX + 1000) == PHP_INT_MAX); | |
bool(true) |
Both are compared as float, so less significant digits are lost (63 bits for integer, 52 bits for float)
$ php -r 'var_dump(gmp_init(PHP_INT_MAX) + gmp_init(1) > gmp_init(PHP_INT_MAX));'
bool(true)
IIRC there is an old proposal to switch to gmp by default on interger overflow.
BTW, huge performance issue.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For the record,
(string) (PHP_INT_MAX + 1) > PHP_INT_MAX
works like a charm.