How to detect overflow

Namal via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Nov 3 22:34:02 PST 2015


On Wednesday, 4 November 2015 at 04:22:03 UTC, BBasile wrote:
> On Wednesday, 4 November 2015 at 03:55:13 UTC, Namal wrote:
>> Is there a way to detect overflow for example for:
>>
>> 	int i = 2_000_000_000;
>> 	
>> 	int a = i*i*i;
>> 	
>> 	writeln(a);
>>
>> -> 1073741824
>
> You can use core.checkedint [1]
>
> ---
>
> http://dlang.org/phobos/core_checkedint.html

Is it just an error in the documentation that the return value is 
stated as sum for the multiplication functions?


More information about the Digitalmars-d-learn mailing list