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

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.