Arithmetic functions
Factor handbook » The language » Numbers » Mathematical functions

Prev:Integer functions
Next:Powers and logarithms


Computing additive and multiplicative inverses:
neg ( x -- -x )

recip ( x -- y )


Complex conjugation:
conjugate ( z -- z* )


Tests:
zero? ( x -- ? )

between? ( x min max -- ? )


Control flow:
if-zero ( ..a n quot1: ( ..a -- ..b ) quot2: ( ..a n -- ..b ) -- ..b )

when-zero ( ... n quot: ( ... -- ... x ) -- ... x )

unless-zero ( ... n quot: ( ... n -- ... ) -- ... )


Sign:
sgn ( x -- n )


Rounding:
ceiling ( x -- y )

floor ( x -- y )

truncate ( x -- y )

round ( x -- y )


Inexact comparison:
~ ( x y epsilon -- ? )


Numbers implement the Linear order protocol, therefore operations such as min and max can be used with numbers.