Warning: This is the manual of the legacy Guile 2.2 series. You may want to read the manual of the current stable series instead.

Next: , Previous: , Up: R6RS Standard Libraries   [Contents][Index]


7.6.2.21 rnrs arithmetic fixnums

The (rnrs arithmetic fixnums (6)) library provides procedures for performing arithmetic operations on an implementation-dependent range of exact integer values, which R6RS refers to as fixnums. In Guile, the size of a fixnum is determined by the size of the SCM type; a single SCM struct is guaranteed to be able to hold an entire fixnum, making fixnum computations particularly efficient—(see The SCM Type). On 32-bit systems, the most negative and most positive fixnum values are, respectively, -536870912 and 536870911.

Unless otherwise specified, all of the procedures below take fixnums as arguments, and will raise an &assertion condition if passed a non-fixnum argument or an &implementation-restriction condition if their result is not itself a fixnum.

Scheme Procedure: fixnum? obj

Returns #t if obj is a fixnum, #f otherwise.

Scheme Procedure: fixnum-width
Scheme Procedure: least-fixnum
Scheme Procedure: greatest-fixnum

These procedures return, respectively, the maximum number of bits necessary to represent a fixnum value in Guile, the minimum fixnum value, and the maximum fixnum value.

Scheme Procedure: fx=? fx1 fx2 fx3 ...
Scheme Procedure: fx>? fx1 fx2 fx3 ...
Scheme Procedure: fx<? fx1 fx2 fx3 ...
Scheme Procedure: fx>=? fx1 fx2 fx3 ...
Scheme Procedure: fx<=? fx1 fx2 fx3 ...

These procedures return #t if their fixnum arguments are (respectively): equal, monotonically increasing, monotonically decreasing, monotonically nondecreasing, or monotonically nonincreasing; #f otherwise.

Scheme Procedure: fxzero? fx
Scheme Procedure: fxpositive? fx
Scheme Procedure: fxnegative? fx
Scheme Procedure: fxodd? fx
Scheme Procedure: fxeven? fx

These numerical predicates return #t if fx is, respectively, zero, greater than zero, less than zero, odd, or even; #f otherwise.

Scheme Procedure: fxmax fx1 fx2 ...
Scheme Procedure: fxmin fx1 fx2 ...

These procedures return the maximum or minimum of their arguments.

Scheme Procedure: fx+ fx1 fx2
Scheme Procedure: fx* fx1 fx2

These procedures return the sum or product of their arguments.

Scheme Procedure: fx- fx1 fx2
Scheme Procedure: fx- fx

Returns the difference of fx1 and fx2, or the negation of fx, if called with a single argument.

An &assertion condition is raised if the result is not itself a fixnum.

Scheme Procedure: fxdiv-and-mod fx1 fx2
Scheme Procedure: fxdiv fx1 fx2
Scheme Procedure: fxmod fx1 fx2
Scheme Procedure: fxdiv0-and-mod0 fx1 fx2
Scheme Procedure: fxdiv0 fx1 fx2
Scheme Procedure: fxmod0 fx1 fx2

These procedures implement number-theoretic division on fixnums; See (rnrs base), for a description of their semantics.

Scheme Procedure: fx+/carry fx1 fx2 fx3

Returns the two fixnum results of the following computation:

(let* ((s (+ fx1 fx2 fx3))
       (s0 (mod0 s (expt 2 (fixnum-width))))
       (s1 (div0 s (expt 2 (fixnum-width)))))
  (values s0 s1))
Scheme Procedure: fx-/carry fx1 fx2 fx3

Returns the two fixnum results of the following computation:

(let* ((d (- fx1 fx2 fx3))
       (d0 (mod0 d (expt 2 (fixnum-width))))
       (d1 (div0 d (expt 2 (fixnum-width)))))
  (values d0 d1))
Scheme Procedure: fx*/carry fx1 fx2 fx3
Returns the two fixnum results of the following computation:
(let* ((s (+ (* fx1 fx2) fx3))
       (s0 (mod0 s (expt 2 (fixnum-width))))
       (s1 (div0 s (expt 2 (fixnum-width)))))
  (values s0 s1))
Scheme Procedure: fxnot fx
Scheme Procedure: fxand fx1 ...
Scheme Procedure: fxior fx1 ...
Scheme Procedure: fxxor fx1 ...

These procedures are identical to the lognot, logand, logior, and logxor procedures provided by Guile’s core library. See Bitwise Operations, for documentation.

Scheme Procedure: fxif fx1 fx2 fx3

Returns the bitwise “if” of its fixnum arguments. The bit at position i in the return value will be the ith bit from fx2 if the ith bit of fx1 is 1, the ith bit from fx3.

Scheme Procedure: fxbit-count fx

Returns the number of 1 bits in the two’s complement representation of fx.

Scheme Procedure: fxlength fx

Returns the number of bits necessary to represent fx.

Scheme Procedure: fxfirst-bit-set fx

Returns the index of the least significant 1 bit in the two’s complement representation of fx.

Scheme Procedure: fxbit-set? fx1 fx2

Returns #t if the fx2th bit in the two’s complement representation of fx1 is 1, #f otherwise.

Scheme Procedure: fxcopy-bit fx1 fx2 fx3

Returns the result of setting the fx2th bit of fx1 to the fx2th bit of fx3.

Scheme Procedure: fxbit-field fx1 fx2 fx3

Returns the integer representation of the contiguous sequence of bits in fx1 that starts at position fx2 (inclusive) and ends at position fx3 (exclusive).

Scheme Procedure: fxcopy-bit-field fx1 fx2 fx3 fx4

Returns the result of replacing the bit field in fx1 with start and end positions fx2 and fx3 with the corresponding bit field from fx4.

Scheme Procedure: fxarithmetic-shift fx1 fx2
Scheme Procedure: fxarithmetic-shift-left fx1 fx2
Scheme Procedure: fxarithmetic-shift-right fx1 fx2

Returns the result of shifting the bits of fx1 right or left by the fx2 positions. fxarithmetic-shift is identical to fxarithmetic-shift-left.

Scheme Procedure: fxrotate-bit-field fx1 fx2 fx3 fx4

Returns the result of cyclically permuting the bit field in fx1 with start and end positions fx2 and fx3 by fx4 bits in the direction of more significant bits.

Scheme Procedure: fxreverse-bit-field fx1 fx2 fx3

Returns the result of reversing the order of the bits of fx1 between position fx2 (inclusive) and position fx3 (exclusive).


Next: , Previous: , Up: R6RS Standard Libraries   [Contents][Index]