Optimized normalizeAngle function.