Programming-Idioms

History of Idiom 86 > diff from v11 to v12

Edit summary for version 12 :
New PHP implementation by user [agilla1]

Version 11

2016-02-21, 17:17:55

Version 12

2016-02-25, 21:05:44

Idiom #86 Check if integer multiplication will overflow

Write boolean function multiplyWillOverflow which takes two integers x, y and return true if (x*y) overflows.

Idiom #86 Check if integer multiplication will overflow

Write boolean function multiplyWillOverflow which takes two integers x, y and return true if (x*y) overflows.

Code
function multiplyWillOverflow($x, $y)
{
      return ($x * $y) > PHP_INT_MAX;
}
Comments bubble
PHP_INT_MAX has different values on 32bit vs 64bit machines
Doc URL
http://php.net/manual/en/reserved.constants.php