On Friday, 24 June 2016 at 17:25:32 UTC, Dominikus Dittes Scherkl wrote:
I have a save exponentiation function (+ two helper functions that may also be useful on their own):

Ah, and I use a better abs() function:

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

unittest
{
   byte a = -128;
   auto b = abs(a);
   assert(is(typeof(b) == ubyte));
   assert(b == 128);
}

Reply via email to