User Tools

Site Tools


jvs:cigal:manual:chapter1:numbers

CIGAL Reference Manual, Chapter 1 (Topics): numbers

Numbers -- CIGAL Numbers

Entering numbers

Numbers in CIGAL can be either integers or floating point numbers. If a number contains a decimal point then it is stored as a 32-bit floating point number with approximately 7 significant digits. Floating point numbers are always decimal (base 10). Some examples of floating point numbers are:

              10.     123.456     .0032      0.12

If a number is entered as an integer, without a decimal point, then it can be in base 2, 4, 8, 10, or 16. The base is determined by the presence of a letter at the end of the number. If there is no letter, then the base is determined by the value of the internal variable IBASE, which is 10 (decimal) by default (see IBASE(4)). You can specify the base explicitly for any number by ending the number with the letter 'b', 'q', 'o', 'd', or 'h' which specify base 2, 4, 8, 10, or 16 respectively. The following table gives some examples for each base with the corresponding decimal values in parentheses (the examples assume IBASE = 10):

 Base              Range of digits     Examples                Decimal values
 ================  ===============     ========                ==============
 Binary        2        0-1            10b, 101B, 100110b      2, 5, 38
               4        0-3            10q,  31Q, 1231q        4, 13, 109
 Octal         8        0-7            10o,  27o, 1321o        8, 23, 721
 Decimal      10        0-9            10d,  33,  3214         10, 33, 3214
 Hexadecimal  16        0-f            10h,  0fH, 0b3ah        16, 15, 2874

Anytime that you enter a number in CIGAL you can enter the number in any base by using the base specifying characters. This is true whether you are entering numbers on a command line or as part of data input (see DATAENTRY(1)). You can freely intermix different bases, integers, or floating point integers from one number to the next.

Note: As usual for hexadecimal numbers, the single character values corresponding to 10-15 are expressed as the letters a-f. Because the command line parser identifies numbers by the fact that the first character is a digit, hexadecimal numbers that start with an a-f must be preceded by an initial '0' to avoid being interpreted as character strings. Letters that are part of a number can be either upper or lower case (but avoid using capital 'O' for ocatl since it is hard to distinguish from a zero).

Numbers are stored within CIGAL in one of seven different formats. The storage format is determined by the type of variable (see VARIABLES(1)). The formats are:

  Name     Storage                      Range of legal values
  ====     =======                      =====================
  Bit      unsigned 1 bit integer                 0 - 1
  Crumb    unsigned 2 bit integer                 0 - 3
  Nibble   unsigned 4 bit integer                 0 - 15
  Byte     unsigned 8 bit integer                 0 - 255
  Integer  signed 16 bit integer             -32767 - 32767
  Long     signed 32 bit integer        -2147483647 - 2147483647
  Real     signed 32 bit floating pt.      7 significant digits

The range of legal values for signed integers is one number less than the maximum range possible because the most negative value (-0: the sign bit set to 1, followed by all zeros) is reserved for a 'missing value' code (see ARITHMETIC(1)).

NOTE: CIGAL currently has some bugs when dealing with very large LONG integers; it tends to round them off to about 7 significant digits.

Displaying numbers

When number values are printed they are normally displayed in decimal (base 10) format. Floating point values are always displayed in decimal. Integer values can be displayed in other bases in several ways:

  • By setting the obase variable to the desired base (e.g. 2, 8, 10, 16).

This will cause all integers displayed using the type command to use that base (default: obase = 10).

  • By explictly specifying the base in the format string of a ftype command.
  • By using the base macro command. For example, try: “base 1234”

See Also:
ibase, obase

CIGAL Home, CIGAL Manual, Topics List, Manual Help

jvs/cigal/manual/chapter1/numbers.txt · Last modified: 2023/02/23 18:43 (external edit)