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
2*sin(pi/4) is exactly 2^(1/2), but Guile
can represent neither pi/4 nor 2^(1/2) exactly.
Instead, it stores an inexact approximation, using the C type
Guile can represent exact rationals of any magnitude, inexact
rationals that fit into a C
double, and inexact complex numbers
double real and imaginary parts.
number? predicate may be applied to any Scheme value to
discover whether the value is any of the supported numerical types.
#tif obj is any kind of number, else
(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.