Report a bug
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 a local clone.

# mir.complex.math

Complex math
Authors:
Ilia Ki, Lars Tandle Kyllingstad, Don Clugston
pure nothrow @nogc @safe Complex!T sqrt(T)(Complex!T z);
Parameters:
 Complex!T z A complex number.
Returns:
The square root of z.
Examples:
assert(sqrt(complex(0.0)) == 0.0);
assert(sqrt(complex(1.0, 0)) == 1.0);
assert(sqrt(complex(-1.0, 0)) == complex(0, 1.0));
assert(sqrt(complex(-8.0, -6.0)) == complex(1.0, -3.0));
pure nothrow @nogc @safe Complex!T log(T)(Complex!T x);
Calculate the natural logarithm of x. The branch cut is along the negative axis.
Parameters:
 Complex!T x A complex number
Returns:
The complex natural logarithm of x
Examples:
import mir.math.common: sqrt;
import mir.math.constant: PI;
import mir.math.common: approxEqual;

auto a = complex(2.0, 1.0);
assert(log(conj(a)) == conj(log(a)));

assert(log(complex(-1.0L, 0.0L)) == complex(0.0L, PI));
assert(log(complex(-1.0L, -0.0L)) == complex(0.0L, -PI));
pure nothrow @nogc @trusted Complex!T exp(T)(Complex!T x);
Calculates ex.
Parameters:
 Complex!T x A complex number
Returns:
The complex base e exponential of x
Examples:
import mir.math.constant: PI;

assert(exp(complex(0.0, 0.0)) == complex(1.0, 0.0));

auto a = complex(2.0, 1.0);
assert(exp(conj(a)) == conj(exp(a)));

auto b = exp(complex(0.0, 1.0) * double(PI));
assert(approxEqual(b, complex(-1.0), 0.0, 1e-15));
bool approxEqual(T)(Complex!T lhs, Complex!T rhs, const T maxRelDiff = 9.53674e-07F, const T maxAbsDiff = 9.53674e-07F);
Computes whether two values are approximately equal, admitting a maximum relative difference, and a maximum absolute difference.
Parameters:
 Complex!T lhs First item to compare. Complex!T rhs Second item to compare. T maxRelDiff Maximum allowable difference relative to rhs. Defaults to 0.5 ^^ 20. T maxAbsDiff Maximum absolute difference. Defaults to 0.5 ^^ 20.
Returns:
true if the two items are equal or approximately equal under either criterium.
Examples:
Complex types works as approxEqual(l.re, r.re) && approxEqual(l.im, r.im)
assert(approxEqual(complex(1.0, 1), complex(1.0000001, 1), 1.0000001));
assert(!approxEqual(complex(100000.0, 0), complex(100001.0, 0)));