r6rs-lib
[Go to
first
previous
next
page
contents
index
Chapter 11
Arithmetic
This chapter describes Scheme's libraries for more specialized
numerical operations: fixnum and flonum arithmetic, as well as bitwise
operations on exact integer objects.
11.1  Bitwise operations
A number of procedures operate on the binary two's-complement
representations of exact integer objects: Bit positions within an
exact integer object are counted from the right, i.e. bit 0 is the
least significant bit. Some procedures allow extracting
bit
fields
, i.e., number objects representing subsequences of the
binary representation of an exact integer object. Bit fields are
always positive, and always defined using a finite number of bits.
11.2  Fixnums
Every implementation must define its fixnum range as a closed
interval
such that
is a (mathematical) integer
≥ 24. Every
mathematical integer within an implementation's fixnum range must
correspond to an exact integer object that is representable within the
implementation.
A fixnum is an exact integer object whose value lies within this
fixnum range.
This section describes the
(rnrs arithmetic fixnums (6))
library,
which defines various operations on fixnums.
Fixnum operations perform integer arithmetic on their fixnum
arguments, but raise an exception with condition type
&implementation-restriction
if the result is not a fixnum.
This section uses
fx
fx
fx
, etc., as parameter
names for arguments that must be fixnums.
fixnum?
obj
procedure
Returns
#t
if
obj
is an exact
integer object within the fixnum range,
#f
otherwise.
fixnum-width
procedure
least-fixnum
procedure
greatest-fixnum
procedure
These procedures return
−2
−1
and 2
−1
− 1: the
width, minimum and the maximum value of the fixnum range, respectively.
fx=?
fx
fx
fx
...
procedure
fx>?
fx
fx
fx
...
procedure
fxfx
fx
fx
...
procedure
fx>=?
fx
fx
fx
...
procedure
fx<=?
fx
fx
fx
...
procedure
These procedures return
#t
if their arguments are (respectively):
equal, monotonically increasing, monotonically decreasing,
monotonically nondecreasing, or monotonically nonincreasing,
#f
otherwise.
fxzero?
fx
procedure
fxpositive?
fx
procedure
fxnegative?
fx
procedure
fxodd?
fx
procedure
fxeven?
fx
procedure
These numerical predicates test a fixnum for a particular property,
returning
#t
or
#f
. The five properties tested by
these procedures are: whether the number object is zero, greater than zero,
less than zero, odd, or even.
fxmax
fx
fx
...
procedure
fxmin
fx
fx
...
procedure
These procedures return the maximum or minimum of their arguments.
fx+
fx
fx
procedure
fx*
fx
fx
procedure
These procedures return the sum or product of their arguments,
provided that sum or product is a fixnum. An exception with condition
type
&implementation-restriction
is raised if
that sum or product is not a fixnum.
fx-
fx
fx
procedure
fx-
fx
procedure
With two arguments, this procedure returns the difference
fx
fx
, provided that difference is a fixnum.
With one argument, this procedure returns the additive
inverse of its argument, provided that integer object is a
fixnum.
An exception with condition type
&assertion
is raised if the
mathematically correct result of this procedure is not a fixnum.
(fx- (least-fixnum))
&assertion
exception
fxdiv-and-mod
fx
fx
procedure
fxdiv
fx
fx
procedure
fxmod
fx
fx
procedure
fxdiv0-and-mod0
fx
fx
procedure
fxdiv0
fx
fx
procedure
fxmod0
fx
fx
procedure
Fx
must be nonzero.
These procedures implement number-theoretic integer division and
return the results of the corresponding mathematical operations
specified in report section on “Integer division”.
(fxdiv
fx
fx
fx
fx
(fxmod
fx
fx
fx
fx
(fxdiv-and-mod
fx
fx
fx
fx
fx
fx
; two return values
(fxdiv0
fx
fx
fx
sb0
fx
(fxmod0
fx
fx
fx
sb0
fx
(fxdiv0-and-mod0
fx
fx
fx
fx
sb0
fx
fx
sb0
fx
; two return values
fx+/carry
fx
fx
fx
procedure
Returns the two fixnum results of the following computation:
(let* ((s (+
fx
fx
fx
))
(s0 (mod0 s (expt 2 (fixnum-width))))
(s1 (div0 s (expt 2 (fixnum-width)))))
(values s0 s1))
fx-/carry
fx
fx
fx
procedure
Returns the two fixnum results of the following computation:
(let* ((d (-
fx
fx
fx
))
(d0 (mod0 d (expt 2 (fixnum-width))))
(d1 (div0 d (expt 2 (fixnum-width)))))
(values d0 d1))
fx*/carry
fx
fx
fx
procedure
Returns the two fixnum results of the following computation:
(let* ((s (+ (*
fx
fx
fx
))
(s0 (mod0 s (expt 2 (fixnum-width))))
(s1 (div0 s (expt 2 (fixnum-width)))))
(values s0 s1))
fxnot
fx
procedure
Returns the unique fixnum that is congruent
mod 2
to the one's-complement of
fx
fxand
fx
...
procedure
fxior
fx
...
procedure
fxxor
fx
...
procedure
These procedures return the fixnum that is the bit-wise “and”,
“inclusive or”, or “exclusive or” of the two's complement
representations of their arguments. If they are passed only one
argument, they return that argument. If they are passed no arguments,
they return the fixnum (either −1 or 0) that acts as identity for the
operation.
fxif
fx
fx
fx
procedure
Returns the fixnum that is the bit-wise “if” of the two's complement
representations of its arguments, i.e. for each bit, if it is 1 in
fx
, the corresponding bit in
fx
becomes the value of
the corresponding bit in the result, and if it is 0, the corresponding
bit in
fx
becomes the corresponding bit in the value of the
result. This is the fixnum result of the following computation:
(fxior (fxand
fx
fx
(fxand (fxnot
fx
fx
))
fxbit-count
fx
procedure
If
fx
is non-negative, this procedure returns the
number of 1 bits in the two's complement representation of
fx
Otherwise it returns the result of the following computation:
(fxnot (fxbit-count (fxnot
ei
)))
fxlength
fx
procedure
Returns the number of bits needed to represent
fx
if it is
positive, and the number of bits needed to represent
(fxnot
fx
if it is negative, which is the fixnum result of the
following computation:
(do ((result 0 (+ result 1))
(bits (if (fxnegative?
fx
(fxnot
fx
fx
(fxarithmetic-shift-right bits 1)))
((fxzero? bits)
result))
fxfirst-bit-set
fx
procedure
Returns the index of the least significant 1 bit in
the two's complement representation of
fx
. If
fx
is 0, then −1 is returned.
(fxfirst-bit-set 0)
⇒  -1
(fxfirst-bit-set 1)
⇒  0
(fxfirst-bit-set -4)
⇒  2
fxbit-set?
fx
fx
procedure
Fx
must be non-negative and less than
(fixnum-width)
. The
fxbit-set?
procedure returns
#t
if the
fx
th bit is 1 in the two's complement
representation of
fx
, and
#f
otherwise. This is the
fixnum result of the following computation:
(not
(fxzero?
(fxand
fx
(fxarithmetic-shift-left 1
fx
))))
fxcopy-bit
fx
fx
fx
procedure
Fx
must be non-negative and less than
(fixnum-width)
Fx
must be 0 or
1. The
fxcopy-bit
procedure returns the result of replacing
the
fx
th bit of
fx
by
fx
, which is
the result of the following computation:
(let* ((mask (fxarithmetic-shift-left 1
fx
)))
(fxif mask
(fxarithmetic-shift-left
fx
fx
fx
))
fxbit-field
fx
fx
fx
procedure
Fx
and
fx
must be non-negative and less than
(fixnum-width)
. Moreover,
fx
must be less than or
equal to
fx
. The
fxbit-field
procedure returns the
number represented by the bits at the positions from
fx
(inclusive) to
fx
(exclusive), which is
the fixnum result of the following computation:
(let* ((mask (fxnot
(fxarithmetic-shift-left -1
fx
))))
(fxarithmetic-shift-right (fxand
fx
mask)
fx
))
fxcopy-bit-field
fx
fx
fx
fx
procedure
Fx
and
fx
must be non-negative and less than
(fixnum-width)
. Moreover,
fx
must be less than or
equal to
fx
. The
fxcopy-bit-field
procedure returns
the result of replacing in
fx
the bits at positions from
fx
(inclusive) to
fx
(exclusive) by the corresponding bits in
fx
, which
is the fixnum result of the following computation:
(let* ((to
fx
(start
fx
(end
fx
(from
fx
(mask1 (fxarithmetic-shift-left -1 start))
(mask2 (fxnot
(fxarithmetic-shift-left -1 end)))
(mask (fxand mask1 mask2)))
(fxif mask
(fxarithmetic-shift-left from start)
to))
fxarithmetic-shift
fx
fx
procedure
The absolute value of
fx
must be less than
(fixnum-width)
. If
(floor (*
fx
(expt 2
fx
)))
is a fixnum, then that fixnum is returned. Otherwise an exception
with condition type
&implementation-restriction
is
raised.
fxarithmetic-shift-left
fx
fx
procedure
fxarithmetic-shift-right
fx
fx
procedure
Fx
must be non-negative, and less than
(fixnum-width)
The
fxarithmetic-shift-left
procedure behaves the same as
fxarithmetic-shift
, and
(fxarithmetic-shift-right
fx
fx
behaves the same as
(fxarithmetic-shift
fx
(fx-
fx
))
fxrotate-bit-field
fx
fx
fx
fx
procedure
Fx
fx
, and
fx
must be non-negative
and less than
(fixnum-width)
Fx
must be less than or
equal to
fx
Fx
must be less than the difference
between
fx
and
fx
. The
fxrotate-bit-field
procedure returns the result of cyclically permuting in
fx
the
bits at positions from
fx
(inclusive) to
fx
(exclusive) by
fx
bits
towards the more significant bits, which is the result of the
following computation:
(let* ((n
fx
(start
fx
(end
fx
(count
fx
(width (fx- end start)))
(if (fxpositive? width)
(let* ((count (fxmod count width))
(field0
(fxbit-field n start end))
(field1
(fxarithmetic-shift-left
field0 count))
(field2
(fxarithmetic-shift-right
field0 (fx- width count)))
(field (fxior field1 field2)))
(fxcopy-bit-field n start end field))
n))
fxreverse-bit-field
fx
fx
fx
procedure
Fx
and
fx
must be non-negative and less than
(fixnum-width)
. Moreover,
fx
must be less than or
equal to
fx
. The
fxreverse-bit-field
procedure
returns
the fixnum obtained from
fx
by reversing the
order of the bits at positions from
fx
(inclusive) to
fx
(exclusive).
(fxreverse-bit-field
b1010010 1 4)
⇒  88 ;
b1011000
11.3  Flonums
This section describes the
(rnrs arithmetic flonums (6))
library.
This section uses
fl
fl
fl
, etc., as
parameter names for arguments that must be flonums, and
ifl
as a name for arguments that
must be integer-valued flonums, i.e., flonums for which the
integer-valued?
predicate returns true.
flonum?
obj
procedure
Returns
#t
if
obj
is a flonum,
#f
otherwise.
real->flonum
procedure
Returns the best flonum representation of
The value returned is a flonum that is numerically closest to the
argument.
Note:
If flonums are represented in binary floating point, then
implementations should break ties by preferring
the floating-point representation whose least significant bit is
zero.
fl=?
fl
fl
fl
...
procedure
flfl
fl
fl
...
procedure
fl<=?
fl
fl
fl
...
procedure
fl>?
fl
fl
fl
...
procedure
fl>=?
fl
fl
fl
...
procedure
These procedures return
#t
if their arguments are (respectively):
equal, monotonically increasing, monotonically decreasing,
monotonically nondecreasing, or monotonically nonincreasing,
#f
otherwise. These
predicates must be transitive.
(fl= +inf.0 +inf.0)
#t
(fl= -inf.0 +inf.0)
#f
(fl= -inf.0 -inf.0)
#t
(fl= 0.0 -0.0)
#t
(fl< 0.0 -0.0)
#f
(fl= +nan.0
fl
#f
(fl< +nan.0
fl
#f
flinteger?
fl
procedure
flzero?
fl
procedure
flpositive?
fl
procedure
flnegative?
fl
procedure
flodd?
ifl
procedure
fleven?
ifl
procedure
flfinite?
fl
procedure
flinfinite?
fl
procedure
flnan?
fl
procedure
These numerical predicates test a flonum for a particular property,
returning
#t
or
#f
The
flinteger?
procedure tests whether the number object is an integer,
flzero?
tests whether
it is
fl=?
to zero,
flpositive?
tests whether it is greater
than zero,
flnegative?
tests whether it is less
than zero,
flodd?
tests whether it is odd,
fleven?
tests whether it is even,
flfinite?
tests whether it is not an infinity and not a NaN,
flinfinite?
tests whether it is an infinity, and
flnan?
tests whether it is a NaN.
(flnegative? -0.0)
#f
(flfinite? +inf.0)
#f
(flfinite? 5.0)
#t
(flinfinite? 5.0)
#f
(flinfinite? +inf.0)
#t
Note:
(flnegative? -0.0)
must return
#f
else it would lose the correspondence with
(fl< -0.0 0.0)
, which is
#f
according to IEEE 754 [
].
flmax
fl
fl
...
procedure
flmin
fl
fl
...
procedure
These procedures return the maximum or minimum of their arguments.
They always return a NaN when one or more of the arguments is a NaN.
fl+
fl
...
procedure
fl*
fl
...
procedure
These procedures return the flonum sum or product of their flonum
arguments. In general, they should return the flonum that best
approximates the mathematical sum or product. (For implementations
that represent flonums using IEEE binary floating point, the
meaning of “best” is defined by the IEEE standards.)
(fl+ +inf.0 -inf.0)
⇒  +nan.0
(fl+ +nan.0
fl
⇒  +nan.0
(fl* +nan.0
fl
⇒  +nan.0
fl-
fl
fl
...
procedure
fl-
fl
procedure
fl/
fl
fl
...
procedure
fl/
fl
procedure
With two or more arguments, these procedures return the flonum
difference or quotient of their flonum arguments, associating to the
left. With one argument, however, they return the additive or
multiplicative flonum inverse of their argument. In general, they
should return the flonum that best approximates the mathematical
difference or quotient. (For implementations that represent flonums
using IEEE binary floating point, the meaning of “best” is
reasonably well-defined by the IEEE standards.)
(fl- +inf.0 +inf.0)
⇒  +nan.0
For undefined quotients,
fl/
behaves as specified by the
IEEE standards:
(fl/ 1.0 0.0)
⇒ +inf.0
(fl/ -1.0 0.0)
⇒ -inf.0
(fl/ 0.0 0.0)
⇒ +nan.0
flabs
fl
procedure
Returns the absolute value of
fl
fldiv-and-mod
fl
fl
procedure
fldiv
fl
fl
procedure
flmod
fl
fl
procedure
fldiv0-and-mod0
fl
fl
procedure
fldiv0
fl
fl
procedure
flmod0
fl
fl
procedure
These procedures implement number-theoretic integer division and
return the results of the corresponding mathematical operations
specified in report section on “Integer division”. For zero divisors, these
procedures may return a NaN or some unspecified flonum.
(fldiv
fl
fl
fl
fl
(flmod
fl
fl
fl
fl
(fldiv-and-mod
fl
fl
fl
fl
fl
fl
; two return values
(fldiv0
fl
fl
fl
fl
(flmod0
fl
fl
fl
fl
(fldiv0-and-mod0
fl
fl
fl
fl
fl
fl
; two return values
flnumerator
fl
procedure
fldenominator
fl
procedure
These procedures return the numerator or denominator of
fl
as a flonum; the result is computed as if
fl
was represented as
a fraction in lowest terms. The denominator is always positive. The
denominator of 0.0 is defined to be 1.0.
(flnumerator +inf.0)
⇒  +inf.0
(flnumerator -inf.0)
⇒  -inf.0
(fldenominator +inf.0)
⇒  1.0
(fldenominator -inf.0)
⇒  1.0
(flnumerator 0.75)
⇒  3.0 ; probably
(fldenominator 0.75)
⇒  4.0 ; probably
Implementations should implement following behavior:
(flnumerator -0.0)
⇒ -0.0
flfloor
fl
procedure
flceiling
fl
procedure
fltruncate
fl
procedure
flround
fl
procedure
These procedures return integral flonums for flonum arguments that are
not infinities or NaNs. For such arguments,
flfloor
returns the
largest integral flonum not larger than
fl
. The
flceiling
procedure
returns the smallest integral flonum not smaller than
fl
The
fltruncate
procedure returns the integral flonum closest to
fl
whose
absolute value is not larger than the absolute value of
fl
The
flround
procedure returns the closest integral flonum to
fl
rounding to even when
fl
represents a number halfway between two integers.
Although infinities and NaNs are not integer objects, these procedures return
an infinity when given an infinity as an argument, and a NaN when
given a NaN:
(flfloor +inf.0)
⇒  +inf.0
(flceiling -inf.0)
⇒  -inf.0
(fltruncate +nan.0)
⇒  +nan.0
flexp
fl
procedure
fllog
fl
procedure
fllog
fl
fl
procedure
flsin
fl
procedure
flcos
fl
procedure
fltan
fl
procedure
flasin
fl
procedure
flacos
fl
procedure
flatan
fl
procedure
flatan
fl
fl
procedure
These procedures compute the usual transcendental functions.
The
flexp
procedure computes the base-
exponential of
fl
The
fllog
procedure with a single argument computes the natural logarithm of
fl
(not the base ten logarithm);
(fllog
fl
fl
computes the base-
fl
logarithm of
fl
The
flasin
flacos
, and
flatan
procedures compute arcsine,
arccosine, and arctangent, respectively.
(flatan
fl
fl
computes the arc tangent of
fl
fl
See report
section on “Transcendental functions” for the underlying
mathematical operations. In the event that these operations do not
yield a real result for the given arguments, the result may be a NaN,
or may be some unspecified flonum.
Implementations that use IEEE binary floating-point arithmetic
should follow the relevant standards for these procedures.
(flexp +inf.0)
⇒ +inf.0
(flexp -inf.0)
⇒ 0.0
(fllog +inf.0)
⇒ +inf.0
(fllog 0.0)
⇒ -inf.0
(fllog -0.0)
unspecified
; if -0.0 is distinguished
(fllog -inf.0)
⇒ +nan.0
(flatan -inf.0)
⇒ -1.5707963267948965
; approximately
(flatan +inf.0)
⇒ 1.5707963267948965
; approximately
flsqrt
fl
procedure
Returns the principal square root of
fl
. For −0.0,
flsqrt
should return −0.0; for other negative arguments,
the result may be a NaN or some unspecified flonum.
(flsqrt +inf.0)
⇒  +inf.0
(flsqrt -0.0)
⇒  -0.0
flexpt
fl
fl
procedure
Either
fl
should be non-negative, or, if
fl
is
negative,
fl
should be an integer object.
The
flexpt
procedure returns
fl
raised to the power
fl
. If
fl
is
negative and
fl
is not an integer object, the result may be a
NaN, or may be some unspecified flonum. If
fl
is zero, then
the result is zero.
&no-infinities
condition type
make-no-infinities-violation
obj
procedure
no-infinities-violation?
obj
procedure
&no-nans
condition type
make-no-nans-violation
obj
procedure
no-nans-violation?
obj
procedure
These condition types could be defined by the following code:
(define-condition-type &no-infinities
&implementation-restriction
make-no-infinities-violation
no-infinities-violation?)
(define-condition-type &no-nans
&implementation-restriction
make-no-nans-violation no-nans-violation?)
These types describe that a program has executed an arithmetic
operations that is specified to return an infinity or a NaN,
respectively, on a Scheme implementation that is not able to represent
the infinity or NaN. (See report section on “Representability of infinities and NaNs”.)
fixnum->flonum
fx
procedure
Returns a flonum that is numerically closest to
fx
Note:
The result of this procedure may not be
numerically equal to
fx
, because the fixnum precision
may be greater than the flonum precision.
11.4  Exact bitwise arithmetic
This section describes the
(rnrs arithmetic bitwise (6))
library. The exact bitwise arithmetic provides generic operations on
exact integer objects. This section uses
ei
ei
ei
, etc.,
as parameter names that must be exact integer objects.
bitwise-not
ei
procedure
Returns the exact integer object whose two's complement representation is the
one's complement of the two's complement representation of
ei
bitwise-and
ei
...
procedure
bitwise-ior
ei
...
procedure
bitwise-xor
ei
...
procedure
These procedures return the exact integer object that is the bit-wise
“and”, “inclusive or”, or “exclusive or” of the two's complement
representations of their arguments. If they are passed only one
argument, they return that argument. If they are passed no arguments,
they return the integer object (either −1 or 0) that acts as identity for
the operation.
bitwise-if
ei
ei
ei
procedure
Returns the exact integer object that is the bit-wise “if” of the two's complement
representations of its arguments, i.e. for each bit, if it is 1 in
ei
, the corresponding bit in
ei
becomes the value of
the corresponding bit in the result, and if it is 0, the corresponding
bit in
ei
becomes the corresponding bit in the value of the
result.
This is the result of the following computation:
(bitwise-ior (bitwise-and
ei
ei
(bitwise-and (bitwise-not
ei
ei
))
bitwise-bit-count
ei
procedure
If
ei
is non-negative, this procedure returns the number of
1 bits in the two's complement representation of
ei
Otherwise it returns the result of the following computation:
(bitwise-not (bitwise-bit-count (bitwise-not
ei
)))
bitwise-length
ei
procedure
Returns the number of bits needed to represent
ei
if it is
positive, and the number of bits needed to represent
(bitwise-not
ei
if it is negative, which is the exact integer object that
is the result of the following computation:
(do ((result 0 (+ result 1))
(bits (if (negative?
ei
(bitwise-not
ei
ei
(bitwise-arithmetic-shift bits -1)))
((zero? bits)
result))
bitwise-first-bit-set
ei
procedure
Returns the index of the least significant 1
bit in the two's complement representation of
ei
If
ei
is 0, then −1 is returned.
(bitwise-first-bit-set 0)
⇒  -1
(bitwise-first-bit-set 1)
⇒  0
(bitwise-first-bit-set -4)
⇒  2
bitwise-bit-set?
ei
ei
procedure
Ei
must be non-negative.
The
bitwise-bit-set?
procedure returns
#t
if the
ei
th bit is 1 in the two's complement
representation of
ei
, and
#f
otherwise. This is the result of the following computation:
(not (zero?
(bitwise-and
(bitwise-arithmetic-shift-left 1
ei
ei
)))
bitwise-copy-bit
ei
ei
ei
procedure
Ei
must be non-negative, and
ei
must be either 0 or 1.
The
bitwise-copy-bit
procedure returns the result of replacing
the
ei
th bit of
ei
by the
ei
th bit of
ei
, which is
the result of the following computation:
(let* ((mask (bitwise-arithmetic-shift-left 1
ei
)))
(bitwise-if mask
(bitwise-arithmetic-shift-left
ei
ei
ei
))
bitwise-bit-field
ei
ei
ei
procedure
Ei
and
ei
must be non-negative, and
ei
must be less than or equal to
ei
The
bitwise-bit-field
procedure returns the
number represented by the bits at the positions from
ei
(inclusive) to
ei
(exclusive), which is
the result of the following computation:
(let ((mask
(bitwise-not
(bitwise-arithmetic-shift-left -1
ei
))))
(bitwise-arithmetic-shift-right
(bitwise-and
ei
mask)
ei
))
bitwise-copy-bit-field
ei
ei
ei
ei
procedure
Ei
and
ei
must be non-negative,
and
ei
must be less than or equal to
ei
The
bitwise-copy-bit-field
procedure returns
the result of replacing in
ei
the bits at positions from
ei
(inclusive) to
ei
(exclusive) by the corresponding bits in
ei
, which
is the fixnum result of the following computation:
(let* ((to
ei
(start
ei
(end
ei
(from
ei
(mask1
(bitwise-arithmetic-shift-left -1 start))
(mask2
(bitwise-not
(bitwise-arithmetic-shift-left -1 end)))
(mask (bitwise-and mask1 mask2)))
(bitwise-if mask
(bitwise-arithmetic-shift-left from
start)
to))
bitwise-arithmetic-shift
ei
ei
procedure
Returns the result of the following computation:
(floor (*
ei
(expt 2
ei
)))
Examples:
(bitwise-arithmetic-shift -6 -1)
⇒ -3
(bitwise-arithmetic-shift -5 -1)
⇒ -3
(bitwise-arithmetic-shift -4 -1)
⇒ -2
(bitwise-arithmetic-shift -3 -1)
⇒ -2
(bitwise-arithmetic-shift -2 -1)
⇒ -1
(bitwise-arithmetic-shift -1 -1)
⇒ -1
bitwise-arithmetic-shift-left
ei
ei
procedure
bitwise-arithmetic-shift-right
ei
ei
procedure
Ei
must be non-negative. The
bitwise-arithmetic-shift-left
procedure returns the same result as
bitwise-arithmetic-shift
, and
(bitwise-arithmetic-shift-right
ei
ei
returns the same result as
(bitwise-arithmetic-shift
ei
(-
ei
)).
bitwise-rotate-bit-field
ei
ei
ei
ei
procedure
Ei
ei
ei
must be non-negative,
ei
must be less than or equal to
ei
, and
ei
must be non-negative.
procedure returns the result of cyclically permuting in
ei
the
bits at positions from
ei
(inclusive) to
ei
(exclusive) by
ei
bits
towards the more significant bits, which is the result of the
following computation:
(let* ((n
ei
(start
ei
(end
ei
(count
ei
(width (- end start)))
(if (positive? width)
(let* ((count (mod count width))
(field0
(bitwise-bit-field n start end))
(field1 (bitwise-arithmetic-shift-left
field0 count))
(field2 (bitwise-arithmetic-shift-right
field0
(- width count)))
(field (bitwise-ior field1 field2)))
(bitwise-copy-bit-field n start end field))
n))
bitwise-reverse-bit-field
ei
ei
ei
procedure
Ei
and
ei
must be non-negative, and
ei
must be less than or equal to
ei
. The
bitwise-reverse-bit-field
procedure returns
the result obtained from
ei
by reversing the
order of the bits at positions from
ei
(inclusive) to
ei
(exclusive).
(bitwise-reverse-bit-field
b1010010 1 4)
⇒  88 ;
b1011000
[Go to
first
previous
next
page
contents
index