当前位置: 首页>>代码示例>>Python>>正文


Python math.h方法代码示例

本文整理汇总了Python中math.h方法的典型用法代码示例。如果您正苦于以下问题:Python math.h方法的具体用法?Python math.h怎么用?Python math.h使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在math的用法示例。


在下文中一共展示了math.h方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_abs_fallback_expr

# 需要导入模块: import math [as 别名]
# 或者: from math import h [as 别名]
def test_abs_fallback_expr():
    expr = ast.AbsExpr(ast.NumVal(-2.0))

    interpreter = CInterpreter()
    interpreter.abs_function_name = NotImplemented

    expected_code = """
#include <math.h>
double score(double * input) {
    double var0;
    double var1;
    var1 = -2.0;
    if ((var1) < (0)) {
        var0 = (0.0) - (var1);
    } else {
        var0 = var1;
    }
    return var0;
}
"""

    assert_code_equal(interpreter.interpret(expr), expected_code) 
开发者ID:BayesWitnesses,项目名称:m2cgen,代码行数:24,代码来源:test_fallback_expressions.py

示例2: test_extension_object

# 需要导入模块: import math [as 别名]
# 或者: from math import h [as 别名]
def test_extension_object(self):
        ffi = FFI()
        ffi.cdef("double sin(double x);")
        csrc = '/*7%s*/' % self + '''
    #include <math.h>
    #ifndef TEST_EXTENSION_OBJECT
    # error "define_macros missing"
    #endif
    '''
        lib = ffi.verify(csrc, define_macros=[('TEST_EXTENSION_OBJECT', '1')],
                         force_generic_engine=self.generic,
                         libraries=[self.lib_m])
        assert lib.sin(12.3) == math.sin(12.3)
        v = ffi.verifier
        ext = v.get_extension()
        assert 'distutils.extension.Extension' in str(ext.__class__) or \
               'setuptools.extension.Extension' in str(ext.__class__)
        assert ext.sources == [maybe_relative_path(v.sourcefilename)]
        assert ext.name == v.get_module_name()
        assert ext.define_macros == [('TEST_EXTENSION_OBJECT', '1')] 
开发者ID:johncsnyder,项目名称:SwiftKitten,代码行数:22,代码来源:test_zdistutils.py

示例3: test_opaque_integer_as_function_result

# 需要导入模块: import math [as 别名]
# 或者: from math import h [as 别名]
def test_opaque_integer_as_function_result():
    #import platform
    #if platform.machine().startswith('sparc'):
    #    py.test.skip('Breaks horribly on sparc (SIGILL + corrupted stack)')
    #elif platform.machine() == 'mips64' and sys.maxsize > 2**32:
    #    py.test.skip('Segfaults on mips64el')
    # XXX bad abuse of "struct { ...; }".  It only works a bit by chance
    # anyway.  XXX think about something better :-(
    ffi = FFI()
    ffi.cdef("""
        typedef struct { ...; } myhandle_t;
        myhandle_t foo(void);
    """)
    lib = ffi.verify("""
        typedef short myhandle_t;
        myhandle_t foo(void) { return 42; }
    """)
    h = lib.foo()
    assert ffi.sizeof(h) == ffi.sizeof("short") 
开发者ID:johncsnyder,项目名称:SwiftKitten,代码行数:21,代码来源:test_verify.py

示例4: test_take_and_return_partial_structs

# 需要导入模块: import math [as 别名]
# 或者: from math import h [as 别名]
def test_take_and_return_partial_structs():
    ffi = FFI()
    ffi.cdef("""
        typedef struct { int x; ...; } foo_t;
        foo_t foo(foo_t, foo_t);
    """)
    lib = ffi.verify("""
        typedef struct { int y, x; } foo_t;
        foo_t foo(foo_t a, foo_t b) {
            foo_t r = { 100, a.x * 5 + b.x * 7 };
            return r;
        }
    """)
    args = ffi.new("foo_t[3]")
    args[0].x = 1000
    args[2].x = -498
    h = lib.foo(args[0], args[2])
    assert ffi.sizeof(h) == 2 * ffi.sizeof("int")
    assert h.x == 1000 * 5 - 498 * 7 
开发者ID:johncsnyder,项目名称:SwiftKitten,代码行数:21,代码来源:test_verify.py

示例5: test_FILE_stored_explicitly

