diff --git a/pyerrors/pyerrors.py b/pyerrors/pyerrors.py index 555c73d8..5d54b9af 100644 --- a/pyerrors/pyerrors.py +++ b/pyerrors/pyerrors.py @@ -655,6 +655,9 @@ class CObs: if isinstance(self.imag, Obs): self.imag.gamma_method(**kwargs) + def conjugate(self): + return CObs(self.real, -self.imag) + def __add__(self, other): if hasattr(other, 'real') and hasattr(other, 'imag'): return CObs(self.real + other.real, @@ -701,7 +704,7 @@ class CObs: return self.real == other.real and self.imag == other.imag def __str__(self): - return '(' + str(self.real) + int(self.imag > - np.finfo(np.float64).eps) * '+' + str(self.imag) + 'j)' + return '(' + str(self.real) + int(self.imag >= 0.0) * '+' + str(self.imag) + 'j)' def __repr__(self): return 'CObs[' + str(self) + ']' diff --git a/tests/test_pyerrors.py b/tests/test_pyerrors.py index bed06530..58ec21f3 100644 --- a/tests/test_pyerrors.py +++ b/tests/test_pyerrors.py @@ -199,6 +199,10 @@ def test_cobs(): obs2 = pe.pseudo_Obs(-0.2, 0.03, 't') my_cobs = pe.CObs(obs1, obs2) + assert not (my_cobs + my_cobs.conjugate()).real.is_zero() + assert (my_cobs + my_cobs.conjugate()).imag.is_zero() + assert (my_cobs - my_cobs.conjugate()).real.is_zero() + assert not (my_cobs - my_cobs.conjugate()).imag.is_zero() np.abs(my_cobs) fs = [[lambda x: x[0] + x[1], lambda x: x[1] + x[0]], [lambda x: x[0] * x[1], lambda x: x[1] * x[0]]]