[pypy-svn] r47939 - in pypy/dist/pypy/lang/smalltalk: . test
oscar at codespeak.net
oscar at codespeak.net
Thu Oct 25 16:34:02 CEST 2007
Author: oscar
Date: Thu Oct 25 16:34:02 2007
New Revision: 47939
Modified:
pypy/dist/pypy/lang/smalltalk/primitives.py
pypy/dist/pypy/lang/smalltalk/test/test_primitives.py
Log:
(cfbolz, oscar) added exp and tests
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 16:34:02 2007
@@ -203,6 +203,7 @@
FLOAT_SIN = 56
FLOAT_ARCTAN = 57
FLOAT_LOG_N = 58
+FLOAT_EXP = 59
math_ops = {
FLOAT_ADD: operator.add,
@@ -263,6 +264,14 @@
res = math.log(f)
return objtable.wrap_float(res)
+ at primitive(FLOAT_EXP)
+ at stack(1)
+def func(args, (w_float,)):
+ f = unwrap_float(w_float)
+ w_res = objtable.wrap_float(math.exp(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 16:34:02 2007
@@ -310,3 +310,9 @@
assert float_equals(prim(p.FLOAT_LOG_N, [10.0]), 2.302585092994046)
assert isinf(prim(p.FLOAT_LOG_N, [0.0]).value) # works also for negative infinity
assert isnan(prim(p.FLOAT_LOG_N, [-1.0]).value)
+
+def test_primitive_exp():
+ assert float_equals(prim(p.FLOAT_EXP, [-1.0]), 1/math.e)
+ assert prim(p.FLOAT_EXP, [0]).value == 1
+ assert float_equals(prim(p.FLOAT_EXP, [1]), math.e)
+ assert float_equals(prim(p.FLOAT_EXP, [math.log(10)]), 10)
More information about the Pypy-commit
mailing list