Skip to main content

phase

phase Function

Syntax:

phase number → phase

Arguments and Values:

number—a number .

phase—a number .

Description:

phase returns the phase of number (the angle part of its polar representation) in radians, in the range −π (exclusive) if minus zero is not supported, or −π (inclusive) if minus zero is supported, to π (inclusive). The phase of a positive real number is zero; that of a negative real number is π. The phase of zero is defined to be zero.

If number is a complex float, the result is a float of the same type as the components of number. If number is a float, the result is a float of the same type. If number is a rational or a complex rational, the result is a single float.

The branch cut for phase lies along the negative real axis, continuous with quadrant II. The range consists of that portion of the real axis between −π (exclusive) and π (inclusive).

The mathematical definition of phase is as follows:

(phase x) = (atan (imagpart x) (realpart x))

Examples:

(phase 1) → 0.0s0 

(phase 0) → 0.0s0
(phase (cis 30))-1.4159266
(phase #c(0 1))1.5707964

Exceptional Situations:

Should signal type-error if its argument is not a number . Might signal arithmetic-error.

See Also:

Section 12.1.3.3 (Rule of Float Substitutability)

Expanded Reference: phase

Phase of real numbers

The phase (angle) of a positive real number is zero. The phase of a negative real number is pi.

(phase 1)
=> 0.0
(phase 5.0)
=> 0.0
(phase 0)
=> 0.0
(phase -1.0)
=> 3.1415927
(phase -5)
=> 3.1415927

Phase of complex numbers

phase returns the angle in radians of the complex number in polar form, ranging from -pi (exclusive) to pi (inclusive).

(phase #c(0 1))
=> 1.5707964
(phase #c(0 -1))
=> -1.5707964
(phase #c(1 1))
=> 0.7853982
(phase #c(-1 0))
=> 3.1415927

Relationship to atan

phase is mathematically equivalent to (atan (imagpart x) (realpart x)).

(let ((z #c(3.0 4.0)))
(list (phase z)
(atan (imagpart z) (realpart z))))
=> (0.9272952 0.9272952)

Reconstructing a complex number from abs and phase

A complex number can be reconstructed from its magnitude and phase using cis.

(let ((z #c(3.0 4.0)))
(* (abs z) (cis (phase z))))
=> #C(3.0 4.0)

Phase with cis

The phase of a complex number created by cis returns the original angle (within the principal range).

(phase (cis 1.0))
=> 1.0
(phase (cis -1.0))
=> -1.0
(phase (cis 30))
=> -1.4159266