The OpenD Programming Language

pow

Compute the power of two integral numbers.

  1. Unqual!F pow(F x, G n)
  2. typeof(Unqual!(F).init * Unqual!(G).init) pow(F x, G n)
    @nogc @trusted pure nothrow
    typeof(Unqual!(F).init * Unqual!(G).init)
    pow
    (
    F
    G
    )
    (
    F x
    ,
    G n
    )
    if ()
  3. real pow(I x, F y)
  4. Unqual!(Largest!(F, G)) pow(F x, G y)

Parameters

x F

base

n G

exponent

Return Value

Type: typeof(Unqual!(F).init * Unqual!(G).init)

x raised to the power of n. If n is negative the result is 1 / pow(x, -n), which is calculated as integer division with remainder. This may result in a division by zero error.

If both x and n are 0, the result is 1.

Throws

If x is 0 and n is negative, the result is the same as the result of a division by zero.

Examples

assert(pow(2, 3) == 8);
assert(pow(3, 2) == 9);

assert(pow(2, 10) == 1_024);
assert(pow(2, 20) == 1_048_576);
assert(pow(2, 30) == 1_073_741_824);

assert(pow(0, 0) == 1);

assert(pow(1, -5) == 1);
assert(pow(1, -6) == 1);
assert(pow(-1, -5) == -1);
assert(pow(-1, -6) == 1);

assert(pow(-2, 5) == -32);
assert(pow(-2, -5) == 0);
assert(pow(cast(double) -2, -5) == -0.03125);

Meta