12.3. The Numbers Dictionary
Prev | Chapter 12. Numbers | Next

## 12.3. The Numbers Dictionary [sec_the_numbers_dictionary]

### 12.3.1. Random Numbers

To ease reproducibility, the variable `*RANDOM-STATE*` is initialized to the same value on each invocation, so that

    $ clisp -norc -x '(RANDOM 1s0)'

will always print the same number.

If you want a new random state on each invocation, you can arrange for that by using init function:

    $ clisp -norc -x '(EXT:SAVEINITMEM "foo" :init-function (LAMBDA () (SETQ *RANDOM-STATE* (MAKE-RANDOM-STATE T))))'
    $ clisp -norc -M foo.mem -x '(RANDOM 1s0)'

or by placing `(`SETQ` `*RANDOM-STATE*` (`MAKE-RANDOM-STATE` `T`))` into your RC file.

### 12.3.2. Additional Integer Functions

Function `EXT:!` `(`EXT:!` `n`)` returns the factorial of `n`, `n` being a nonnegative `INTEGER`.

Function `EXT:EXQUO`. `(`EXT:EXQUO` `x` `y`)` returns the integer quotient `x/y` of two integers `x`,`y`, and `SIGNAL`s an `ERROR` when the quotient is not integer. (This is more efficient than `/`.)

Function `EXT:XGCD`. `(`EXT:XGCD` `x1` ... `xn`)` returns the values `l`, `k1`, ..., `kn`, where `l` is the greatest common divisor of the integers `x1`, ..., `xn`, and `k1`, ..., `kn` are the integer coefficients such that

    l = (GCD x1 ... xn)
      = (+ (* k1 x1) ... (* kn xn))

Function `EXT:MOD-EXPT`. `(`EXT:MOD-EXPT` `k` `l` `m`)` is equivalent to `(`MOD` (`EXPT` `k` `l`) `m`)` except it is more efficient for very large arguments.

### 12.3.3. Floating Point Arithmetics

Function `EXPT`. `(`EXPT` `base` `exponent`)` is not very precise if `exponent` has a large absolute value.

Function `LOG`. `(`LOG` `number` `base`)` `SIGNAL`s an `ERROR` if ``base` = 1`.

Constant `PI`. The value of `PI` is a `LONG-FLOAT` with the precision given by `(`EXT:LONG-FLOAT-DIGITS`)`. When this precision is changed, the value of `PI` is automatically recomputed. Therefore `PI` is not a constant variable.

Function `UPGRADED-COMPLEX-PART-TYPE`. When the argument is not a recognizable subtype or `REAL`, `UPGRADED-COMPLEX-PART-TYPE` `SIGNAL`s an `ERROR`, otherwise it returns its argument (even though a `COMPLEX` number in CLISP can always have `REALPART` and `IMAGPART` of any type) because it allows the most precise type inference.

Variable `CUSTOM:*DEFAULT-FLOAT-FORMAT*`. When rational numbers are to be converted to floats (due to `FLOAT`, `COERCE`, `SQRT` or a transcendental function), the result type is given by the variable `CUSTOM:*DEFAULT-FLOAT-FORMAT*`.

Macro `EXT:WITHOUT-FLOATING-POINT-UNDERFLOW`. The macro `(`EXT:WITHOUT-FLOATING-POINT-UNDERFLOW` {`form`}*)` executes the `form`s, with errors of type `FLOATING-POINT-UNDERFLOW` inhibited. Floating point operations will silently return zero instead of `SIGNAL`ing an `ERROR` of type `FLOATING-POINT-UNDERFLOW`.

Condition `FLOATING-POINT-INVALID-OPERATION`. This `CONDITION` is never `SIGNAL`ed by CLISP.

Condition `FLOATING-POINT-INEXACT`. This `CONDITION` is never `SIGNAL`ed by CLISP.

### 12.3.4. Float Decoding [fun_decode-fl_decode-float]

`FLOAT-RADIX` always returns 2.

`(`FLOAT-DIGITS` `number` `digits`)` coerces `number` (a `REAL`) to a floating point number with at least `digits` mantissa digits. The following always evaluates to `T`:

    (>= (FLOAT-DIGITS (FLOAT-DIGITS number digits)) digits)

### 12.3.5. Boolean Operations [convar_boole-_cm_boole-xor]

Table 12.1. Boolean operations

constant | value
--- | ---
`BOOLE-CLR` | 0
`BOOLE-SET` | 15
`BOOLE-1` | 10
`BOOLE-2` | 12
`BOOLE-C1` | 5
`BOOLE-C2` | 3
`BOOLE-AND` | 8
`BOOLE-IOR` | 14
`BOOLE-XOR` | 6
`BOOLE-EQV` | 9
`BOOLE-NAND` | 7
`BOOLE-NOR` | 1
`BOOLE-ANDC1` | 4
`BOOLE-ANDC2` | 2
`BOOLE-ORC1` | 13
`BOOLE-ORC2` | 11

### 12.3.6. Fixnum Limits [convar_most-p_ative-fixnum]

Table 12.2. Fixnum limits

CPU type | 32-bit CPU | 64-bit CPU
--- | --- | ---
`MOST-POSITIVE-FIXNUM` | 224-1 = 16777215 | 248-1 = 281474976710655
`MOST-NEGATIVE-FIXNUM` | -224 = -16777216 | -248 = -281474976710656

### 12.3.7. Bignum Limits [typ_bignum]

`BIGNUM`s are limited in size. Their maximum size is `32*(216-2)=2097088` bits. The largest representable `BIGNUM` is therefore `22097088-1`.

### 12.3.8. Float Limits [convar_most-p_d-long-float]

Together with `PI`, the other `LONG-FLOAT` constants

`LEAST-NEGATIVE-LONG-FLOAT` | `LONG-FLOAT-EPSILON`
`LEAST-NEGATIVE-NORMALIZED-LONG-FLOAT` | `LONG-FLOAT-NEGATIVE-EPSILON`
`LEAST-POSITIVE-LONG-FLOAT` | `MOST-NEGATIVE-LONG-FLOAT`
`LEAST-POSITIVE-NORMALIZED-LONG-FLOAT` | `MOST-POSITIVE-LONG-FLOAT`

are recomputed whenever `(`EXT:LONG-FLOAT-DIGITS`)` is `SETF`ed. They are not constant variables.

| These notes document CLISP version 2.45 | Last modified: 2008-04-15

Enter your search termsSubmit search form
Webclisp.cons.orgclisp.podval.orgwww.lisp.org

Prev | Up | Next
12.2. Number Concepts | Home | Chapter 13. Characters