(fn, *args)
Convert to IEEE 754, apply function, convert back.
Convert to IEEE 754, apply function, convert back.
Convert to IEEE 754 apply function convert back .
def _call_float_function(fn, *args):
    """Convert to IEEE 754, apply function, convert back."""
    args = list(args)
    pass_number(args[0])
    values = args[0]._values
    feh = args[0].error_handler
    try:
        # to_float can overflow on Double.pos_max
        args = [_arg.to_float(values.double_math) for _arg in args]
        floatcls = args[0].__class__
        python_args = [_arg.to_value() for _arg in args]
        result = fn(*python_args)
        # python3 may return complex values for some real functions
        # where python2 simply raises an error
        if isinstance(result, complex):
            raise ValueError('Non-real result')
        return floatcls(None, values).from_value(result)
    except (ValueError, ArithmeticError) as e:
        # create positive infinity of the appropriate class
        if values.double_math and isinstance(args[0], numbers.Double):
            floatcls = numbers.Double
        else:
            floatcls = numbers.Single
        infty = floatcls(None, values).from_bytes(floatcls.pos_max)
        # attach as exception payload for float error handler to deal with
        return feh.handle(e.__class__(infty))
def _call_float_function ( fn , * args ) : args = list ( args ) pass_number ( args [ 0 ] ) values = args [ 0 ] . _values feh = args [ 0 ] . error_handler try : # to_float can overflow on Double.pos_max args = [ _arg . to_float ( values . double_math ) for _arg in args ] floatcls = args [ 0 ] . __class__ python_args = [ _arg . to_value ( ) for _arg in args ] result = fn ( * python_args ) # python3 may return complex values for some real functions # where python2 simply raises an error if isinstance ( result , complex ) : raise ValueError ( 'Non-real result' ) return floatcls ( None , values ) . from_value ( result ) except ( ValueError , ArithmeticError ) as e : # create positive infinity of the appropriate class if values . double_math and isinstance ( args [ 0 ] , numbers . Double ) : floatcls = numbers . Double else : floatcls = numbers . Single infty = floatcls ( None , values ) . from_bytes ( floatcls . pos_max ) # attach as exception payload for float error handler to deal with return feh . handle ( e . __class__ ( infty ) )