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
Complex numbers
Authors:
Ilia Ki, Lars Tandle Kyllingstad, Don Clugston
- struct
Complex(T) if (is(T == float) || is(T == double) || is(T == real));
Complex!Tcomplex(T)(const Tre, const Tim= 0)
if (is(T == float) || is(T == double) || is(T == real)); - Generic complex number type
- T
re; - Real part. Default value is zero.
- T
im; - Imaginary part. Default value is zero.
- ref Complex
opAssign(R)(Complex!Rrhs)
if (!is(R == T)); - ref Complex
opAssign(F)(const Frhs)
if (isNumeric!F); - ref Complex
opOpAssign(string op : "+", R)(Complex!Rrhs) return; - ref Complex
opOpAssign(string op : "-", R)(Complex!Rrhs) return; - ref Complex
opOpAssign(string op, R)(Complex!Rrhs) return
if (op == "*" || op == "/"); - ref Complex
opOpAssign(string op : "+", R)(const Rrhs) return
if (isNumeric!R); - ref Complex
opOpAssign(string op : "-", R)(const Rrhs) return
if (isNumeric!R); - ref Complex
opOpAssign(string op : "*", R)(const Rrhs) return
if (isNumeric!R); - ref Complex
opOpAssign(string op : "/", R)(const Rrhs) return
if (isNumeric!R); - bool
opEquals(const Complexrhs); - size_t
toHash(); - bool
opEquals(R)(Complex!Rrhs)
if (!is(R == T)); - bool
opEquals(F)(const Frhs)
if (isNumeric!F); - Complex
opUnary(string op : "+")(); - Complex
opUnary(string op : "-")(); - Complex!(CommonType!(T, R))
opBinary(string op : "+", R)(Complex!Rrhs); - Complex!(CommonType!(T, R))
opBinary(string op : "-", R)(Complex!Rrhs); - Complex!(CommonType!(T, R))
opBinary(string op : "*", R)(Complex!Rrhs); - Complex!(CommonType!(T, R))
opBinary(string op : "/", R)(Complex!Rrhs); - Complex!(CommonType!(T, R))
opBinary(string op : "+", R)(const Rrhs)
if (isNumeric!R); - Complex!(CommonType!(T, R))
opBinary(string op : "-", R)(const Rrhs)
if (isNumeric!R); - Complex!(CommonType!(T, R))
opBinary(string op : "*", R)(const Rrhs)
if (isNumeric!R); - Complex!(CommonType!(T, R))
opBinary(string op : "/", R)(const Rrhs)
if (isNumeric!R); - Complex!(CommonType!(T, R))
opBinaryRight(string op : "+", R)(const Rrhs)
if (isNumeric!R); - Complex!(CommonType!(T, R))
opBinaryRight(string op : "-", R)(const Rrhs)
if (isNumeric!R); - Complex!(CommonType!(T, R))
opBinaryRight(string op : "*", R)(const Rrhs)
if (isNumeric!R); - Complex!(CommonType!(T, R))
opBinaryRight(string op : "/", R)(const Rrhs)
if (isNumeric!R); - R
opCast(R)()
if (isNumeric!R || isComplex!R);
- pure nothrow @nogc @safe Complex!T
fromPolar(T)(const Tmodulus, const Targument)
if (__traits(isFloating, T)); - Constructs a complex number given its absolute value and argument.Parameters:
T modulusThe modulus T argumentThe argument Returns:The complex number with the given modulus and argument.Examples:import mir.math : approxEqual, PI, sqrt; auto z = fromPolar(sqrt(2.0), double(PI / 4)); assert(approxEqual(z.re, 1.0)); assert(approxEqual(z.im, 1.0));
- pure nothrow @nogc @safe Complex!T
conj(T)(Complex!Tz); - Parameters:
Complex!T zA complex number. Returns:The complex conjugate ofz.Examples:assert(conj(complex(1.0)) == complex(1.0)); assert(conj(complex(1.0, 2.0)) == complex(1.0, -2.0));
- pure nothrow @nogc @safe T
arg(T)(Complex!Tz); - Parameters:
Complex!T zA complex number. Returns:The argument (or phase) ofz.Examples:import mir.math.constant: PI_2, PI_4; assert(arg(complex(1.0)) == 0.0); assert(arg(complex(0.0L, 1.0L)) == PI_2); assert(arg(complex(1.0L, 1.0L)) == PI_4);
- pure nothrow @nogc @safe T
cabs(T)(Complex!Tz); - Parameters:
Complex!T zA complex number. Returns:The absolute value (or modulus) ofz.Examples:import mir.math.common: sqrt; assert(cabs(complex(1.0)) == 1.0); assert(cabs(complex(0.0, 1.0)) == 1.0); assert(cabs(complex(1.0L, -2.0L)) == sqrt(5.0L));
Copyright © 2016-2023 by Ilya Yaroshenko | Page generated by
Ddoc on Mon Nov 6 15:24:34 2023