[pypy-commit] lang-js default: added more math builtins
stepahn
noreply at buildbot.pypy.org
Fri Dec 28 11:32:58 CET 2012
Author: Stephan <stephan at stzal.com>
Branch:
Changeset: r160:1fcb3fe472d9
Date: 2011-12-21 13:05 +0100
http://bitbucket.org/pypy/lang-js/changeset/1fcb3fe472d9/
Log: added more math builtins
diff --git a/js/builtins.py b/js/builtins.py
--- a/js/builtins.py
+++ b/js/builtins.py
@@ -817,27 +817,39 @@
import js.builtins_math as math_builtins
put_native_function(w_Math, 'abs', math_builtins.abs)
put_native_function(w_Math, 'floor', math_builtins.floor)
+ put_native_function(w_Math, 'round', math_builtins.round)
put_native_function(w_Math, 'random', math_builtins.random)
put_native_function(w_Math, 'min', math_builtins.min)
put_native_function(w_Math, 'max', math_builtins.max)
+ put_native_function(w_Math, 'pow', math_builtins.pow)
+ put_native_function(w_Math, 'sqrt', math_builtins.sqrt)
+ put_native_function(w_Math, 'log', math_builtins.log)
- #w_math.Put('round', W_Builtin(roundjs, Class='function'))
- #w_math.Put('pow', W_Builtin(powjs, Class='function'))
- #w_math.Put('sqrt', W_Builtin(sqrtjs, Class='function'))
- #w_math.Put('log', W_Builtin(logjs, Class='function'))
- #w_math.Put('E', W_FloatNumber(math.e), flags=allon)
- #w_math.Put('LN2', W_FloatNumber(math.log(2)), flags=allon)
- #w_math.Put('LN10', W_FloatNumber(math.log(10)), flags=allon)
- #log2e = math.log(math.e) / math.log(2) # rpython supports log with one argument only
- #w_math.Put('LOG2E', W_FloatNumber(log2e), flags=allon)
- #w_math.Put('LOG10E', W_FloatNumber(math.log10(math.e)), flags=allon)
- #w_math.Put('PI', W_FloatNumber(math.pi), flags=allon)
- #w_math.Put('SQRT1_2', W_FloatNumber(math.sqrt(0.5)), flags=allon)
- #w_math.Put('SQRT2', W_FloatNumber(math.sqrt(2)), flags=allon)
- #w_math.Put('random', W_Builtin(randomjs, Class='function'))
- #w_math.Put('min', W_Builtin(minjs, Class='function'))
- #w_math.Put('max', W_Builtin(maxjs, Class='function'))
- #w_Global.Put('version', W_Builtin(versionjs), flags=allon)
+ # 15.8.1
+
+ # 15.8.1.1
+ w_Math.Put('E', _w(math_builtins.E), flags = allon)
+
+ # 15.8.1.2
+ w_Math.Put('LN10', _w(math_builtins.LN10), flags = allon)
+
+ # 15.8.1.3
+ w_Math.Put('LN2', _w(math_builtins.LN2), flags = allon)
+
+ # 15.8.1.4
+ w_Math.Put('LOG2E', _w(math_builtins.LOG2E), flags = allon)
+
+ # 15.8.1.5
+ w_Math.Put('LOG10E', _w(math_builtins.LOG10E), flags = allon)
+
+ # 15.8.1.6
+ w_Math.Put('PI', _w(math_builtins.PI), flags = allon)
+
+ # 15.8.1.7
+ w_Math.Put('SQRT1_2', _w(math_builtins.SQRT1_2), flags = allon)
+
+ # 15.8.1.8
+ w_Math.Put('SQRT2', _w(math_builtins.SQRT2), flags = allon)
##Date
#w_Date = W_DateObject('Date', w_FncPrototype)
diff --git a/js/builtins_math.py b/js/builtins_math.py
--- a/js/builtins_math.py
+++ b/js/builtins_math.py
@@ -3,6 +3,7 @@
from pypy.rlib.rfloat import NAN, INFINITY, isnan, isinf
+# 15.8.2.9
def floor(this, *args):
if len(args) < 1:
return NAN
@@ -15,6 +16,7 @@
return pos
+# 15.8.2.1
def abs(this, *args):
val = args[0]
if isinstance(val, W_IntNumber):
@@ -23,24 +25,30 @@
return -val.ToInteger()
return abs(args[0].ToNumber())
-def rounds(args, this):
- return floorjs(args, this)
+# 15.8.2.15
+def round(this, *args):
+ return floor(this, args)
-def pow(args, this):
+# 15.8.2.13
+def pow(this, *args):
return math.pow(args[0].ToNumber(), args[1].ToNumber())
-def sqrt(args, this):
+# 15.8.2.17
+def sqrt(this, *args):
return math.sqrt(args[0].ToNumber())
-def log(args, this):
+# 15.8.2.10
+def log(this, *args):
return math.log(args[0].ToNumber())
+# 15.8.2.11
py_min = min
def min(this, *args):
a = args[0].ToNumber()
b = args[1].ToNumber()
return py_min(a, b)
+# 15.8.2.12
py_max = max
def max(this, *args):
a = args[0].ToNumber()
@@ -51,6 +59,30 @@
from pypy.rlib import rrandom
_random = rrandom.Random(int(time.time()))
+# 15.8.2.14
+# 15.8.1.1
+E = math.e
+
+# 15.8.1.2
+LN10 = math.log(10)
+
+# 15.8.1.3
+LN2 = math.log(2)
+
+# 15.8.1.4
+LOG2E = math.log(math.e) / math.log(2)
+
+# 15.8.1.5
+LOG10E = math.log10(math.e)
+
+# 15.8.1.6
+PI = math.pi
+
+# 15.8.1.7
+SQRT1_2 = math.sqrt(0.5)
+
+# 15.8.1.8
+SQRT2 = math.sqrt(2)
def random(this, *args):
return _random.random()
More information about the pypy-commit
mailing list