make-rectangular, make-polar - construct complex numbers
(import (rnrs)) ;R6RS
(import (rnrs base)) ;R6RS
(import (scheme r5rs)) ;R7RS
(import (scheme complex)) ;R7RS
(make-rectangular x y)
(make-polar m a)
the complex number with real part
and imaginary part
the complex number with approximate magnitude
and approximate angle
- GNU Guile 3.0
Guile does not have a way to represent exact complex numbers with
non-zero imaginary parts. This means that 1+2i is automatically turned
into 1.0+2.0i. This is a deviation from R6RS but is allowed by R7RS.
- Loko Scheme
Loko Scheme can internally represent complex numbers in polar
notation, keeping the polar notation when convenient. This is mostly
done as a joke and isn't something normally found in Scheme. Most
implementations convert the polar notation to an inexact rectangular
The real numbers, the rational numbers and the integers are a subset
of the complex numbers. Many implementations will simplify the return
type when one of
is exact zero.
Both procedures return a single value; a complex number. If either
argument is inexact then the returned number is inexact. The
procedure may return inexact results even when the arguments are
(make-rectangular 1 2)
(make-rectangular 1.1 2.2)
=> 1.1+2.2i ; approximately
(make-polar 1.1 2.2)
=> email@example.com ; approximately
These procedures, where they are implemented, are intended to achieve
the same result: return the mathematically correct result to the
extent allowed by the implementation. Some variations between
implementations are noted above.
Support for these procedures is required by R6RS. There are however
still variations in which types of numbers that can be represented.
Some of the possible variations are: IEEE 754 floats are not required,
-0.0 does not need to be distinct, the precision of inexact numbers
can vary, numbers in polar notation can be turned into inexact
numbers in rectangular notation.
Support for complex numbers is not guaranteed at all in R7RS.
An R7RS implementation's support can be tested with
Exact complex numbers are provided. (Note that this refers to
the rectangular representation only).
Inexact numbers are IEEE 754 binary floating point values.
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.
In particular, all arguments must be real numbers.
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.
- R7RS and unsupported numbers
If an implementation encounters an exact numerical constant that it
cannot represent as an exact number, then it may either report a
violation of an implementation restriction or it may silently
represent the constant by an inexact number.
These procedures first appeared in R2RS, which got them from Common Lisp.
This page is part of the
It includes materials from the RnRS documents.
More information can be found at
Markup created by unroff 1.0sc, March 04, 2023.