Scheme's numerical “tower” consists of the following categories of numbers:
It is called a tower because each category “sits on” the one that follows it, in the sense that every integer is also a rational, every rational is also real, and every real number is also a complex number (but with zero imaginary part).
In addition to the classification into integers, rationals, reals and
complex numbers, Scheme also distinguishes between whether a number is
represented exactly or not. For example, the result of
sin(pi/4) is exactly 2^(1/2) but Guile
can neither represent pi/4 nor 2^(1/2) exactly.
Instead, it stores an inexact approximation, using the C type
double
.
Guile can represent exact rationals of any magnitude, inexact
rationals that fit into a C double
, and inexact complex numbers
with double
real and imaginary parts.
The number?
predicate may be applied to any Scheme value to
discover whether the value is any of the supported numerical types.
Return
#t
if obj is any kind of number, else#f
.
For example:
(number? 3) => #t (number? "hello there!") => #f (define pi 3.141592654) (number? pi) => #t
The next few subsections document each of Guile's numerical data types in detail.