Fixed-point operations
Operation | Description |
---|---|
dec |
Convert to decimal |
rounding.mode/d |
Sets the default rounding mode |
rounding.mode/d? |
Gets the default rounding mode |
trunc |
Truncate |
Converts a number into a decimal value.
Stack effects:
( x:Dec -- Dec )
( x:Rat -- Dec )
Example:
Input | Stack |
---|---|
c 0xff dec |
255 |
c 1/2 dec |
0.5 |
Sets the rounding mode to one of the following:
- ceil
- down
- floor
- half.up
- half.even
- up
If m is not one of the above, a invalid argument error is raised.
Stack effects:
( m:Text -- )
Example:
Input | Stack |
---|---|
rounding.mode/d? |
half.even |
c 5.55 1 round |
5.6 |
/down rounding.mode/d |
rounding mode set to down |
c 5.55 1 round |
5.5 |
Gets the current rounding mode which is one of the following:
- ceil
- down
- floor
- half.up
- half.even
- up
Stack effects:
( -- Text )
Example:
Input | Stack |
---|---|
rounding.mode/d? |
half.even |
Truncates the number x which is the same as rounding to an integer value towards zero.
Stack effects:
( x:Dec -- Dec )
Example:
Input | Stack |
---|---|
c 3.9 trunc |
3 |
c -3.9 trunc |
-3 |