(v, prec, options)
This function handles sin and cos of complex arguments.

    TODO: should also handle tan of complex arguments.
This function handles sin and cos of complex arguments.
This function handles sin and cos of complex arguments .
def evalf_trig(v, prec, options):
    """
    This function handles sin and cos of complex arguments.

    TODO: should also handle tan of complex arguments.
    """
    if v.func is C.cos:
        func = mpf_cos
    elif v.func is C.sin:
        func = mpf_sin
    else:
        raise NotImplementedError
    arg = v.args[0]
    # 20 extra bits is possibly overkill. It does make the need
    # to restart very unlikely
    xprec = prec + 20
    re, im, re_acc, im_acc = evalf(arg, xprec, options)
    if im:
        if 'subs' in options:
            v = v.subs(options['subs'])
        return evalf(v._eval_evalf(prec), prec, options)
    if not re:
        if v.func is C.cos:
            return fone, None, prec, None
        elif v.func is C.sin:
            return None, None, None, None
        else:
            raise NotImplementedError
    # For trigonometric functions, we are interested in the
    # fixed-point (absolute) accuracy of the argument.
    xsize = fastlog(re)
    # Magnitude <= 1.0. OK to compute directly, because there is no
    # danger of hitting the first root of cos (with sin, magnitude
    # <= 2.0 would actually be ok)
    if xsize < 1:
        return func(re, prec, rnd), None, prec, None
    # Very large
    if xsize >= 10:
        xprec = prec + xsize
        re, im, re_acc, im_acc = evalf(arg, xprec, options)
    # Need to repeat in case the argument is very close to a
    # multiple of pi (or pi/2), hitting close to a root
    while 1:
        y = func(re, prec, rnd)
        ysize = fastlog(y)
        gap = -ysize
        accuracy = (xprec - xsize) - gap
        if accuracy < prec:
            if options.get('verbose'):
                print("SIN/COS", accuracy, "wanted", prec, "gap", gap)
                print(to_str(y, 10))
            if xprec > options.get('maxprec', DEFAULT_MAXPREC):
                return y, None, accuracy, None
            xprec += gap
            re, im, re_acc, im_acc = evalf(arg, xprec, options)
            continue
        else:
            return y, None, prec, None
def evalf_trig ( v , prec , options ) : if v . func is C . cos : func = mpf_cos elif v . func is C . sin : func = mpf_sin else : raise NotImplementedError arg = v . args [ 0 ] # 20 extra bits is possibly overkill. It does make the need # to restart very unlikely xprec = prec + 20 re , im , re_acc , im_acc = evalf ( arg , xprec , options ) if im : if 'subs' in options : v = v . subs ( options [ 'subs' ] ) return evalf ( v . _eval_evalf ( prec ) , prec , options ) if not re : if v . func is C . cos : return fone , None , prec , None elif v . func is C . sin : return None , None , None , None else : raise NotImplementedError # For trigonometric functions, we are interested in the # fixed-point (absolute) accuracy of the argument. xsize = fastlog ( re ) # Magnitude <= 1.0. OK to compute directly, because there is no # danger of hitting the first root of cos (with sin, magnitude # <= 2.0 would actually be ok) if xsize < 1 : return func ( re , prec , rnd ) , None , prec , None # Very large if xsize >= 10 : xprec = prec + xsize re , im , re_acc , im_acc = evalf ( arg , xprec , options ) # Need to repeat in case the argument is very close to a # multiple of pi (or pi/2), hitting close to a root while 1 : y = func ( re , prec , rnd ) ysize = fastlog ( y ) gap = - ysize accuracy = ( xprec - xsize ) - gap if accuracy < prec : if options . get ( 'verbose' ) : print ( "SIN/COS" , accuracy , "wanted" , prec , "gap" , gap ) print ( to_str ( y , 10 ) ) if xprec > options . get ( 'maxprec' , DEFAULT_MAXPREC ) : return y , None , accuracy , None xprec += gap re , im , re_acc , im_acc = evalf ( arg , xprec , options ) continue else : return y , None , prec , None