diff --git a/python/_long.py b/python/_long.py index caa6316b..3c28c386 100644 --- a/python/_long.py +++ b/python/_long.py @@ -175,15 +175,15 @@ class long: else: assert type(other) is long if self.sign == other.sign: - return long(ulong_add(self.digits, other.digits), self.sign) + return long((ulong_add(self.digits, other.digits), self.sign)) else: cmp = ulong_cmp(self.digits, other.digits) if cmp == 0: return long(0) if cmp > 0: - return long(ulong_sub(self.digits, other.digits), self.sign) + return long((ulong_sub(self.digits, other.digits), self.sign)) else: - return long(ulong_sub(other.digits, self.digits), other.sign) + return long((ulong_sub(other.digits, self.digits), other.sign)) def __radd__(self, other): return self.__add__(other) @@ -194,15 +194,15 @@ class long: else: assert type(other) is long if self.sign != other.sign: - return long(ulong_add(self.digits, other.digits), self.sign) + return long((ulong_add(self.digits, other.digits), self.sign)) else: cmp = ulong_cmp(self.digits, other.digits) if cmp == 0: return long(0) if cmp > 0: - return long(ulong_sub(self.digits, other.digits), self.sign) + return long((ulong_sub(self.digits, other.digits), self.sign)) else: - return long(ulong_sub(other.digits, self.digits), -other.sign) + return long((ulong_sub(other.digits, self.digits), -other.sign)) def __rsub__(self, other): return self.__sub__(other) @@ -270,7 +270,7 @@ class long: raise NotImplementedError def __neg__(self): - return long(self.digits, -self.sign) + return long((self.digits, -self.sign)) def __cmp__(self, other): if type(other) is int: diff --git a/src/vm.h b/src/vm.h index a61af15b..082f5719 100644 --- a/src/vm.h +++ b/src/vm.h @@ -114,6 +114,7 @@ public: PyObject* None; PyObject* True; PyObject* False; + PyObject* NotImplemented; // unused PyObject* Ellipsis; PyObject* builtins; // builtins module PyObject* StopIteration; @@ -1125,6 +1126,7 @@ inline void VM::init_builtin_types(){ tp_star_wrapper = _new_type_object("_star_wrapper"); this->None = heap._new(_new_type_object("NoneType"), {}); + this->NotImplemented = heap._new(_new_type_object("NotImplementedType"), {}); this->Ellipsis = heap._new(_new_type_object("ellipsis"), {}); this->True = heap._new(tp_bool, {}); this->False = heap._new(tp_bool, {}); diff --git a/tests/09_long.py b/tests/09_long.py new file mode 100644 index 00000000..8d194f65 --- /dev/null +++ b/tests/09_long.py @@ -0,0 +1,12 @@ +assert long(123) == long('123') == 123 + +a = long(2) +assert a ** 0 == 1 +assert a ** 60 == 1152921504606846976 + +assert a + 1 == 3 +assert a - 1 == 1 +assert a * 2 == 4 +assert a // 2 == 1 + +assert -a == -2 \ No newline at end of file