From 9d9ec9a6d06279e172dcb27f2cf12270ad69a100 Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Tue, 2 Jan 2024 00:24:22 +0800 Subject: [PATCH] add `__neg__` for complex --- python/cmath.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/python/cmath.py b/python/cmath.py index bb2dec50..81029bbc 100644 --- a/python/cmath.py +++ b/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))