smartOp.abs

Get the absolute value of num. Because the return type is always unsigned, overflow is not possible.

  1. Unsigned!N abs(N num)
    template smartOp(IntFlagPolicy policy)
    pure @safe nothrow @nogc
    static if(policy == IntFlagPolicy.none)
    Unsigned!N
    abs
    (
    N
    )
    (
    const N num
    )
    if (
    isIntegral!N
    )
  2. IntFromChar!N abs(N num)
  3. alias abs = smartOp!(IntFlagPolicy.none).abs

Examples

import checkedint.sticky : smartOp; // smartOp.abs() never throws

assert(smartOp.abs(int.min) == std.math.pow(2.0, 31));
assert(smartOp.abs(-25) == 25u);
assert(smartOp.abs(745u) == 745u);

Meta