This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| 4rpl:commands:asfloat [2022/04/13 09:12] – cross-ref Karsten75 | 4rpl:commands:asfloat [2025/02/14 14:57] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 7: | Line 7: | ||
| ===== Description ===== | ===== Description ===== | ||
| Converts an item on the stack to a floating point number and pushes it back onto the stack. | Converts an item on the stack to a floating point number and pushes it back onto the stack. | ||
| + | |||
| + | This is useful if one needs a floating-point result from operating on two integers. By default, 4RPL may return an integer value after an arithmetic operation on two integers, but a floating-point value might be desirable. | ||
| ===== Examples ===== | ===== Examples ===== | ||
| <code 4rpl> | <code 4rpl> | ||
| " | " | ||
| + | </ | ||
| + | |||
| + | Force (coerce) floating point: | ||
| + | <code 4rpl> | ||
| + | |||
| + | 4 3 div trace # yields 1 | ||
| + | |||
| + | 4 asFloat 3 div trace # yields 1.333.. | ||
| + | |||
| </ | </ | ||