xref: /petsc/include/petsccxxcomplexfix.h (revision 3982974734951e59c0db36d72a93519e8f3a76a6)
1 #if !defined(PETSCCXXCOMPLEXFIX_H)
2 #define PETSCCXXCOMPLEXFIX_H
3 #if defined(__cplusplus) && defined(PETSC_HAVE_COMPLEX) && defined(PETSC_HAVE_CXX_COMPLEX)
4 
5 #define PETSC_CXX_COMPLEX_FIX(Type) \
6 static inline PetscComplex operator+(const PetscComplex& lhs, const Type& rhs) { return lhs + PetscReal(rhs); } \
7 static inline PetscComplex operator+(const Type& lhs, const PetscComplex& rhs) { return PetscReal(lhs) + rhs; } \
8 static inline PetscComplex operator-(const PetscComplex& lhs, const Type& rhs) { return lhs - PetscReal(rhs); } \
9 static inline PetscComplex operator-(const Type& lhs, const PetscComplex& rhs) { return PetscReal(lhs) - rhs; } \
10 static inline PetscComplex operator*(const PetscComplex& lhs, const Type& rhs) { return lhs * PetscReal(rhs); } \
11 static inline PetscComplex operator*(const Type& lhs, const PetscComplex& rhs) { return PetscReal(lhs) * rhs; } \
12 static inline PetscComplex operator/(const PetscComplex& lhs, const Type& rhs) { return lhs / PetscReal(rhs); } \
13 static inline PetscComplex operator/(const Type& lhs, const PetscComplex& rhs) { return PetscReal(lhs) / rhs; } \
14 static inline bool operator==(const PetscComplex& lhs, const Type& rhs) { return lhs.imag() == PetscReal(0) && lhs.real() == PetscReal(rhs); } \
15 static inline bool operator==(const Type& lhs, const PetscComplex& rhs) { return rhs.imag() == PetscReal(0) && rhs.real() == PetscReal(lhs); } \
16 static inline bool operator!=(const PetscComplex& lhs, const Type& rhs) { return lhs.imag() != PetscReal(0) || lhs.real() != PetscReal(rhs); } \
17 static inline bool operator!=(const Type& lhs, const PetscComplex& rhs) { return rhs.imag() != PetscReal(0) || rhs.real() != PetscReal(lhs); } \
18 /* PETSC_CXX_COMPLEX_FIX */
19 
20 #if defined(PETSC_USE_REAL_SINGLE)
21 PETSC_CXX_COMPLEX_FIX(double)
22 #elif defined(PETSC_USE_REAL_DOUBLE)
23 PETSC_CXX_COMPLEX_FIX(PetscInt)
24 #endif /* PETSC_USE_REAL_* */
25 
26 #endif /* __cplusplus && PETSC_HAVE_COMPLEX && PETSC_HAVE_CXX_COMPLEX */
27 #endif
28