# 需要导入模块: import math [as 别名]
# 或者: from math import h [as 别名]
def test_FILE_stored_explicitly():
    ffi = FFI()
    ffi.cdef("int myprintf11(const char *, int); FILE *myfile;")
    lib = ffi.verify("""
        #include <stdio.h>
        FILE *myfile;
        int myprintf11(const char *out, int value) {
            return fprintf(myfile, out, value);
        }
    """)
    import os
    fdr, fdw = os.pipe()
    fw1 = os.fdopen(fdw, 'wb', 256)
    lib.myfile = ffi.cast("FILE *", fw1)
    #
    fw1.write(b"X")
    r = lib.myprintf11(b"hello, %d!\n", ffi.cast("int", 42))
    fw1.close()
    assert r == len("hello, 42!\n")
    #
    result = os.read(fdr, 256)
    os.close(fdr)
    # the 'X' might remain in the user-level buffer of 'fw1' and
    # end up showing up after the 'hello, 42!\n'
    assert result == b"Xhello, 42!\n" or result == b"hello, 42!\nX" 
开发者ID:johncsnyder,项目名称:SwiftKitten,代码行数:27,代码来源:test_verify.py

示例6: test_ptr_to_opaque

# 需要导入模块: import math [as 别名]
# 或者: from math import h [as 别名]
def test_ptr_to_opaque():
    ffi = FFI()
    ffi.cdef("typedef ... foo_t; int f1(foo_t*); foo_t *f2(int);")
    lib = ffi.verify("""
        #include <stdlib.h>
        typedef struct { int x; } foo_t;
        int f1(foo_t* p) {
            int x = p->x;
            free(p);
            return x;
        }
        foo_t *f2(int x) {
            foo_t *p = malloc(sizeof(foo_t));
            p->x = x;
            return p;
        }
    """)
    p = lib.f2(42)
    x = lib.f1(p)
    assert x == 42 
开发者ID:johncsnyder,项目名称:SwiftKitten,代码行数:22,代码来源:test_verify.py

示例7: test_implicit_unicode_on_windows

# 需要导入模块: import math [as 别名]
# 或者: from math import h [as 别名]
def test_implicit_unicode_on_windows():
    if sys.platform != 'win32':
        py.test.skip("win32-only test")
    ffi = FFI()
    e = py.test.raises(FFIError, ffi.cdef, "int foo(LPTSTR);")
    assert str(e.value) == ("The Windows type 'LPTSTR' is only available after"
                            " you call ffi.set_unicode()")
    for with_unicode in [True, False]:
        ffi = FFI()
        ffi.set_unicode(with_unicode)
        ffi.cdef("""
            DWORD GetModuleFileName(HMODULE hModule, LPTSTR lpFilename,
                                    DWORD nSize);
        """)
        lib = ffi.verify("""
            #include <windows.h>
        """, libraries=['Kernel32'])
        outbuf = ffi.new("TCHAR[]", 200)
        n = lib.GetModuleFileName(ffi.NULL, outbuf, 500)
        assert 0 < n < 500
        for i in range(n):
            #print repr(outbuf[i])
            assert ord(outbuf[i]) != 0
        assert ord(outbuf[n]) == 0
        assert ord(outbuf[0]) < 128     # should be a letter, or '\' 
开发者ID:johncsnyder,项目名称:SwiftKitten,代码行数:27,代码来源:test_verify.py

示例8: test_errno_working_even_with_pypys_jit

# 需要导入模块: import math [as 别名]
# 或者: from math import h [as 别名]
def test_errno_working_even_with_pypys_jit():
    ffi = FFI()
    ffi.cdef("int f(int);")
    lib = ffi.verify("""
        #include <errno.h>
        int f(int x) { return (errno = errno + x); }
    """)
    @_run_in_multiple_threads
    def test1():
        ffi.errno = 0
        for i in range(10000):
            e = lib.f(1)
            assert e == i + 1
            assert ffi.errno == e
        for i in range(10000):
            ffi.errno = i
            e = lib.f(42)
            assert e == i + 42 
开发者ID:johncsnyder,项目名称:SwiftKitten,代码行数:20,代码来源:test_verify1.py

示例9: test_unicode_libraries

# 需要导入模块: import math [as 别名]
# 或者: from math import h [as 别名]
def test_unicode_libraries():
    try:
        unicode
    except NameError:
        py.test.skip("for python 2.x")
    #
    import math
    lib_m = "m"
    if sys.platform == 'win32':
        #there is a small chance this fails on Mingw via environ $CC
        import distutils.ccompiler
        if distutils.ccompiler.get_default_compiler() == 'msvc':
            lib_m = 'msvcrt'
    ffi = FFI()
    ffi.cdef(unicode("float sin(double); double cos(double);"))
    lib = verify(ffi, 'test_math_sin_unicode', unicode('#include <math.h>'),
                 libraries=[unicode(lib_m)])
    assert lib.cos(1.43) == math.cos(1.43) 
