1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
From 5b187e8543f44267db5d71b289bca1f3f8de07df Mon Sep 17 00:00:00 2001
From: Abdelnour Osman <64225524+D4rkTT@users.noreply.github.com>
Date: Thu, 28 Dec 2023 17:19:46 +0200
Subject: [PATCH 1/2] Add Math.sign support
---
js2py/constructors/jsmath.py | 3 +++
1 file changed, 3 insertions(+)
diff --git a/js2py/constructors/jsmath.py b/js2py/constructors/jsmath.py
index 06751a3b..856d33ed 100644
--- a/js2py/constructors/jsmath.py
+++ b/js2py/constructors/jsmath.py
@@ -152,6 +152,9 @@ def max():
def random():
return random.random()
+
+ def sign(x):
+ return math.copysign(1, x)
fill_prototype(Math, MathFunctions, default_attrs)
From 4cd0a0015ae8567b2f894ece1a3715a3a314fd6e Mon Sep 17 00:00:00 2001
From: Abdelnour Osman <64225524+D4rkTT@users.noreply.github.com>
Date: Thu, 28 Dec 2023 22:55:57 +0200
Subject: [PATCH 2/2] Update jsmath.py
Added Math.sign Support
---
js2py/constructors/jsmath.py | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/js2py/constructors/jsmath.py b/js2py/constructors/jsmath.py
index 856d33ed..cef5f230 100644
--- a/js2py/constructors/jsmath.py
+++ b/js2py/constructors/jsmath.py
@@ -154,7 +154,10 @@ def random():
return random.random()
def sign(x):
- return math.copysign(1, x)
+ a = x.to_number().value
+ if a != a: # it must be a nan
+ return NaN
+ return math.copysign(1, a)
fill_prototype(Math, MathFunctions, default_attrs)
|