magnitude, angle - magnitude and angle of complex numbers
(import (rnrs)) ;R6RS
(import (rnrs base)) ;R6RS
(import (scheme r5rs)) ;R7RS
(import (scheme complex)) ;R7RS
Return the magnitude and angle of z, respectively.
Most implementations of complex numbers do not store them in polar form but
instead use rectangular form. The magnitude can be found using the equation
for Euclidean distance: (sqrt (+ (expt (real-part z) 2) (expt
(imag-part z) 2))). The angle can be found using atan:
(atan (imag-part z) (real-part z)).
These procedures return a single value; a real number.
(angle -1) => 3.141592653589793 ; approximately
(magnitude 1+i) => 1.4142135623730951 ; 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
(angle 0) => &assertion raised
(magnitude 0) => 0
These procedures work the same everywhere that they are supported. R7RS
implementations may not have support for complex numbers.
This procedure can raise exceptions with the following condition types:
- &assertion (R6RS)
- The wrong number of arguments was passed or an argument was outside its
domain.
- R7RS
- The assertions described above are errors. Implementations may signal an
error, extend the procedure's domain of definition to include such
arguments, or fail catastrophically.
R4RS, IEEE Scheme, R5RS, R6RS, R7RS
These procedures first appeared in R2RS, which used Common Lisp as inspiration
for its number system. In Common Lisp these procedures are called abs
and phase.