فهرست منبع

add `__neg__` for complex

blueloveTH 2 سال پیش
والد
کامیت
9d9ec9a6d0
1فایلهای تغییر یافته به همراه3 افزوده شده و 0 حذف شده
  1. 3 0
      python/cmath.py

+ 3 - 0
python/cmath.py

@@ -69,6 +69,9 @@ class complex:
     
     def __abs__(self) -> float:
         return math.sqrt(self.real ** 2 + self.imag ** 2)
+
+    def __neg__(self):
+        return complex(-self.real, -self.imag)
     
     def __hash__(self):
         return hash((self.real, self.imag))