View source code
Display the source code in std/complex.d from which this page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using local clone.

Function std.complex.pow

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

Complex!T pow(T, Int) (
  Complex!T x,
  const Int n
) pure nothrow @nogc @safe
if (isIntegral!Int);

Complex!T pow(T) (
  Complex!T x,
  const T n
) pure nothrow @nogc @trusted;

Complex!T pow(T) (
  Complex!T x,
  Complex!T y
) pure nothrow @nogc @trusted;

Complex!T pow(T) (
  const T x,
  Complex!T n
) pure nothrow @nogc @trusted;

Parameters

NameDescription
x base
n exponent

Returns

x raised to the power of n

Example

import std.math : isClose;

auto a = complex(1.0, 2.0);
writeln(pow(a, 2)); // a * a
writeln(pow(a, 3)); // a * a * a
writeln(pow(a, -2)); // 1.0 / (a * a)
assert(isClose(pow(a, -3), 1.0 / (a * a * a)));

auto b = complex(2.0);
assert(isClose(pow(b, 3), exp(3 * log(b))));

Example

import std.math : isClose;
writeln(pow(complex(0.0), 2.0)); // complex(0.0)
writeln(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));

Example

import std.math : isClose, exp, PI;
auto a = complex(0.0);
auto b = complex(2.0);
writeln(pow(a, b)); // complex(0.0)

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

Example

import std.math : isClose;
writeln(pow(2.0, complex(0.0))); // complex(1.0)
writeln(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));

Authors

Lars Tandle Kyllingstad, Don Clugston

License

Boost License 1.0