<< Home | About Forth | About TurboForth | Download | Language Reference | Resources | Tutorials | YouTube >>
In Programming and Stack Management Words in 32-bit library
Converts a signed single value on the stack to a signed double value, by adding a 0 in the high order cell (for positive values) or a -1 for negative values.
21499 S>D .S (displays 21499 0)
-21499 S>D .S (displays -24199 -1)
21499 S>D .S
-21499 S>D .S
This can be confirmed with D. as follows:
24199 S>D D. (displays 24199)
-24199 S>D D. (displays -24199)
24199 S>D D.
-24199 S>D D.
Note: Unsigned single values can be converted to a double simply by pushing a 0 on top of the value. For example, to convert the number 41999 to an unsigned-double:
41999 0 D. (displays 41999)
41999 0 D.
For clarity, this could be added as a colon definition:
: US>UD ( us – ud) 0 ;
Here “US>UD” means “unsigned-single to unsigned-double”. The stack signature shows an unsigned-single value on the top of the stack before conversion, and an unsigned-double value after the conversion.