Node:Integers, 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
(define (factorial n) (let loop ((n n) (product 1)) (if (= n 0) 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.
|integer? x||Scheme Procedure|
|scm_integer_p (x)||C Function|
(integer? 487) => #t (integer? -3.4) => #f