smartOp.abs

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

  1. Unsigned!N abs(const N num)
  2. IntFromChar!N abs(const N num)
    template smartOp(IntFlagPolicy policy)
    IntFromChar!N
    abs
    pure @safe nothrow @nogc
    (
    N
    )
    (
    const N num
    )
    if (
    isSomeChar!N
    )

Examples

1 import checkedint.sticky : smartOp; // smartOp.abs() never throws
2 
3 assert(smartOp.abs(int.min) == std.math.pow(2.0, 31));
4 assert(smartOp.abs(-25) == 25u);
5 assert(smartOp.abs(745u) == 745u);

Meta