Esempio n. 1
0
from pypy.rpython.ootypesystem.module import ll_math as oo_math
from pypy.rpython.module import ll_os
from pypy.rpython.module import ll_time
try:
    import termios
except ImportError:
    pass
else:
    from pypy.rpython.module import ll_termios

# the following functions all take one float, return one float
# and are part of math.h
for name in ll_math.unary_math_functions:
    llimpl = getattr(ll_math, 'll_math_%s' % name, None)
    register_external(getattr(math, name), [float], float,
                      export_name="ll_math.ll_math_%s" % name,
                       sandboxsafe=True, llimpl=llimpl)

complex_math_functions = [
    ('frexp', [float],        (float, int)),
    ('ldexp', [float, int],   float),
    ('modf',  [float],        (float, float)),
    ] + [(name, [float, float], float) for name in
         ll_math.binary_math_functions]

for name, args, res in complex_math_functions:
    func = getattr(math, name)
    llimpl = getattr(ll_math, 'll_math_%s' % name, None)
    oofake = getattr(oo_math, 'll_math_%s' % name, None)
    register_external(func, args, res, 'll_math.ll_math_%s' % name,
                      llimpl=llimpl, oofakeimpl=oofake,
Esempio n. 2
0
    import termios
except ImportError:
    pass
else:
    from pypy.rpython.module import ll_termios

# the following functions all take one float, return one float
# and are part of math.h
for name in ll_math.unary_math_functions:
    llimpl = getattr(ll_math, 'll_math_%s' % name, None)
    try:
        f = getattr(math, name)
    except AttributeError:
        f = getattr(rfloat, name)
    register_external(f, [float], float,
                      export_name="ll_math.ll_math_%s" % name,
                       sandboxsafe=True, llimpl=llimpl)

register_external(rfloat.isinf, [float], bool,
                  export_name="ll_math.ll_math_isinf", sandboxsafe=True,
                  llimpl=ll_math.ll_math_isinf)
register_external(rfloat.isnan, [float], bool,
                  export_name="ll_math.ll_math_isnan", sandboxsafe=True,
                  llimpl=ll_math.ll_math_isnan)
register_external(rfloat.isfinite, [float], bool,
                  export_name="ll_math.ll_math_isfinite", sandboxsafe=True,
                  llimpl=ll_math.ll_math_isfinite)
register_external(rfloat.copysign, [float, float], float,
                  export_name="ll_math.ll_math_copysign", sandboxsafe=True,
                  llimpl=ll_math.ll_math_copysign)
register_external(math.floor, [float], float,
Esempio n. 3
0
from pypy.rpython.module import ll_time
from pypy.rpython.module import ll_foo
try:
    import termios
except ImportError:
    pass
else:
    from pypy.rpython.module import ll_termios

# the following functions all take one float, return one float
# and are part of math.h
for name in ll_math.unary_math_functions:
    llimpl = getattr(ll_math, 'll_math_%s' % name, None)
    register_external(getattr(math, name), [float],
                      float,
                      export_name="ll_math.ll_math_%s" % name,
                      sandboxsafe=True,
                      llimpl=llimpl)

complex_math_functions = [
    ('frexp', [float], (float, int)),
    ('ldexp', [float, int], float),
    ('modf', [float], (float, float)),
] + [(name, [float, float], float) for name in ll_math.binary_math_functions]

for name, args, res in complex_math_functions:
    func = getattr(math, name)
    llimpl = getattr(ll_math, 'll_math_%s' % name, None)
    oofake = getattr(oo_math, 'll_math_%s' % name, None)
    register_external(func,
                      args,
Esempio n. 4
0
from pypy.rpython.module import ll_os
try:
    import termios
except ImportError:
    pass
else:
    from pypy.rpython.module import ll_termios

# the following functions all take one float, return one float
# and are part of math.h
simple_math_functions = [
    'acos', 'asin', 'atan', 'ceil', 'cos', 'cosh', 'exp', 'fabs',
    'floor', 'log', 'log10', 'sin', 'sinh', 'sqrt', 'tan', 'tanh'
    ]
for name in simple_math_functions:
    register_external(getattr(math, name), [float], float, "ll_math.ll_math_%s" % name)

def frexp_hook():
    from pypy.rpython.extfunctable import record_call
    from pypy.annotation.model import SomeInteger, SomeTuple, SomeFloat
    from pypy.rpython.lltypesystem.module.ll_math import ll_frexp_result
    record_call(ll_frexp_result, (SomeFloat(), SomeInteger()), 'MATH_FREXP')

def modf_hook():
    from pypy.rpython.extfunctable import record_call
    from pypy.annotation.model import SomeTuple, SomeFloat
    from pypy.rpython.lltypesystem.module.ll_math import ll_modf_result
    record_call(ll_modf_result, (SomeFloat(), SomeFloat()), 'MATH_MODF')

complex_math_functions = [
    ('frexp', [float],        (float, int),   frexp_hook),