[pypy-svn] r15413 - in pypy/dist/pypy/translator/c: src test
arigo at codespeak.net
arigo at codespeak.net
Sat Jul 30 14:04:42 CEST 2005
Author: arigo
Date: Sat Jul 30 14:04:40 2005
New Revision: 15413
Modified:
pypy/dist/pypy/translator/c/src/int.h
pypy/dist/pypy/translator/c/test/test_typed.py
Log:
Well, we really need / and % on r_uint.
Modified: pypy/dist/pypy/translator/c/src/int.h
==============================================================================
--- pypy/dist/pypy/translator/c/src/int.h (original)
+++ pypy/dist/pypy/translator/c/src/int.h Sat Jul 30 14:04:40 2005
@@ -105,7 +105,7 @@
/* floor division */
#define OP_INT_FLOORDIV(x,y,r,err) r = op_divmod_adj(x, y, NULL);
-#define OP_UINT_FLOORDIV(x,y,r,err) & Is_Unsigned_Division_Really_Useful;
+#define OP_UINT_FLOORDIV(x,y,r,err) r = (x) / (y);
#define OP_INT_FLOORDIV_OVF(x,y,r,err) \
if ((y) == -1 && (x) < 0 && ((unsigned long)(x) << 1) == 0) \
@@ -115,7 +115,9 @@
#define OP_INT_FLOORDIV_ZER(x,y,r,err) \
if ((y)) { OP_INT_FLOORDIV(x,y,r,err) } \
else FAIL_ZER(err, "integer division")
-#define OP_UINT_FLOORDIV_ZER(x,y,r,err) & Is_Unsigned_Division_Really_Useful;
+#define OP_UINT_FLOORDIV_ZER(x,y,r,err) \
+ if ((y)) { OP_UINT_FLOORDIV(x,y,r,err) } \
+ else FAIL_ZER(err, "unsigned integer division")
#define OP_INT_FLOORDIV_OVF_ZER(x,y,r,err) \
if ((y)) { OP_INT_FLOORDIV_OVF(x,y,r,err) } \
@@ -124,7 +126,7 @@
/* modulus */
#define OP_INT_MOD(x,y,r,err) op_divmod_adj(x, y, &r);
-#define OP_UINT_MOD(x,y,r,err) & Is_Unsigned_Division_Really_Useful;
+#define OP_UINT_MOD(x,y,r,err) r = (x) % (y);
#define OP_INT_MOD_OVF(x,y,r,err) \
if ((y) == -1 && (x) < 0 && ((unsigned long)(x) << 1) == 0) \
@@ -134,7 +136,9 @@
#define OP_INT_MOD_ZER(x,y,r,err) \
if ((y)) { OP_INT_MOD(x,y,r,err) } \
else FAIL_ZER(err, "integer modulo")
-#define OP_UINT_MOD_ZER(x,y,r,err) & Is_Unsigned_Division_Really_Useful;
+#define OP_UINT_MOD_ZER(x,y,r,err) \
+ if ((y)) { OP_UINT_MOD(x,y,r,err) } \
+ else FAIL_ZER(err, "unsigned integer modulo")
#define OP_INT_MOD_OVF_ZER(x,y,r,err) \
if ((y)) { OP_INT_MOD_OVF(x,y,r,err) } \
Modified: pypy/dist/pypy/translator/c/test/test_typed.py
==============================================================================
--- pypy/dist/pypy/translator/c/test/test_typed.py (original)
+++ pypy/dist/pypy/translator/c/test/test_typed.py Sat Jul 30 14:04:40 2005
@@ -4,6 +4,7 @@
from pypy.translator.translator import Translator
from pypy.translator.test import snippet
from pypy.translator.tool.buildpyxmodule import skip_missing_compiler
+from pypy.rpython.rarithmetic import r_uint
from pypy.translator.c.test.test_annotated import TestAnnotatedTestCase as _TestAnnotatedTestCase
@@ -294,3 +295,13 @@
f = self.getcompiled(fn)
assert f(1.0) == fn(1.0)
+ def test_uint_arith(self):
+ def fn(i=r_uint):
+ try:
+ return ~(i*(i+1))/(i-1)
+ except ZeroDivisionError:
+ return r_uint(91872331)
+ f = self.getcompiled(fn)
+ for value in range(15):
+ i = r_uint(value)
+ assert f(i) == fn(i)
More information about the Pypy-commit
mailing list