In Poplog there is a major division between two kinds of data items: simple items, and compound items. Simple items are directly represented in the machine as bit patterns. Compound items are represented indirectly as bit patterns that are pointers, or addresses, of data structures that contain the actual information.
The simple items can all be completely represented in a single "machine word", which is normally 32 bits, but may be larger on some machine architectures. Compound items are larger structures, and each includes information about what TYPE of item it is, so that run time checks can be made. (See also Chapter 2 and REF DATA). This type information is represented by another pointer, to a KEY for the type of data in question.
There are only two sorts of simple items in Poplog, integers and decimals. Both are represented within a single machine word. However not all the bits of the word can be used for this purpose, as two bits in every word are reserved for specifying whether the item is a compound item, an integer, or a decimal. In a 32 bit machine that leaves 30 bits for the integer or decimal, of which 1 will be for the sign.
This "direct" representation by bit patterns means that operations on integers or decimals do not create new Poplog datastructures, since they merely involve operations on bit patterns in machine registers.
By contrast, operations that create compound items, such as bigintegers, ddecimals, ratios and complexes will require additional records to be allocated in the storage "heap", and their use can therefore trigger garbage collections every now and again. (For more information see HELP EFFICIENCY.)
Besides the numerical compound items just mentioned, all other Pop-11 data types besides integers and decimals are compound items, including lists, words, strings, procedures, properties, arrays, etc.
Another distinction that is important is between those items that have fixed size in memory and those that can be as big as needed. Integers, decimals, ddecimals, and complexes composed only of integers, decimals and ddecimals all have fixed sizes. So typically a ddecimal will occupy three words, one for the key which identifies the object as a ddecimal, and two for the actual number.
By contrast bigintegers and ratios, and complexes composed of bigintegers and ratios provide "infinite" precision arithmetic and can take up as much store as is available. So the only limit to the size of a biginteger is the (virtual) memory available in the machine. To illustrate this try the following:
define factorial(n); if n == 0 then 1 else n * factorial(n - 1) endif enddefine; factorial(3) => ** 6 factorial(30) => ** 265252859812191058636308480000000 factorial(100) => ** 933262154439441526816992388562667004907159682643816214685929638 95217599993229915608941463976156518286253697920827223758251185 210916864000000000000000000000000 factorial(1000) =>The number printed out by the last example will take about 37 lines (depending on your screendwidth).
Similarly ratios can represent small numbers very accurately, e.g.
237/factorial(37) => ** 79_/4587917697075448348771993193860300800000000 1/(2**150 - 1) => ** 1_/1427247692705959881058285969449495136382746623
Pop-11 provides facilities for creating records and vectors that include numbers represented compactly as bit patterns. Examples are
bitvectors, (described in HELP BITVECTORS,)
strings (which contain packed 8 bit integers, described in REF STRINGS)
shortvecs (which contain packed 16 bit integers, described in REF INTVEC)
intvecs (which contain packed 32 bit integers, described REF INTVEC)
NOTE: The numbers of bits per field in shortvecs and intvecs is implementation dependent.
Using the "defclass" syntax construct users can define new record types and vector types containing packed integers of various field sizes.
Because Pop-11 can tell the types of all these integers from their occupancy of fields of particular types, it does not need to use 2 bits per integer to recognize them. However, extraction or insertion of these field values, e.g. assigning to or from a variable, necessitates conversion to and from the standard Poplog representation. This is performed automatically by the corresponding record or vector access and update procedures.
It is also possible to have vectors or records with packed floating point numbers, and similar remarks apply to them.