5.2 Floating-point number and complex literals

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:

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.