abs

Calculates the absolute value (or modulus) of a complex number.

normal case

Special Values
zabs(z)Notes
(0, 0)0
(NaN, any) or (any, NaN)NaN
(Inf, any) or (any, Inf)Inf
(a, b)hypot(a, b)Uses algorithm to prevent overflow/underflow
@safe pure nothrow @nogc
T
abs
(
T
)

Parameters

z Complex!T

A complex number of type Complex!T

Return Value

Type: T

The absolute value (modulus) of z

Examples

static import core.math;
assert(abs(complex(1.0)) == 1.0);
assert(abs(complex(0.0, 1.0)) == 1.0);
assert(abs(complex(1.0L, -2.0L)) == core.math.sqrt(5.0L));

Meta