[pypy-svn] r46931 - in pypy/dist/pypy/translator: . c c/test
arigo at codespeak.net
arigo at codespeak.net
Thu Sep 27 11:17:39 CEST 2007
Author: arigo
Date: Thu Sep 27 11:17:38 2007
New Revision: 46931
Modified:
pypy/dist/pypy/translator/c/primitive.py
pypy/dist/pypy/translator/c/test/test_lltyped.py
pypy/dist/pypy/translator/exceptiontransform.py
Log:
Float support in the exception transformer and C backend.
Modified: pypy/dist/pypy/translator/c/primitive.py
==============================================================================
--- pypy/dist/pypy/translator/c/primitive.py (original)
+++ pypy/dist/pypy/translator/c/primitive.py Thu Sep 27 11:17:38 2007
@@ -97,6 +97,19 @@
else:
return repr(value)
+def name_singlefloat(value, db):
+ value = float(value)
+ if isinf(value):
+ if value > 0:
+ return '((float)Py_HUGE_VAL)'
+ else:
+ return '((float)-Py_HUGE_VAL)'
+ elif isnan(value):
+ # XXX are these expressions ok?
+ return '((float)(Py_HUGE_VAL/Py_HUGE_VAL))'
+ else:
+ return repr(value) + 'f'
+
def name_char(value, db):
assert type(value) is str and len(value) == 1
if ' ' <= value < '\x7f':
@@ -128,6 +141,7 @@
UnsignedLongLong: name_unsignedlonglong,
Unsigned: name_unsigned,
Float: name_float,
+ SingleFloat: name_singlefloat,
Char: name_char,
UniChar: name_unichar,
Bool: name_bool,
@@ -141,6 +155,7 @@
UnsignedLongLong: 'unsigned long long @',
Unsigned: 'unsigned long @',
Float: 'double @',
+ SingleFloat: 'float @',
Char: 'char @',
UniChar: 'unsigned int @',
Bool: 'bool_t @',
@@ -154,6 +169,7 @@
UnsignedLongLong: '((unsigned long long) -1)',
Unsigned: '((unsigned) -1)',
Float: '-1.0',
+ SingleFloat: '-1.0f',
Char: '((char) -1)',
UniChar: '((unsigned) -1)',
Bool: '0 /* error */',
Modified: pypy/dist/pypy/translator/c/test/test_lltyped.py
==============================================================================
--- pypy/dist/pypy/translator/c/test/test_lltyped.py (original)
+++ pypy/dist/pypy/translator/c/test/test_lltyped.py Thu Sep 27 11:17:38 2007
@@ -598,3 +598,24 @@
fn = self.getcompiled(llf)
fn()
+
+ def test_r_singlefloat(self):
+
+ z = r_singlefloat(0.4)
+
+ def g(n):
+ if n > 0:
+ return r_singlefloat(n * 0.1)
+ else:
+ return z
+
+ def llf(n):
+ return float(g(n))
+
+ fn = self.getcompiled(llf, [int])
+ res = fn(21)
+ assert res != 2.1 # precision lost
+ assert abs(res - 2.1) < 1E-6
+ res = fn(-5)
+ assert res != 0.4 # precision lost
+ assert abs(res - 0.4) < 1E-6
Modified: pypy/dist/pypy/translator/exceptiontransform.py
==============================================================================
--- pypy/dist/pypy/translator/exceptiontransform.py (original)
+++ pypy/dist/pypy/translator/exceptiontransform.py Thu Sep 27 11:17:38 2007
@@ -12,6 +12,7 @@
from pypy.rpython import rclass
from pypy.rpython.rmodel import inputconst
from pypy.rlib.rarithmetic import r_uint, r_longlong, r_ulonglong
+from pypy.rlib.rarithmetic import r_singlefloat
from pypy.annotation import model as annmodel
from pypy.rpython.annlowlevel import MixLevelHelperAnnotator
@@ -20,6 +21,7 @@
lltype.SignedLongLong: r_longlong(-1),
lltype.UnsignedLongLong: r_ulonglong(-1),
lltype.Float: -1.0,
+ lltype.SingleFloat: r_singlefloat(-1.0),
lltype.Char: chr(255),
lltype.UniChar: unichr(0xFFFF), # XXX is this always right?
lltype.Bool: True,
More information about the Pypy-commit
mailing list