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

From: Date: Thu, 11 Feb 2021 18:12:35 +0000
Subject: Bug #80732 [Opn->Nab]: 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-232075@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
 Updated by:         requinix@php.net
 Reported by:        809721719 at qq dot com
 Summary:            The sum of two large integers lead to errors when
                     overflow occurs.
-Status:             Open
+Status:             Not a bug
 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:

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php

https://www.php.net/manual/en/language.types.integer.php
> If PHP encounters a number beyond the bounds of the int type, it will be
> interpreted as a float instead. Also, an operation which results in a number
> beyond the bounds of the int type will return a float instead.

> When converting from float to int, the number will be rounded towards zero.
>
> If the float is beyond the boundaries of int (usually +/- 2.15e+9 = 2^31 on
> 32-bit platforms and +/- 9.22e+18 = 2^63 on 64-bit platforms), the result is
> undefined, since the float doesn't have enough precision to give an exact int
> result. No warning, not even a notice will be issued when this happens!


Previous Comments:
------------------------------------------------------------------------
[2021-02-11 17:15:45] 809721719 at qq dot com

Summary is modified.

------------------------------------------------------------------------
[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


Thread (5 messages)

« previous php.bugs (#232075) next »