Programming-Idioms

History of Idiom 86 > diff from v23 to v24

Edit summary for version 24 :
[D] DPaste has been down for a while ✝

Version 23

2020-05-21, 20:16:53

Version 24

2020-05-21, 22:08:22

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