Next: Reals and Rationals, Previous: Numerical Tower, Up: Numbers
Integers are whole numbers, that is numbers with no fractional part, such as 2, 83 and -3789.
Integers in Guile can be arbitrarily big, as shown by the following example.
(define (factorial n)
(let loop ((n n) (product 1))
(if (zero? n)
product
(loop (- n 1) (* product n)))))
(factorial 3)
⇒ 6
(factorial 20)
⇒ 2432902008176640000
(- (factorial 45))
⇒ -119622220865480194561963161495657715064383733760000000000
Readers whose background is in programming languages where integers are limited by the need to fit into just 4 or 8 bytes of memory may find this surprising, or suspect that Guile's representation of integers is inefficient. In fact, Guile achieves a near optimal balance of convenience and efficiency by using the host computer's native representation of integers where possible, and a more general representation where the required number does not fit in the native form. Conversion between these two representations is automatic and completely invisible to the Scheme level programmer.
The infinities +inf.0 and -inf.0 are considered to be
inexact integers. They are explained in detail in the next section,
together with reals and rationals.
Return
#tif x is an integer number,#fotherwise.
(integer? 487)
⇒ #t
(integer? -3.4)
⇒ #f
(integer? +inf.0)
⇒ #t