Reputation: 2190
I'm fairly confused about how the s>d
and d>s
functions work in Forth.
From what I've read, typing 16.0
will put 160 0
on the stack (since it takes up two cells) and d.
will show 160
.
Now, if I enter 16 s>d
I would expect the stack to be 160 0
and d.
to show 160
like in the previous example. However, the stack is 16 0
and d.
is 16
.
Am I entering doubles incorrectly? Is s>d
not as simple as "convert a single celled value into a double celled value? Is there any reason for this irregularity? Any clues would be much appreciated.
Upvotes: 0
Views: 101
Reputation: 14325
Gforth interpets all of these the same: 1.60
, 16.0
, and 160.
, i.e. 160 converted to a double number. Whereas 16 s>d
converts 16 to a double number.
ANS Forth only mandates that when the text interpreter processes a number that is immediately followed by a decimal point and is not found as a definition name, the text interpreter shall convert it to a double-cell number. But Gforth goes beoynd that: http://www.complang.tuwien.ac.at/forth/gforth/Docs-html/Number-Conversion.html#Number-Conversion
Upvotes: 2