Armin Rigo avatar Armin Rigo committed 901792f

Improve the test portability.

Comments (0)

Files changed (1)

testing/test_verify.py

 
 def test_longdouble_precision():
     # Test that we don't loose any precision of 'long double' when
-    # passing through Python and CFFI.  This test might be too exact,
-    # checking the results that we get on Intel.
+    # passing through Python and CFFI.
     ffi = FFI()
     ffi.cdef("long double step1(long double x);")
     lib = ffi.verify("""
             return 4*x-x*x;
         }
     """)
-    for cast_to_double in [False, True]:
+    def do(cast_to_double):
         x = 0.9789
-        for i in range(50):
+        for i in range(10000):
             x = lib.step1(x)
             if cast_to_double:
                 x = float(x)
-        if cast_to_double:
-            expected = 3.3061
-        else:
-            expected = 3.2585
-        assert (float(x) - expected) < 0.01
+        return float(x)
+
+    more_precise = do(False)
+    less_precise = do(True)
+    assert abs(more_precise - less_precise) > 0.1
+
+    # Check the particular results on Intel
+    import platform
+    if (platform.machine().startswith('i386') or
+        platform.machine().startswith('x86')):
+        assert abs(more_precise - 0.656769) < 0.001
+        assert abs(less_precise - 3.99091) < 0.001
+    else:
+        py.test.skip("don't know the very exact precision of 'long double'")
 
 
 all_integer_types = ['short', 'int', 'long', 'long long',
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.