sgn ( x -- n )
Factor handbook » The language » Numbers » Mathematical functions » Arithmetic functions

Prev:unless-zero ( ... n quot: ( ... n -- ... ) -- ... )
Next:ceiling ( x -- y )


Vocabulary
math

Inputs
xa real


Outputs
n-1, 0 or 1


Word description
Outputs one of the following:
-1 if x is negative
0 if x is equal to 0
1 if x is positive


Definition


: sgn ( x -- n ) dup 0 < [ drop -1 ] [ 0 > 1 0 ? ] if ; inline