开发者ID:johncsnyder,项目名称:SwiftKitten,代码行数:20,代码来源:test_recompiler.py

示例10: setUp

# 需要导入模块: import math [as 别名]
# 或者: from math import h [as 别名]
def setUp(self):
        """NOTE this is called once for each test* method
        (it is not called once per class).
        FIXME This is slightly inefficient as it is called *way* more times than it needs to be.
        """
        header_str = """
#include <math.h>
#define sin_plus_y(x,y) (sin(x) + (y))
"""
        if sys.platform == "win32":
            # pick something from %windir%\system32\msvc*dll that include stdlib
            libraries = ["msvcrt.dll"]
            libraries = ["msvcrt"]
        elif sys.platform.startswith("linux"):
            libraries = ["libm.so.6"]
        else:
            libraries = ["libc"]
        self.module, output = ctypesgentest.test(header_str, libraries=libraries, all_headers=True) 
开发者ID:davidjamesca,项目名称:ctypesgen,代码行数:20,代码来源:testsuite.py

示例11: c_headers

# 需要导入模块: import math [as 别名]
# 或者: from math import h [as 别名]
def c_headers(self, c_compiler):
        l = ['<math.h>']
        # These includes are needed by Scalar and TensorType,
        # we declare them here and they will be re-used by TensorType
        l.append('<numpy/arrayobject.h>')
        l.append('<numpy/arrayscalars.h>')
        if config.lib.amdlibm and c_compiler.supports_amdlibm:
            l += ['<amdlibm.h>']
        return l 
开发者ID:muhanzhang,项目名称:D-VAE,代码行数:11,代码来源:basic.py

示例12: test_write_source

# 需要导入模块: import math [as 别名]
# 或者: from math import h [as 别名]
def test_write_source(self):
        ffi = FFI()
        ffi.cdef("double sin(double x);")
        csrc = '/*hi there %s!*/\n#include <math.h>\n' % self
        v = Verifier(ffi, csrc, force_generic_engine=self.generic,
                     libraries=[self.lib_m])
        v.write_source()
        with open(v.sourcefilename, 'r') as f:
            data = f.read()
        assert csrc in data 
开发者ID:johncsnyder,项目名称:SwiftKitten,代码行数:12,代码来源:test_zdistutils.py

示例13: test_write_source_explicit_filename

# 需要导入模块: import math [as 别名]
# 或者: from math import h [as 别名]
def test_write_source_explicit_filename(self):
        ffi = FFI()
        ffi.cdef("double sin(double x);")
        csrc = '/*hi there %s!*/\n#include <math.h>\n' % self
        v = Verifier(ffi, csrc, force_generic_engine=self.generic,
                     libraries=[self.lib_m])
        v.sourcefilename = filename = str(udir.join('write_source.c'))
        v.write_source()
        assert filename == v.sourcefilename
        with open(filename, 'r') as f:
            data = f.read()
        assert csrc in data 
开发者ID:johncsnyder,项目名称:SwiftKitten,代码行数:14,代码来源:test_zdistutils.py

示例14: test_write_source_to_file_obj

# 需要导入模块: import math [as 别名]
# 或者: from math import h [as 别名]
def test_write_source_to_file_obj(self):
        ffi = FFI()
        ffi.cdef("double sin(double x);")
        csrc = '/*hi there %s!*/\n#include <math.h>\n' % self
        v = Verifier(ffi, csrc, force_generic_engine=self.generic,
                     libraries=[self.lib_m])
        try:
            from StringIO import StringIO
        except ImportError:
            from io import StringIO
        f = StringIO()
        v.write_source(file=f)
        assert csrc in f.getvalue() 
开发者ID:johncsnyder,项目名称:SwiftKitten,代码行数:15,代码来源:test_zdistutils.py

示例15: test_compile_module

# 需要导入模块: import math [as 别名]
# 或者: from math import h [as 别名]
def test_compile_module(self):
        ffi = FFI()
        ffi.cdef("double sin(double x);")
        csrc = '/*hi there %s!*/\n#include <math.h>\n' % self
        v = Verifier(ffi, csrc, force_generic_engine=self.generic,
                     libraries=[self.lib_m])
        v.compile_module()
        assert v.get_module_name().startswith('_cffi_')
        if v.generates_python_module():
            mod = imp.load_dynamic(v.get_module_name(), v.modulefilename)
            assert hasattr(mod, '_cffi_setup') 
开发者ID:johncsnyder,项目名称:SwiftKitten,代码行数:13,代码来源:test_zdistutils.py


注:本文中的math.h方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。