Previous: , Up: baselib math ops   [Index]


4.6.4.9 Complex numbers functions

Procedure: make-rectangular x1 x2
Procedure: make-polar x3 x4
Procedure: real-part z
Procedure: imag-part z
Procedure: magnitude z
Procedure: angle z

Suppose a_1, a_2, a_3, and a_4 are real numbers, and c is a complex number such that the following holds:

c = a_1 + a_2 i = a_3 e^(i a_4)

Then, if x1, x2, x3, and x4 are number objects representing a_1, a_2, a_3, and a_4, respectively, (make-rectangular x1 x2) returns c, and (make-polar x3 x4) returns c.

(make-rectangular 1.1 2.2)    ⇒ 1.1+2.2i ; approximately
(make-polar 1.1 2.2)          ⇒ 1.1@2.2 ; approximately

Conversely, if -\pi <= a_4 <= \pi, and if z is a number object representing c, then (real-part z) returns a_1, (imag-part z) returns a_2, (magnitude z) returns a_3, and (angle z) returns a_4.

(real-part 1.1+2.2i)    ⇒ 1.1
                        ; approximately
(imag-part 1.1+2.2i)    ⇒ 2.2
                        ; approximately
(magnitude 1.1@2.2)     ⇒ 1.1
                        ; approximately
(angle     1.1@2.2)     ⇒ 2.2
                        ; approximately

(angle -1.0)            ⇒ 3.141592653589793
                        ; approximately
(angle -1.0+0.0i)       ⇒ 3.141592653589793
                        ; approximately
(angle -1.0-0.0i)       ⇒ -3.141592653589793
                        ; approximately if -0.0 is distinguished
(angle +inf.0)          ⇒ 0.0
(angle -inf.0)          ⇒ 3.141592653589793
                        ; approximately

Moreover, suppose x1, x2 are such that either x1 or x2 is an infinity, then

(make-rectangular x1 x2)        ⇒ z
(magnitude z)                   ⇒ +inf.0

The make-polar, magnitude, and angle procedures may return inexact results even when given exact arguments.

(angle -1)              ⇒ 3.141592653589793
                        ; approximately