Home > Articles > Programming

This chapter is from the book

This chapter is from the book

2–8 Sign Function

The sign, or signum, function is defined by


It can 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–7, giving the following nicely symmetric formula (five instructions):


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

Finally, we note that the formula 021fig01.jpg almost works; it fails only for x = –231.

  • + Share This
  • 🔖 Save To Your Account