[pypy-svn] r47930 - in pypy/dist/pypy/lang/smalltalk: . test
oscar at codespeak.net
oscar at codespeak.net
Thu Oct 25 15:55:25 CEST 2007
Author: oscar
Date: Thu Oct 25 15:55:24 2007
New Revision: 47930
Modified:
pypy/dist/pypy/lang/smalltalk/primitives.py
pypy/dist/pypy/lang/smalltalk/test/test_primitives.py
Log:
(cbolz, oscar) float sin primitive
Modified: pypy/dist/pypy/lang/smalltalk/primitives.py
==============================================================================
--- pypy/dist/pypy/lang/smalltalk/primitives.py (original)
+++ pypy/dist/pypy/lang/smalltalk/primitives.py Thu Oct 25 15:55:24 2007
@@ -200,6 +200,7 @@
FLOAT_DIVIDE = 50
FLOAT_TRUNCATED = 51
FLOAT_SQUARE_ROOT = 55
+FLOAT_SIN = 56
math_ops = {
FLOAT_ADD: operator.add,
@@ -234,6 +235,13 @@
w_res = objtable.wrap_float(math.sqrt(f))
return w_res
+ at primitive(FLOAT_SIN)
+ at stack(1)
+def func(args, (w_float,)):
+ f = unwrap_float(w_float)
+ w_res = objtable.wrap_float(math.sin(f))
+ return w_res
+
# ___________________________________________________________________________
# Subscript and Stream Primitives
Modified: pypy/dist/pypy/lang/smalltalk/test/test_primitives.py
==============================================================================
--- pypy/dist/pypy/lang/smalltalk/test/test_primitives.py (original)
+++ pypy/dist/pypy/lang/smalltalk/test/test_primitives.py Thu Oct 25 15:55:24 2007
@@ -1,4 +1,5 @@
import py
+import math
from pypy.lang.smalltalk.primitives import prim_table, PrimitiveFailedError
from pypy.lang.smalltalk import model, shadow
from pypy.lang.smalltalk import interpreter
@@ -281,7 +282,16 @@
return
ROUNDING_DIGITS = 8
+
+def float_equals(w_f,f):
+ return round(w_f.value,ROUNDING_DIGITS) == round(f,ROUNDING_DIGITS)
+
def test_primitive_square_root():
- assert prim(p.FLOAT_SQUARE_ROOT, [4.0]).value == 2.0
- assert round(prim(p.FLOAT_SQUARE_ROOT, [2.0]).value,ROUNDING_DIGITS) == round(1.414213562373095,ROUNDING_DIGITS)
- prim_fails(p.FLOAT_SQUARE_ROOT, [-2.0])
+ assert prim(p.FLOAT_SQUARE_ROOT, [4.0]).value == 2.0
+ assert float_equals(prim(p.FLOAT_SQUARE_ROOT, [2.0]), 1.414213562373095)
+ prim_fails(p.FLOAT_SQUARE_ROOT, [-2.0])
+
+def test_primitive_sin():
+ assert prim(p.FLOAT_SIN, [0.0]).value == 0.0
+ assert float_equals(prim(p.FLOAT_SIN, [math.pi]), 0.0)
+ assert float_equals(prim(p.FLOAT_SIN, [math.pi/2]), 1.0)
More information about the Pypy-commit
mailing list