Author: Armin Rigo <[email protected]>
Branch:
Changeset: r1207:e67cd88ae64b
Date: 2013-03-30 16:59 +0100
http://bitbucket.org/cffi/cffi/changeset/e67cd88ae64b/
Log: Fix for PPC: check that "long double" has more precision than
"double" if the type is larger, without assuming that it can hold
bigger values.
diff --git a/c/_cffi_backend.c b/c/_cffi_backend.c
--- a/c/_cffi_backend.c
+++ b/c/_cffi_backend.c
@@ -4785,11 +4785,12 @@
return ptr->a1 + (int)ptr->a2;
}
-static long double _testfunc19(long double x)
+static long double _testfunc19(long double x, int count)
{
int i;
- for (i=0; i<28; i++)
- x += x;
+ for (i=0; i<count; i++) {
+ x = 4*x - x*x;
+ }
return x;
}
diff --git a/c/test_c.py b/c/test_c.py
--- a/c/test_c.py
+++ b/c/test_c.py
@@ -2288,6 +2288,7 @@
def test_longdouble():
py_py = 'PY_DOT_PY' in globals()
+ BInt = new_primitive_type("int")
BLongDouble = new_primitive_type("long double")
BLongDoublePtr = new_pointer_type(BLongDouble)
BLongDoubleArray = new_array_type(BLongDoublePtr, None)
@@ -2305,21 +2306,22 @@
assert float(x) == 1.23
assert int(x) == 1
#
- BFunc19 = new_function_type((BLongDouble,), BLongDouble)
+ BFunc19 = new_function_type((BLongDouble, BInt), BLongDouble)
f = cast(BFunc19, _testfunc(19))
- start = 8
+ start = lstart = 1.5
for i in range(107):
- start = f(start)
+ start = 4 * start - start * start
+ lstart = f(lstart, 1)
+ lother = f(1.5, 107)
+ assert float(lstart) == float(lother)
+ assert repr(lstart) == repr(lother)
if sizeof(BLongDouble) > sizeof(new_primitive_type("double")):
- if not py_py:
- assert repr(start).startswith("<cdata 'long double' 6.15")
- assert repr(start).endswith("E+902>")
- #
- c = newp(BLongDoubleArray, [start])
- x = c[0]
- if not py_py:
- assert repr(x).endswith("E+902>")
- assert float(x) == float("inf")
+ assert float(lstart) != start
+ assert repr(lstart).startswith("<cdata 'long double' ")
+ #
+ c = newp(BLongDoubleArray, [lstart])
+ x = c[0]
+ assert float(f(lstart, 50)) == float(f(x, 50))
def test_get_array_of_length_zero():
for length in [0, 5, 10]:
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit