For floating-point numbers in Forth, you recognize them due to their
exponent. I.e. 1.
is a double-cell integer, and 1e0
is
a floating-point number; the latter can be (and usually is) shortened
to 1e
. Both the significand (the part before the e
or
E
) and the exponent may have signs (including +
); the
significand must contain at least one digit and may contain a decimal
point, the exponent can be empty. Floating-point numbers always use
decimal base for both significand and exponent, and are only
recognized when the base is decimal. Examples are: 1e 1e0 1.e
1.e0 +1e+0
(which all represent the same number) +12.E-4
.
A Gforth extension (since 1.0) is to write a floating-point number in
scaled notation: It can optionally have a sign, then one or more
digits, then use one of the mostly SI-defined scaling symbols (aka
metric prefixes) or %
, and then optionally more digits. Here’s
the full list of scaling symbols that Gforth accepts:
Q
e30
quetta
R
e27
ronna
Y
e24
yotta
Z
e21
zetta
X
e18
exa (not E
)
P
e15
peta
T
e12
tera
G
e9
giga
M
e6
mega
k
e3
kilo
h
e2
hecto
d
e-1
deci
%
e-2
percent (not c
)
m
e-3
milli
u
e-6
micro (not μ
)
n
e-9
nano
p
e-12
pico
f
e-15
femto
a
e-18
atto
z
e-21
zepto
y
e-24
yocto
r
e-27
ronto
q
e-30
quecto
Unlike most of the rest of Gforth, scaling symbols are treated
case-sensitively. Using the scaled notation is equivalent to using a
decimal point instead of the scaling symbol and appending the
exponential notation at the end. Examples of scaled notation:
6k5
(6500e) 23%
(0.23e).
In Gforth (since 1.0) you can input a complex number with
real+imaginaryi
, where both real
and
imaginary
are strings that are recognized as floating-point
numbers. E.g., 1e+2ei
. This pushes the values 1e
and
2e
on the floating-point stack, so one might just as well have
written 1e 2e
, but 1e+2ei
makes the intent obvious.