2019-03-15 15:23:47 +01:00
|
|
|
# Working With Numbers
|
|
|
|
|
2020-01-08 14:39:12 +01:00
|
|
|
Numbers in RETRO are signed integers.
|
2019-03-15 15:23:47 +01:00
|
|
|
|
|
|
|
## Token Prefix
|
|
|
|
|
|
|
|
All numbers start with a `#` prefix.
|
|
|
|
|
2019-03-18 15:52:49 +01:00
|
|
|
## Namespace
|
|
|
|
|
|
|
|
Most words operating on numbers are in the `n:` namespace.
|
|
|
|
|
2020-01-08 14:39:12 +01:00
|
|
|
## Range of Values
|
2019-03-15 15:23:47 +01:00
|
|
|
|
2020-01-08 14:39:12 +01:00
|
|
|
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
|