Home > Articles > Programming

This chapter is from the book

This chapter is from the book

2–4 Absolute Value Function

If your machine does not have an instruction for computing the absolute value, this computation can usually be done in three or four branch-free instructions. First, compute 018equ04.jpg, and then one of the following:

018equ02.jpg

By “2x” we mean, of course, x + x or x << 1.

If you have fast multiplication by a variable whose value is ±1, the following will do:

018equ03.jpg
  • + Share This
  • 🔖 Save To Your Account