The OpenD Programming Language

pow

Calculates xn. The branch cut is on the negative axis.

  1. Complex!T pow(Complex!T x, Int n)
  2. Complex!T pow(Complex!T x, T n)
  3. Complex!T pow(Complex!T x, Complex!T y)
  4. Complex!T pow(T x, Complex!T n)
    @trusted pure nothrow @nogc
    pow
    (
    T
    )
    (
    const T x
    ,)

Parameters

x T

base

n Complex!T

exponent

Return Value

Type: Complex!T

x raised to the power of n

Examples

import std.math.operations : isClose;
assert(pow(2.0, complex(0.0)) == complex(1.0));
assert(pow(2.0, complex(5.0)) == complex(32.0));

auto a = pow(-2.0, complex(-1.0));
assert(isClose(a, complex(-0.5), 0.0, 1e-16));

auto b = pow(-0.5, complex(-1.0));
assert(isClose(b, complex(-2.0), 0.0, 1e-15));
import std.math.operations : isClose;

auto a = complex(1.0, 2.0);
assert(pow(a, 2) == a * a);
assert(pow(a, 3) == a * a * a);
assert(pow(a, -2) == 1.0 / (a * a));
assert(isClose(pow(a, -3), 1.0 / (a * a * a)));
import std.math.operations : isClose;
assert(pow(complex(0.0), 2.0) == complex(0.0));
assert(pow(complex(5.0), 2.0) == complex(25.0));

auto a = pow(complex(-1.0, 0.0), 0.5);
assert(isClose(a, complex(0.0, +1.0), 0.0, 1e-16));

auto b = pow(complex(-1.0, -0.0), 0.5);
assert(isClose(b, complex(0.0, -1.0), 0.0, 1e-16));
import std.math.operations : isClose;
import std.math.exponential : exp;
import std.math.constants : PI;
auto a = complex(0.0);
auto b = complex(2.0);
assert(pow(a, b) == complex(0.0));

auto c = complex(0.0L, 1.0L);
assert(isClose(pow(c, c), exp((-PI) / 2)));

Meta