[Issue 8666] std.math.abs(int.min) returns int.min

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Jan 24 01:51:14 PST 2014


https://d.puremagic.com/issues/show_bug.cgi?id=8666



--- Comment #3 from Don <clugdbug at yahoo.com.au> 2014-01-24 01:50:36 PST ---
This is just a consequence of the fact that overflow checking never happens for
integral types.

int x = abs(int.min);

returns an incorrect result, in the same way that

int y = int.max + int.max;

returns an incorrect result. There's really nothing special going on here, all
of the types are correct. It's not unsigned, there is no doubt about how to
interpret the number -- it's positive. It just doesn't fit!

If we declare that integer overflow is an error, as has been proposed a few
times, we could use bound checking to statically detect some of these cases.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list