def acos(x, err=defaultError): """ acos(x [,err]) returns arc cosine of x. """ if x > 1 or x < -1: raise ValueError("%s is not in the range [-1, 1]." % str(x)) if x == 0: return pi(err) / 2 if err <= defaultError: rx = rational.Rational(x) y = sqrt(1 - rx**2) if rx > 0: return asin(y, err) else: return pi(err) + asin(-y, err) else: return rational.Rational(math.acos(x))