Logo

Programming-Idioms

History of Idiom 86 > diff from v18 to v19

Edit summary for version 19 by daxim:
New Perl implementation by user [daxim]

Version 18

2019-02-01, 05:08:43

Version 19

2019-09-27, 23:34:40

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
sub multiply_will_overflow {
    my ($x, $y) = @_;
    return 'Inf' eq $x * $y;
}
Doc URL
http://p3rl.org/data#Special-floating-point:-infinity-%28Inf%29-and-not-a-number-%28NaN%29