Spencer Lam
Spencer Lam

Reputation: 81

Why can't I get a floating point answer in Gforth?

I heard that you just have to put an F in front of the operator and then put a (.) at the end to calculate the floating point number and then display it. But it gave me this answer:

2 3 F/ .       
:8: Floating-point stack underflow
2 3 >>>F/<<< .
Backtrace:

How can I get 0.66666667 ok?

Upvotes: 3

Views: 606

Answers (1)

jwodder
jwodder

Reputation: 57590

You heard wrong. Presumably whoever told you that meant that the period should be at the end of the operands, but that would make them double-precision values (no relation to double floats). You need to put an e at the end of 2 and 3 to make them floats, write f/ to divide them, and write f. to print:

in:  2e 3e f/ f.
out: 0.666666666666667 ok

Upvotes: 7

Related Questions