Not sure about the signs of these epsilons. It might also be necessary to clamp the values to guarantee they lie in the acceptable range.