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 and then one of the following:


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

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


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

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