Report a bug
If you spot a problem with this page, click here to create a GitHub 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
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!Tz
); - Parameters:
Complex!T z
A complex number. Returns:The square root ofz
.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!Tx
); - 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 ofx
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!Tx
); - Calculates ex.Parameters:
Complex!T x
A complex number Returns:The complex base e exponential ofx
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!Tlhs
, Complex!Trhs
, const TmaxRelDiff
= 9.53674e-07F, const TmaxAbsDiff
= 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 asapproxEqual
(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)));
Copyright © 2016-2023 by Ilya Yaroshenko | Page generated by
Ddoc on Mon Nov 6 15:24:34 2023