Use fabs instead of abs to calculate Z.