Reva: Numbers

General

Reva supports a variety of number formats. The most widely supported is the single-cell integer, which is what you get if you just type a regular number. Generally, a number is just what you expect -- a series of digits, maybe with a leading minus sign. For example:

  1234
  -5678

Integers

Single

This is the "normal" kind of number. You get it simply by typing in digits. It is a four-byte (one-cell) integer. The formats permitted are:
  N
  -N

where "N" is any sequence of digits valid in the current base You may also prefix it with the integer modifiers:

  $ - base 16
  # - base 10
  & - base 8
  % - base 2

So these are also valid singles:

  $abcd
  %100110
  #123

but these are not:

  $xyz
  %12
  #1e34

There is a further special case prefix of a single quote character, ' - this causes Reva to interpret the next character as its ASCII value:

  'A

puts "65" on TOS.

Double

These are double-cell integers, eight-bytes long. They look the same as "single" numbers except for two things:
  1. They are always suffixed by the character L (capital-L)
  2. It is permitted (but not required) to punctuate them with commas and periods inside

Examples of valid doubles:

  1,234,567,890,555L
  $aabbccdd.11223344L

Invalid doubles:

  1,234,567,890,555
  L1234547890

Reva will allow you to enter doubles, but only has rudimentary built-in support: it provides d+ and d- to add and subtract them. If you want more support for doubles, then needs math/doubles will load the support library (so you can print them and multiply etc.)

Floating-point

"Floating-point" numbers are more-or-less what mathematicians call "real" numbers. They can represent a wide variety of values, at the expense of precision. Reva does not support them by default, since most applications do not require them. If your application does require them, simply type needs math/floats to load the floating-point support library.

Default 80-bit IEEE

Reva's support for floats uses the x86 FPU native 80-bit IEEE format, thus f@ reads 10 bytes, and f! writes 10 bytes. There is also support for 4-byte and 8-byte floating point values. This provides the maximum precision, but is inconvenient when interfacing with libraries written for most C compilers. In Reva, the valid formats for floats are:
  N.
  N.M
  .M
  N.MeX

Floats require a period in the number. They may have an 'exponent block'. So these are all valid floats representing the same value:

  10.
  1.0e1
  10.0
  .1e2

These are also valid floats:

  -10.
  -1.0e1
  5.e-3
  5.033E5

Conversion between numbers and Strings

Numbers to strings

The word (.) converts a single in TOS to a string. Similarly, (d.) converts a double to a string. The single words are in Reva by default; the double words need to be loaded via needs math/doubles.

The word (f.) converts FTOS to a string, utilizing sigdig to control number of significant digits printed after the decimal.

Strings to numbers

The words >single,>double >float all work similarly. They take a string, and try to convert it to the numeric type indicated. If they succeed, they leave true on TOS and the converted number in TOS or FTOS as appropriate. If they fail, they leave false on TOS and leave the original string underneath it.

Changing the numeric base

The convenience words hex, decimal, octal and binary change the base to 16, 10,8, and 2 respectively. One can also change the base arbitrarily by setting the variable base.
 16 base !
 10  | this is the same as $10, or 16 decimal
 #10 | this is 10 decimal
 10 base !
 10  | this is the same as $a, or 10 decimal
 $10 | this is 16 decimal