Scheme’s numerical “tower” consists of the following categories of numbers:
Whole numbers, positive or negative; e.g. –5, 0, 18.
The set of numbers that can be expressed as p/q where p and q are integers; e.g. 9/16 works, but pi (an irrational number) doesn’t. These include integers (n/1).
The set of numbers that describes all possible positions along a one-dimensional line. This includes rationals as well as irrational numbers.
The set of numbers that describes all possible positions in a two dimensional space. This includes real as well as imaginary numbers (a+bi, where a is the real part, b is the imaginary part, and i is the square root of -1.)
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.
#t if obj is any kind of number, else
(number? 3) ⇒ #t (number? "hello there!") ⇒ #f (define pi 3.141592654) (number? pi) ⇒ #t
This is equivalent to
scm_is_true (scm_number_p (obj)).
The next few subsections document each of Guile’s numerical data types in detail.