Next: , Previous: Defining Ptobs, Up: Data Types


6.1.8 Smob Cells

A smob is a miscellaneous datatype. The type code and GCMARK bit occupy the lower order 16 bits of the CAR half of the cell. The rest of the CAR can be used for sub-type or other information. The CDR contains data of size long and is often a pointer to allocated memory.

Like ptobs, new varieties of smobs can be defined dynamically (see Defining Smobs). These are the initial smobs:

— smob: tc_free_cell

unused cell on the freelist.

— smob: tc16_flo

single-precision float.

Inexact number data types are subtypes of type tc16_flo. If the sub-type is:

  1. a single precision float is contained in the CDR.
  2. CDR is a pointer to a malloced double.
  1. CDR is a pointer to a malloced pair of doubles.
— smob: tc_dblr

double-precision float.

— smob: tc_dblc

double-precision complex.

— smob: tc16_bigpos
— smob: tc16_bigneg

positive and negative bignums, respectively.

Scm has large precision integers called bignums. They are stored in sign-magnitude form with the sign occuring in the type code of the SMOBs bigpos and bigneg. The magnitude is stored as a malloced array of type BIGDIG which must be an unsigned integral type with size smaller than long. BIGRAD is the radix associated with BIGDIG.

NUMDIGS_MAX (defined in scmfig.h) limits the number of digits of a bignum to 1000. These digits are base BIGRAD, which is typically 65536, giving 4816 decimal digits.

Why only 4800 digits? The simple multiplication algorithm SCM uses is O(n^2); this means the number of processor instructions required to perform a multiplication is some multiple of the product of the number of digits of the two multiplicands.

          digits * digits  ==> operations
           5                    x
           50                   100 * x
           500                  10000 * x
           5000                 1000000 * x

To calculate numbers larger than this, FFT multiplication [O(n*log(n))] and other specialized algorithms are required. You should obtain a package which specializes in number-theoretical calculations:

ftp://megrez.math.u-bordeaux.fr/pub/pari/
— smob: tc16_promise

made by DELAY. See Control features.

— smob: tc16_arbiter

synchronization object. See Process Synchronization.

— smob: tc16_macro

macro expanding function. See Macro Primitives.

— smob: tc16_array

multi-dimensional array. See Arrays.

This type implements both conventional arrays (those with arbitrary data as elements see Conventional Arrays) and uniform arrays (those with elements of a uniform type see Uniform Array).

Conventional Arrays have a pointer to a vector for their CDR. Uniform Arrays have a pointer to a Uniform Vector type (string, Vbool, VfixZ32, VfixN32, VfloR32, VfloR64, or VfloC64) in their CDR.