How to detect overflow
Ali Çehreli via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Nov 3 23:59:44 PST 2015
On 11/03/2015 11:52 PM, Namal wrote:
>> http://dlang.org/phobos/core_checkedint.html
>
> It says:
>
>
> "The overflow is sticky, meaning a sequence of operations can be done
> and overflow need only be checked at the end."
>
> But how can I make multiple operations? I can only put 2 values in the
> function.
import core.checkedint;
void main() {
bool overflowed;
auto result = adds(int.max, 1, overflowed); // this overflows
adds(1, 2, overflowed); // this does not reset the flag
assert(overflowed);
}
Ali
More information about the Digitalmars-d-learn
mailing list