std.complex

This module contains the Complex type, which is used to represent complex numbers, along with related mathematical operations and functions.

Complex will eventually

deprecate, Deprecated Features, replace the built-in types cfloat, cdouble, creal, ifloat, idouble, and ireal.

Types 1

structComplex(T) if (isFloatingPoint!T)

A complex number parametrised by a type T, which must be either float, double or real.

Fields
T reThe real part of the number.
T imThe imaginary part of the number.
Methods
string toString() const @safeConverts the complex number to a string representation.
void toString(Writer, Char)(scope Writer w, scope const ref FormatSpec!Char formatSpec) if (isOutputRange!(Writer, const(Char)[])) constditto
Complex opAssign(R : T)(Complex!R z) ref
Complex opAssign(R : T)(const R r) ref
bool opEquals(R : T)(Complex!R z) const
bool opEquals(R : T)(const R r) const
Complex opUnary(string op)() if (op == "+") const
Complex opUnary(string op)() if (op == "-") const
Complex!(CommonType!(T, R)) opBinary(string op, R)(Complex!R z) const
Complex!(CommonType!(T, R)) opBinary(string op, R)(const R r) if (isNumeric!R) const
Complex!(CommonType!(T, R)) opBinaryRight(string op, R)(const R r) if ((op == "+" || op == "*") && (isNumeric!R)) const
Complex!(CommonType!(T, R)) opBinaryRight(string op, R)(const R r) if (op == "-" && isNumeric!R) const
Complex!(CommonType!(T, R)) opBinaryRight(string op, R)(const R r) if (op == "/" && isNumeric!R) const
Complex!(CommonType!(T, R)) opBinaryRight(string op, R)(const R lhs) if (op == "^^" && isNumeric!R) const
Complex opOpAssign(string op, C)(const C z) if ((op == "+" || op == "-") && is(C R == Complex!R)) ref
Complex opOpAssign(string op, C)(const C z) if (op == "*" && is(C R == Complex!R)) ref
Complex opOpAssign(string op, C)(const C z) if (op == "/" && is(C R == Complex!R)) ref
Complex opOpAssign(string op, C)(const C z) if (op == "^^" && is(C R == Complex!R)) ref
Complex opOpAssign(string op, U : T)(const U a) if (op == "+" || op == "-") ref
Complex opOpAssign(string op, U : T)(const U a) if (op == "*" || op == "/") ref
Complex opOpAssign(string op, R)(const R r) if (op == "^^" && isFloatingPoint!R) ref
Complex opOpAssign(string op, U)(const U i) if (op == "^^" && isIntegral!U) ref
auto toNative()Returns a complex number instance that correponds in size and in ABI to the associated C compiler's `Complex` type.
Constructors
this(Complex!R z)Construct a complex number with the specified real and imaginary parts. In the case where a single argument is passed that is not complex, the imaginary part of the result will be zero.
this(const Rx x, const Ry y)ditto
this(const R r)ditto

Functions 32

fnauto complex(R)(const R re) if (is(R : double)) @safe pure nothrow @nogcHelper function that returns a complex number with the specified real and imaginary parts.
fnauto complex(R, I)(const R re, const I im) if (is(R : double) && is(I : double)) @safe pure nothrow @nogcditto
fnT abs(T)(Complex!T z) @safe pure nothrow @nogcCalculates the absolute value (or modulus) of a complex number.
fnT sqAbs(T)(Complex!T z) @safe pure nothrow @nogcParams: z = A complex number. x = A real number. Returns: The squared modulus of `z`. For genericity, if called on a real number, returns its square.
fnT sqAbs(T)(const T x) if (isFloatingPoint!T) @safe pure nothrow @nogcditto
fnT arg(T)(Complex!T z) @safe pure nothrow @nogcParams: z = A complex number. Returns: The argument (or phase) of `z`.
fnT norm(T)(Complex!T z) @safe pure nothrow @nogcExtracts the norm of a complex number. Params: z = A complex number Returns: The squared magnitude of `z`.
fnComplex!T conj(T)(Complex!T z) @safe pure nothrow @nogcParams: z = A complex number. Returns: The complex conjugate of `z`.
fnComplex!T proj(T)(Complex!T z)Returns the projection of `z` onto the Riemann sphere. Params: z = A complex number Returns: The projection of `z` onto the Riemann sphere.
fnComplex!(CommonType!(T, U)) fromPolar(T, U)(const T modulus, const U argument) @safe pure nothrow @nogcConstructs a complex number given its absolute value and argument. Params: modulus = The modulus argument = The argument Returns: The complex number with the given modulus and argument.
fnComplex!T sin(T)(Complex!T z) @safe pure nothrow @nogcTrigonometric functions on complex numbers.
fnComplex!T cos(T)(Complex!T z) @safe pure nothrow @nogcditto
fnComplex!T tan(T)(Complex!T z) @safe pure nothrow @nogcditto
fnComplex!T asin(T)(Complex!T z) @safe pure nothrow @nogcInverse trigonometric functions on complex numbers.
fnComplex!T acos(T)(Complex!T z) @safe pure nothrow @nogcditto
fnComplex!T atan(T)(Complex!T z) @safe pure nothrow @nogcditto
fnComplex!T sinh(T)(Complex!T z) @safe pure nothrow @nogcHyperbolic trigonometric functions on complex numbers.
fnComplex!T cosh(T)(Complex!T z) @safe pure nothrow @nogcditto
fnComplex!T tanh(T)(Complex!T z) @safe pure nothrow @nogcditto
fnComplex!T asinh(T)(Complex!T z) @safe pure nothrow @nogcInverse hyperbolic trigonometric functions on complex numbers.
fnComplex!T acosh(T)(Complex!T z) @safe pure nothrow @nogcditto
fnComplex!T atanh(T)(Complex!T z) @safe pure nothrow @nogcditto
fnComplex!real expi(real y) @trusted pure nothrow @nogcParams: y = A real number. Returns: The value of cos(y) + i sin(y).
fnComplex!real coshisinh(real y) @safe pure nothrow @nogcParams: y = A real number. Returns: The value of cosh(y) + i sinh(y)
fnComplex!T sqrt(T)(Complex!T z) @safe pure nothrow @nogcParams: z = A complex number. Returns: The square root of `z`.
fnComplex!T exp(T)(Complex!T x) @trusted pure nothrow @nogcCalculates ex. Params: x = A complex number Returns: The complex base e exponential of `x`
fnComplex!T log(T)(Complex!T x) @safe pure nothrow @nogcCalculate the natural logarithm of x. The branch cut is along the negative axis. Params: x = A complex number Returns: The complex natural logarithm of `x`
fnComplex!T log10(T)(Complex!T x) @safe pure nothrow @nogcCalculate the base-10 logarithm of x. Params: x = A complex number Returns: The complex base 10 logarithm of `x`
fnComplex!T pow(T, Int)(Complex!T x, const Int n) if (isIntegral!Int) @safe pure nothrow @nogcCalculates xn. The branch cut is on the negative axis. Params: x = base n = exponent Returns: `x` raised to the power of `n`
fnComplex!T pow(T)(Complex!T x, const T n) @trusted pure nothrow @nogcditto
fnComplex!T pow(T)(Complex!T x, Complex!T y) @trusted pure nothrow @nogcditto
fnComplex!T pow(T)(const T x, Complex!T n) @trusted pure nothrow @nogcditto

Templates 1

tmplComplex(T) if (is(T R == Complex!R))