This is an old version, view current version.

4.6 Complex special functions

The following functions are specific to complex numbers other than absolute value, which has a specific meaning for complex numbers.

real abs(complex z)
Return the absolute value of z, also known as the modulus or magnitude, which for z=x+yi is abs(z)=x2+y2.

This function works elementwise over containers, returning the same shape and kind of the input container but holding reals. For example, a complex_vector[n] input will return a vector[n] output, with each element transformed by the above equation.
Available since 2.28, vectorized in 2.30

real arg(complex z)
Return the phase angle (in radians) of z, which for z=x+yi is arg(z)=atan2(y,x)=atan(y/x).
Available since 2.28

real norm(complex z)
Return the Euclidean norm of z, which is its absolute value squared, and which for z=x+yi is norm(z)=abs2(z)=x2+y2.
Available since 2.28

complex conj(complex z)
Return the complex conjugate of z, which negates the imaginary component, so that if z=x+yi, conj(z)=xyi.
Available since 2.28

complex proj(complex z)
Return the projection of z onto the Riemann sphere, which for z=x+yi is proj(z)={zif z is finite, and0+sign(y)iotherwise, where sign(y) is -1 if y is negative and 1 otherwise.
Available since 2.28

complex polar(real r, real theta)
Return the complex number with magnitude (absolute value) r and phase angle theta.
Available since 2.28