Go to the first, previous, next, last section, table of contents.

Floating Point

The format of floating point numbers recognized by the outer (aka text) interpreter is: a signed decimal number, possibly containing a decimal point (.), followed by E or e, optionally followed by a signed integer (the exponent). E.g., 1e is the same as +1.0e+0. Note that a number without e is not interpreted as floating-point number, but as double (if the number contains a .) or single precision integer. Also, conversions between string and floating point numbers always use base 10, irrespective of the value of BASE (in Gforth; for the standard this is an ambiguous condition). If BASE contains a value greater then 14, the E may be interpreted as digit and the number will be interpreted as integer, unless it has a signed exponent (both + and - are allowed as signs).

Angles in floating point operations are given in radians (a full circle has 2 pi radians). Note, that Gforth has a separate floating point stack, but we use the unified notation.

Floating point numbers have a number of unpleasant surprises for the unwary (e.g., floating point addition is not associative) and even a few for the wary. You should not use them unless you know what you are doing or you don't care that the results you get are totally bogus. If you want to learn about the problems of floating point numbers (and how to avoid them), you might start with David Goldberg, What Every Computer Scientist Should Know About Floating-Point Arithmetic, ACM Computing Surveys 23(1):5-48, March 1991 (http://www.validgh.com/goldberg/paper.ps).

f+       r1 r2 -- r3       float       ``f-plus''

f-       r1 r2 -- r3       float       ``f-minus''

f*       r1 r2 -- r3       float       ``f-star''

f/       r1 r2 -- r3       float       ``f-slash''

fnegate       r1 -- r2       float       ``fnegate''

fabs       r1 -- r2       float-ext       ``fabs''

fmax       r1 r2 -- r3       float       ``fmax''

fmin       r1 r2 -- r3       float       ``fmin''

floor       r1 -- r2       float       ``floor''

round towards the next smaller integral value, i.e., round toward negative infinity

fround       r1 -- r2       float       ``fround''

round to the nearest integral value

f**       r1 r2 -- r3       float-ext       ``f-star-star''

r3 is r1 raised to the r2th power

fsqrt       r1 -- r2       float-ext       ``fsqrt''

fexp       r1 -- r2       float-ext       ``fexp''

fexpm1       r1 -- r2       float-ext       ``fexpm1''


fln       r1 -- r2       float-ext       ``fln''

flnp1       r1 -- r2       float-ext       ``flnp1''


flog       r1 -- r2       float-ext       ``flog''

the decimal logarithm

falog       r1 -- r2       float-ext       ``falog''


fsin       r1 -- r2       float-ext       ``fsin''

fcos       r1 -- r2       float-ext       ``fcos''

fsincos       r1 -- r2 r3       float-ext       ``fsincos''

r2=sin(r1), r3=cos(r1)

ftan       r1 -- r2       float-ext       ``ftan''

fasin       r1 -- r2       float-ext       ``fasin''

facos       r1 -- r2       float-ext       ``facos''

fatan       r1 -- r2       float-ext       ``fatan''

fatan2       r1 r2 -- r3       float-ext       ``fatan2''

r1/r2=tanr3. The standard does not require, but probably intends this to be the inverse of fsincos. In gforth it is.

fsinh       r1 -- r2       float-ext       ``fsinh''

fcosh       r1 -- r2       float-ext       ``fcosh''

ftanh       r1 -- r2       float-ext       ``ftanh''

fasinh       r1 -- r2       float-ext       ``fasinh''

facosh       r1 -- r2       float-ext       ``facosh''

fatanh       r1 -- r2       float-ext       ``fatanh''

Go to the first, previous, next, last section, table of contents.