Programming-Idioms

History of Idiom 86 > diff from v2 to v3

Edit summary for version 3 :

Version 2

2015-09-09, 21:27:37

Version 3

2015-09-10, 18:36:04

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.

Imports
import core.checkedint;
Code
bool multiplyWillOverflow(int x, int y)
{
    bool result;
    core.checkedint.muls(x, y, result);
    return result;
}
Doc URL
http://dlang.org/phobos/core_checkedint.html#.muls
Demo URL
http://dpaste.dzfl.pl/b9a4af2e5249