## 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 $\begin{equation*} \textrm{abs}(z) = \sqrt{x^2 + y^2}. \end{equation*}$

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 $\begin{equation*} \textrm{arg}(z) = \textrm{atan2}(y, x) = \textrm{atan}(y / x). \end{equation*}$
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 $\begin{equation*} \textrm{norm}(z) = \textrm{abs}^2(z) = x^2 + y^2. \end{equation*}$
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$$, $\begin{equation*} \textrm{conj}(z) = x - yi. \end{equation*}$
Available since 2.28

Z conj(Z z)
Vectorized version of conj. This will apply the conj function to each element of a complex array, vector, or matrix.
Available since 2.31

complex proj(complex z)
Return the projection of z onto the Riemann sphere, which for $$z = x + yi$$ is $\begin{equation*} \textrm{proj}(z) = \begin{cases} z & \textrm{if} \ z \ \textrm{is finite, and} \\ 0 + \textrm{sign}(y)i & \textrm{otherwise,} \end{cases} \end{equation*}$ where $$\textrm{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