Question

In Gforth, is there a way to add an integer value to a floating point value?

Something like 1 + 2.1? If I do 1 2.1e f+ I get an error which I'm guessing is because the values are not on the same stack. I know that I could just do 1.0e 2.1e f+, but that's not what I'm trying to figure out how to do.

Was it helpful?

Solution

Gforth has the s>f and d>f words that convert an int (single cell and double cell respectively) to a double - Gforth floating point functions doc is here

1 s>f 2.1e f+

should do the trick in this case.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top