7

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131

1 Answers1

6

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.

fvu
  • 32,488
  • 6
  • 61
  • 79
  • 1
    That didn't quite work so I tried 1 s>f 2.1e f+ and got the correct answer. Thanks! – user1981802 Jan 15 '13 at 22:36
  • @user1981802 sorry for the confusion, looks like my Forth knowledge is getting quite rusty. I changed by answer to mention both s>f and d>f – fvu Jan 15 '13 at 22:57