2-7. Sign Function

The sign, or signum, function is defined by


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


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):


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

Equation 3


Finally, we note that the formula almost works; it fails only for x = −231.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset