| magnitude(3scm) | Scheme Programmer's Manual | magnitude(3scm) |
NAME
magnitude, angle - magnitude and angle of complex numbers
LIBRARY
(import (rnrs)) ;R6RS (import (rnrs base)) ;R6RS (import (scheme r5rs)) ;R7RS (import (scheme complex)) ;R7RS
SYNOPSIS
(magnitude z) (angle z)
DESCRIPTION
Return the magnitude and angle of z, respectively.
IMPLEMENTATION NOTES
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)).
RETURN VALUES
These procedures return a single value; a real number.
EXAMPLES
(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
COMPATIBILITY
These procedures work the same everywhere that they are supported. R7RS implementations may not have support for complex numbers.
ERRORS
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.
SEE ALSO
abs(3scm), make-rectangular(3scm)
STANDARDS
R4RS, IEEE Scheme, R5RS, R6RS, R7RS
HISTORY
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.
AUTHORS
This page is part of the scheme-manpages project. It includes materials from the RnRS documents. More information can be found at https://weinholt.se/scheme/manpages/.
| 2023-03-14 |