diff --git a/js2py/constructors/jsmath.py b/js2py/constructors/jsmath.py index 06751a3b..cef5f230 100644 --- a/js2py/constructors/jsmath.py +++ b/js2py/constructors/jsmath.py @@ -152,6 +152,12 @@ def max(): def random(): return random.random() + + def sign(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)