2-7 Sign Function

The sign, or signum, function is defined by

graphics/02icon54.gif

 

It may be calculated with four instructions on most machines [Hop]:

graphics/02icon55.gif

 

If you don't have shift right signed, then use the substitute noted at the end of Section 2-6, giving the following nicely symmetric formula (five instructions):

graphics/02icon56.gif

 

Comparison predicate instructions permit a three-instruction solution, with either

Equation 3

graphics/02icon57.gif

 

Finally, we note that the formula graphics/02icon58.gifalmost works; it fails only for x = -231.