www.delorie.com/gnu/docs/gforth/gforth_74.html search
Gforth Manual

 [ < ] [ > ] [ << ] [ Up ] [ >> ] [Top] [Contents] [Index] [ ? ]

### 5.5.6 Floating Point

For the rules used by the text interpreter for recognising floating-point numbers see 5.13.2 Number Conversion.

Gforth has a separate floating point stack, but the documentation uses the unified notation.(9)

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, ACM Computing Surveys 23(1):5-48.

doc-d>f doc-f>d doc-f+ doc-f- doc-f* doc-f/ doc-fnegate doc-fabs doc-fmax doc-fmin doc-floor doc-fround doc-f** doc-fsqrt doc-fexp doc-fexpm1 doc-fln doc-flnp1 doc-flog doc-falog doc-f2* doc-f2/ doc-1/f doc-precision doc-set-precision

Angles in floating point operations are given in radians (a full circle has 2 pi radians).

doc-fsin doc-fcos doc-fsincos doc-ftan doc-fasin doc-facos doc-fatan doc-fatan2 doc-fsinh doc-fcosh doc-ftanh doc-fasinh doc-facosh doc-fatanh doc-pi

One particular problem with floating-point arithmetic is that comparison for equality often fails when you would expect it to succeed. For this reason approximate equality is often preferred (but you still have to know what you are doing). Also note that IEEE NaNs may compare differently from what you might expect. The comparison words are:

doc-f~rel doc-f~abs doc-f~ doc-f= doc-f<>

doc-f< doc-f<= doc-f> doc-f>=

doc-f0< doc-f0<= doc-f0<> doc-f0= doc-f0> doc-f0>=

 webmaster delorie software   privacy Copyright © 2003   by The Free Software Foundation Updated Jun 2003