def _cos_to_angle(result, deriv, sign=<NUM_LIT:1>):
v = np.arccos(np.clip(result[<NUM_LIT:0>], -<NUM_LIT:1>, <NUM_LIT:1>))<EOL>if deriv == <NUM_LIT:0>:<EOL><INDENT>return v*sign,<EOL><DEDENT>if abs(result[<NUM_LIT:0>]) >= <NUM_LIT:1>:<EOL><INDENT>factor1 = <NUM_LIT:0><EOL><DEDENT>else:<EOL><INDENT>factor1 = -<NUM_LIT:1.0>/np.sqrt(<NUM_LIT:1>-result[<NUM_LIT:0>]**<NUM_LIT:2>)<EOL><DEDENT>d = factor1*result[<NUM_LIT:1>]<EOL>if deriv == <NUM_LIT:1>:<EOL><INDENT>return v*sign, d*sign<EOL><DEDENT>factor2 = result[<NUM_LIT:0>]*factor1**<NUM_LIT:3><EOL>dd = factor2*np.outer(result[<NUM_LIT:1>], result[<NUM_LIT:1>]) + factor1*result[<NUM_LIT:2>]<EOL>if deriv == <NUM_LIT:2>:<EOL><INDENT>return v*sign, d*sign, dd*sign<EOL><DEDENT>raise ValueError("<STR_LIT>")<EOL>
Convert a cosine and its derivatives to an angle and its derivatives