Skip to content

Latest commit

 

History

History
98 lines (71 loc) · 1.83 KB

dec.md

File metadata and controls

98 lines (71 loc) · 1.83 KB

dec

Fixed-point operations

Index

Operation Description
dec Convert to decimal
rounding.mode/d Sets the default rounding mode
rounding.mode/d? Gets the default rounding mode
trunc Truncate

Operations

dec

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

rounding.mode/d

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

rounding.mode/d?

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

trunc

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