Next: , Previous: Other I/O, Up: Other I/O


5.19.1 Simple numeric output

The simplest output functions are those that display numbers from the data or floating-point stacks. Floating-point output is always displayed using base 10. Numbers displayed from the data stack use the value stored in base.

.       n –         core       “dot”

Display (the signed single number) n in free-format, followed by a space.

dec.       n –         gforth       “dec.”

Display n as a signed decimal number, followed by a space.

hex.       u –         gforth       “hex.”

Display u as an unsigned hex number, prefixed with a "$" and followed by a space.

u.       u –         core       “u-dot”

Display (the unsigned single number) u in free-format, followed by a space.

.r       n1 n2 –         core-ext       “dot-r”

Display n1 right-aligned in a field n2 characters wide. If more than n2 characters are needed to display the number, all digits are displayed. If appropriate, n2 must include a character for a leading “-”.

u.r       u n –         core-ext       “u-dot-r”

Display u right-aligned in a field n characters wide. If more than n characters are needed to display the number, all digits are displayed.

d.       d –         double       “d-dot”

Display (the signed double number) d in free-format. followed by a space.

ud.       ud –         gforth       “u-d-dot”

Display (the signed double number) ud in free-format, followed by a space.

d.r       d n –         double       “d-dot-r”

Display d right-aligned in a field n characters wide. If more than n characters are needed to display the number, all digits are displayed. If appropriate, n must include a character for a leading “-”.

ud.r       ud n –         gforth       “u-d-dot-r”

Display ud right-aligned in a field n characters wide. If more than n characters are needed to display the number, all digits are displayed.

f.       r –         float-ext       “f-dot”

Display (the floating-point number) r without exponent, followed by a space.

fe.       r –         float-ext       “f-e-dot”

Display r using engineering notation (with exponent dividable by 3), followed by a space.

fs.       r –         float-ext       “f-s-dot”

Display r using scientific notation (with exponent), followed by a space.

f.rdp       rf +nr +nd +np –         gforth       “f.rdp”

Print float rf formatted. The total width of the output is nr. For fixed-point notation, the number of digits after the decimal point is +nd and the minimum number of significant digits is np. Set-precision has no effect on f.rdp. Fixed-point notation is used if the number of siginicant digits would be at least np and if the number of digits before the decimal point would fit. If fixed-point notation is not used, exponential notation is used, and if that does not fit, asterisks are printed. We recommend using nr>=7 to avoid the risk of numbers not fitting at all. We recommend nr>=np+5 to avoid cases where f.rdp switches to exponential notation because fixed-point notation would have too few significant digits, yet exponential notation offers fewer significant digits. We recommend nr>=nd+2, if you want to have fixed-point notation for some numbers. We recommend np>nr, if you want to have exponential notation for all numbers.

Examples of printing the number 1234.5678E23 in the different floating-point output formats are shown below:

     f. 123456779999999000000000000.
     fe. 123.456779999999E24
     fs. 1.23456779999999E26