[Issue 20205] std.math: Wrong result for abs(int.min)

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Sep 12 07:59:47 UTC 2019


https://issues.dlang.org/show_bug.cgi?id=20205

Dominikus Dittes Scherkl <dominikus at scherkl.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dominikus at scherkl.de

--- Comment #1 from Dominikus Dittes Scherkl <dominikus at scherkl.de> ---
Use better implementation of abs:

/// get the absolute value of x as unsigned type. always succeeds, even for
T.min
Unsigned!T abs(T)(const(T) x) if(isIntegral!T)
{
   static if(isSigned!T) if(x < 0) return -x;
   return x;
}

--


More information about the Digitalmars-d-bugs mailing list