retroforth/doc/book/techniques/numbers
crc 32d22c51fa docs: more details on assembly, numbers
FossilOrigin-Name: 94245d967728aac960b4ce6a834a4e51d84238490d0be4c9e849751a385f6fb6
2020-01-08 13:39:12 +00:00

82 lines
1.2 KiB
Text

# Working With Numbers
Numbers in RETRO are signed integers.
## Token Prefix
All numbers start with a `#` prefix.
## Namespace
Most words operating on numbers are in the `n:` namespace.
## Range of Values
A default RETRO system with 32 bit cells provides a range of
-2,147,483,648 to 2,147,483,647. For 64 bit systems, the range
will be -9,223,372,036,854,775,807 to 9,223,372,036,854,775,806.
You can check the range your VM and image support using:
n:MIN
n:MAX
These will return the limits for your system.
## Comparisons
RETRO provides a number of comparison words for numeric values.
The basic comparators are:
-eq?
eq?
lt?
lteq?
gt?
gteq?
Additionally RETRO also provides:
n:-zero?
n:between?
n:even?
n:negative?
n:odd?
n:positive?
n:strictly-positive?
n:zero?
## Basic Operations
+
-
*
/
mod
/mod
n:abs
n:dec
n:inc
n:limit
n:max
n:min
n:negate
n:pow
n:sqrt
n:square
## Conversions
You can convert a number to a string with `n:to-string` or
to a floating point value with `n:to-float`.
#123 n:to-float f:put
#123 n:to-string s:put
## Display
To display a number, use `n:put`.
#123 n:put