smartOp.pow

Raise base to the exp power.

Errors that may be signalled if neither input is floating-point:

  • IntFlag.posOver or IntFlag.negOver if the absolute value of the result is too large to represent with the return type.
  • IntFlag.div0 if base == 0 and exp < 0.
  1. auto pow(N base, M exp)
    template smartOp(IntFlagPolicy policy)
    pure @safe nothrow @nogc
    pow
    (
    N
    M
    )
    (
    const N base
    ,
    const M exp
    )
    if (
    (
    isFloatingPoint!N &&
    isScalarType!M
    )
    ||
    (
    isScalarType!N &&
    isFloatingPoint!M
    )
    )
  2. auto pow(N base, M exp)

Examples

import checkedint.sticky : smartOp; // use IntFlagPolicy.sticky

assert(smartOp.pow(-10, 3) == -1_000);
assert(smartOp.pow(16, 4uL) == 65536);
assert(smartOp.pow(2, -1) == 0);

smartOp.pow(-3, 27);
assert(IntFlags.local.clear() == IntFlag.negOver);
smartOp.pow(0, -5);
assert(IntFlags.local.clear() == IntFlag.div0);

Meta