Re: How to detect overflow

2015-11-04 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Wednesday, 4 November 2015 at 10:06:47 UTC, Ali Çehreli wrote: Thanks. It looks like I've been making stuff up on this page: :( http://ddili.org/ders/d.en/arithmetic.html It's a common source for confusion, the word "underflow" is a bit misleading. Maybe better to use the term "zero-flus

Re: How to detect overflow

2015-11-04 Thread Ali Çehreli via Digitalmars-d-learn
On 11/04/2015 02:01 AM, Ola Fosheim Grøstad wrote: On Wednesday, 4 November 2015 at 08:18:00 UTC, Ali Çehreli wrote: Thanks. I've noticed that the parameter of the subtraction functions should be named 'underflow', no? Integer math cannot underflow, unless you define division to be equivalent

Re: How to detect overflow

2015-11-04 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Wednesday, 4 November 2015 at 08:18:00 UTC, Ali Çehreli wrote: Thanks. I've noticed that the parameter of the subtraction functions should be named 'underflow', no? Integer math cannot underflow, unless you define division to be equivalent to division over reals. overflow => higher/lower

Re: How to detect overflow

2015-11-04 Thread Ali Çehreli via Digitalmars-d-learn
On 11/03/2015 11:34 PM, BBasile wrote: On Wednesday, 4 November 2015 at 07:19:09 UTC, Ali Çehreli wrote: On 11/03/2015 10:34 PM, Namal wrote: 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 fu

Re: How to detect overflow

2015-11-04 Thread Ali Çehreli via Digitalmars-d-learn
On 11/04/2015 12:11 AM, Namal wrote: >> 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 > > wow,

Re: How to detect overflow

2015-11-04 Thread Namal via Digitalmars-d-learn
On Wednesday, 4 November 2015 at 07:59:44 UTC, Ali Çehreli wrote: 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

Re: How to detect overflow

2015-11-04 Thread Ali Çehreli via Digitalmars-d-learn
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.

Re: How to detect overflow

2015-11-03 Thread Namal via Digitalmars-d-learn
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 c

Re: How to detect overflow

2015-11-03 Thread BBasile via Digitalmars-d-learn
On Wednesday, 4 November 2015 at 07:19:09 UTC, Ali Çehreli wrote: On 11/03/2015 10:34 PM, Namal wrote: 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? Yeah, looks like classic co

Re: How to detect overflow

2015-11-03 Thread Ali Çehreli via Digitalmars-d-learn
On 11/03/2015 10:34 PM, Namal wrote: 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? Yeah, looks like classic copy-paste errors. :) Ali

Re: How to detect overflow

2015-11-03 Thread Namal via Digitalmars-d-learn
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 c

Re: How to detect overflow

2015-11-03 Thread BBasile via Digitalmars-d-learn
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_checkedin

How to detect overflow

2015-11-03 Thread Namal via Digitalmars-d-learn
Is there a way to detect overflow for example for: int i = 2_000_000_000; int a = i*i*i; writeln(a); -> 1073741824