Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Explain why -9223372036854775808 is a float, not PHP_INT_MIN - #6092

Merged
lacatoire merged 1 commit into
php:masterfrom
officialasishkumar:integer-literal-php-int-min
Nov 16, 2026
Merged

lacatoire merged 1 commit into
php:masterfrom
officialasishkumar:integer-literal-php-int-min

Conversation

@officialasishkumar

Copy link
Copy Markdown
Contributor

A negative int literal is a positive literal with the negation operator applied to it. In -9223372036854775808, the literal 9223372036854775808 is beyond PHP_INT_MAX on 64-bit systems, so it is already a float when it gets negated, and -9223372036854775808 === PHP_INT_MIN is false (the same happens with -2147483648 on 32-bit systems). The integer page says nothing about this, which is what #2400 ran into.

This adds a paragraph and an example to the "Integer overflow" section that explain it and point to PHP_INT_MIN, or an expression such as -9223372036854775807 - 1, instead. The example output was checked on PHP 7.4, 8.5 and 8.6. configure.php and docbook-cs pass locally.

Fixes #2400

A negative int literal is a positive literal with the negation operator
applied to it. The literal 9223372036854775808 is beyond PHP_INT_MAX on
64-bit systems, so it is already a float when it is negated, and
-9223372036854775808 === PHP_INT_MIN is false. The same happens with
-2147483648 on 32-bit systems.

Add a paragraph and an example to the integer overflow section that
explain this and point to PHP_INT_MIN, or an expression such as
-9223372036854775807 - 1, instead. The example output was checked on
PHP 7.4, 8.5 and 8.6.

Fixes php#2400

@lacatoire lacatoire left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect behavior of literal value of PHP_INT_MIN

2 participants