Search code examples
conditional-statementsforthgforth

Floating point conditionals in Gforth


Using integers, you can simply make conditional statements like so:

5 4 > . // -1
4 5 > . // 0

variable foo //ok
6 foo ! //ok
foo @ 5 > . // -1

Now is there a simple way to do this with floating point numbers? I have tried this:

4.2 5.4 > . //-1 - Wrong
4.2e 5.4e > . //-1 - Wrong
4.2e 5.4e f> f. //error

Is it possible to do?

EDIT:

To expand this, how can i do this with variables

 fvariable foo 6.2 foo f!
 fvariable boo 8.2 boo f!

 boo @ foo @ f> //How is this done? 

Solution

  • 4.5 in Forth is not a floating point number, but a double integer. You correctly found the e syntax for floats and f> for comparing them. However, the result from f> is a normal integer.

    4.2e 5.4e f> .