Bug #79955 [Opn->Nab]: converting large floats to int leads to overflow or the arithmetical unit

From: Date: Tue, 11 Aug 2020 20:35:12 +0000
Subject: Bug #79955 [Opn->Nab]: converting large floats to int leads to overflow or the arithmetical unit
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-228519@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=79955&edit=1 ID: 79955 Updated by: cmb@php.net Reported by: peter dot fargas at informatik-handwerk dot de Summary: converting large floats to int leads to overflow or the arithmetical unit -Status: Open +Status: Not a bug Type: Bug Package: Math related PHP Version: 8.0.0beta1 -Assigned To: +Assigned To: cmb Block user comment: N Private report: N New Comment: From the docs[1]: | If PHP encounters a number beyond the bounds of the integer | type, it will be interpreted as a float instead. Also, an | operation which results in a number beyond the bounds of the | integer type will return a float instead. and (float to int conversion): | If the float is beyond the boundaries of integer (usually +/- | 2.15e+9 = 2^31 on 32-bit platforms and +/- 9.22e+18 = 2^63 on | 64-bit platforms other than Windows prior to PHP 7), the result is | undefined, since the float doesn't have enough precision to give | an exact integer result. No warning, not even a notice will be | issued when this happens! [1] <https://www.php.net/manual/en/language.types.integer.php> Previous Comments: ------------------------------------------------------------------------ [2020-08-11 20:20:04] peter dot fargas at informatik-handwerk dot de Description: ------------ (int](PHP_MAX_INT + 1) returns \PHP_INT_MIN. Increasing the argument passed, zero result can be achieved. Same goes for the \intval() function. This happens for all current PHP versions - reported by https://3v4l.org/iDnt4 7.2.0 - 7.2.33, 7.3.0 - 7.3.21, 7.4.0 - 7.4.9 8.0.0alpha1 - beta1 Test script: --------------- <?php echo '---- INTMAX vs INTMAX+1'. \PHP_EOL; var_dump(\PHP_INT_MAX); var_dump(\PHP_INT_MAX+1); echo '---- INTMAX to float and back'. \PHP_EOL; var_dump(\intval((float)\PHP_INT_MAX)); var_dump((int)((float)\PHP_INT_MAX)); echo '---- INTMAX+1 to float and back'. \PHP_EOL; var_dump(\intval(\PHP_INT_MAX+1)); var_dump((int)(\PHP_INT_MAX+1)); var_dump(\PHP_INT_MIN); echo '---- ...rendezvous point is...'. \PHP_EOL; var_dump(\intval(18446744073709551615)); Expected result: ---------------- one of: - \PHP_MAX_INT (just as the documentation states), a sign stable result - type error - zero Actual result: -------------- overflow or the arithmetical unit ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=79955&edit=1

« previous php.bugs (#228519) next »