[pypy-svn] r13877 - in pypy/dist/pypy/rpython: . test
ale at codespeak.net
ale at codespeak.net
Sat Jun 25 18:15:42 CEST 2005
Author: ale
Date: Sat Jun 25 18:15:41 2005
New Revision: 13877
Modified:
pypy/dist/pypy/rpython/llinterp.py
pypy/dist/pypy/rpython/rbuiltin.py
pypy/dist/pypy/rpython/test/test_rbuiltin.py
Log:
added support for math.floor and math.fmod
Modified: pypy/dist/pypy/rpython/llinterp.py
==============================================================================
--- pypy/dist/pypy/rpython/llinterp.py (original)
+++ pypy/dist/pypy/rpython/llinterp.py Sat Jun 25 18:15:41 2005
@@ -5,6 +5,7 @@
import py
from pypy.rpython.lltype import _ptr, Ptr, Void, typeOf, malloc, cast_pointer
from pypy.rpython.lltype import Array
+import math
log = py.log.Producer('llinterp')
@@ -272,6 +273,15 @@
assert type(b) is r_uint
return intmask(b)
+ def op_float_floor(self, b):
+ assert type(b) is float
+ return math.floor(b)
+
+ def op_float_fmod(self, b,c):
+ assert type(b) is float
+ assert type(c) is float
+ return math.fmod(b,c)
+
# __________________________________________________________
# primitive operations
from pypy.objspace.flow.operation import FunctionByName
Modified: pypy/dist/pypy/rpython/rbuiltin.py
==============================================================================
--- pypy/dist/pypy/rpython/rbuiltin.py (original)
+++ pypy/dist/pypy/rpython/rbuiltin.py Sat Jun 25 18:15:41 2005
@@ -7,7 +7,7 @@
from pypy.rpython.rmodel import Repr, TyperError, IntegerRepr
from pypy.rpython import rptr
from pypy.rpython.robject import pyobj_repr
-from pypy.rpython.rfloat import float_repr
+from pypy.rpython.rfloat import float_repr, FloatRepr
from pypy.rpython import rclass
@@ -154,6 +154,18 @@
return i1
return i2
+def rtype_math_floor(hop):
+ vlist = hop.inputargs(lltype.Float)
+ return hop.genop('float_floor', vlist, resulttype=lltype.Float)
+
+def rtype_math_fmod(hop):
+ vlist = hop.inputargs(lltype.Float, lltype.Float)
+ return hop.genop('float_fmod', vlist, resulttype=lltype.Float)
+
+import math
+##def ll_floor(f1):
+## return float(int((f1)
+
# collect all functions
import __builtin__
BUILTIN_TYPER = {}
@@ -161,7 +173,8 @@
if name.startswith('rtype_builtin_'):
original = getattr(__builtin__, name[14:])
BUILTIN_TYPER[original] = value
-
+BUILTIN_TYPER[math.floor] = rtype_math_floor
+BUILTIN_TYPER[math.fmod] = rtype_math_fmod
# annotation of low-level types
def rtype_malloc(hop):
Modified: pypy/dist/pypy/rpython/test/test_rbuiltin.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_rbuiltin.py (original)
+++ pypy/dist/pypy/rpython/test/test_rbuiltin.py Sat Jun 25 18:15:41 2005
@@ -40,3 +40,27 @@
assert ev_fun(1, -1) == 1
assert ev_fun(2, 2) == 2
assert ev_fun(-1, -12) == -1
+
+def test_builtin_math_floor():
+ import math
+ def fn(f):
+
+ return math.floor(f)
+ ev_fun = make_interpreter(fn, [0.0])
+ import random
+ for i in range(20):
+ rv = 1000 * float(i-10) #random.random()
+ assert math.floor(rv) == ev_fun(rv)
+
+def test_builtin_math_fmod():
+ import math
+ def fn(f,y):
+
+ return math.fmod(f,y)
+ ev_fun = make_interpreter(fn, [0.0,0.0])
+ for i in range(20):
+ for j in range(20):
+ rv = 1000 * float(i-10)
+ ry = 100 * float(i-10) +0.1
+ assert math.fmod(rv,ry) == ev_fun(rv,ry)
+
\ No newline at end of file
More information about the Pypy-commit
mailing list