Bug #80732 [Opn]: The addition of two large integers lead to errors when overflow occurs.
| From: | 809721719 at qq dot com | Date: | Thu, 11 Feb 2021 16:57:56 +0000 |
| Subject: | Bug #80732 [Opn]: The addition of two large integers lead to errors when overflow occurs. | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-232069@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=80732&edit=1
ID: 80732
User updated by: 809721719 at qq dot com
Reported by: 809721719 at qq dot com
-Summary: large integer operating addition error when overflow
+Summary: The addition of two large integers lead to errors
when overflow occurs.
Status: Open
Type: Bug
Package: *General Issues
Operating System: MacOS 10.14 (64bit)
PHP Version: 7.4.15
Block user comment: N
Private report: N
New Comment:
Modification summary
Previous Comments:
------------------------------------------------------------------------
[2021-02-11 16:30:05] 809721719 at qq dot com
Description:
------------
The addition of two integers exceeds the maximum value of the integer. After an overflow occurs, the
resulting value is distorted.
I test in C/C++/Go and got different results from PHP, but they get the same results.
Test script:
---------------
var_dump(intval(9223372036854775807 + 1));
// int(-9223372036854775808)
var_dump(intval(9223372036854775807 + 2));
// int(-9223372036854775808)
var_dump(intval(9223372036854775807 + 3));
// int(-9223372036854775808)
Expected result:
----------------
int(-9223372036854775808)
int(-9223372036854775807)
int(-9223372036854775806)
Actual result:
--------------
int(-9223372036854775808)
int(-9223372036854775808)
int(-9223372036854775808)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=80732&edit=1