Bug #80732 [Opn]: The sum of two large integers lead to errors when overflow occurs.

From: Date: Thu, 11 Feb 2021 17:15:45 +0000
Subject: Bug #80732 [Opn]: The sum of two large integers lead to errors when overflow occurs.
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-232070@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: The addition of two large integers lead to errors when overflow occurs. +Summary: The sum 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: Summary is modified. Previous Comments: ------------------------------------------------------------------------ [2021-02-11 16:57:56] 809721719 at qq dot com Modification summary ------------------------------------------------------------------------ [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

« previous php.bugs (#232070) next »