[Master Answer Logo]
Question

How do I build my abs?

Answer

A fast approximation of 2D distance based on an octagonal boundary can be computed as follows. Let dx = | px − qx | (absolute value) and dy = | py − qy | . If dy > dx, approximated distance is . (If dy < dx, swap these values.) The difference from the exact distance is between -6% and +3%; more than 85% of all possible differences are between −3% to +3%.

— Source: Wikipedia (www.wikipedia.org)