safeOp.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.
  • exp < 0, IntFlag.undef is raised because std.math.pow would trigger an FPE given the same input.
template safeOp(IntFlagPolicy policy)
CallType!(std.math.pow, N, M)
pow
@safe
(
N
M
)
(
const N base
,
const M exp
)
if (
isFixedPoint!N &&
isFixedPoint!M
)

Examples

1 import checkedint.sticky : safeOp; // use IntFlagPolicy.sticky
2 
3 assert(safeOp.pow(-10, 3) == -1_000);
4 static assert(!__traits(compiles, safeOp.pow(16, 4uL)));
5 safeOp.pow(2, -1);
6 assert(IntFlags.local.clear() == IntFlag.undef);
7 
8 safeOp.pow(-3, 27);
9 assert(IntFlags.local.clear() == IntFlag.negOver);
10 safeOp.pow(0, -5);
11 assert(IntFlags.local.clear() == IntFlag.undef);

Meta