1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
|
<center><a href="https://gitlab.com/petsc/petsc/-/blob/966382dc56242773704ef5f5cee7aa2db3ebc577/include/petsccxxcomplexfix.h">Actual source code: petsccxxcomplexfix.h</a></center><br>
<html>
<head>
<title></title>
<meta name="generator" content="c2html 0.9.6">
<meta name="date" content="2025-04-30T18:14:50+00:00">
</head>
<body bgcolor="#FFFFFF">
<pre width=80>
<a name="line1"> 1: </a><font color="#A020F0">#pragma once</font>
<a name="line3"> 3: </a><font color="#B22222">/*</font>
<a name="line4"> 4: </a><font color="#B22222"> The pragma below silence all compiler warnings coming from code in this header file.</font>
<a name="line5"> 5: </a><font color="#B22222"> In particular, it silences `-Wfloat-equal` warnings in `operator==()` and `operator!=` below.</font>
<a name="line6"> 6: </a><font color="#B22222"> Other compilers beyond GCC support this pragma.</font>
<a name="line7"> 7: </a><font color="#B22222">*/</font>
<a name="line8"> 8: </a><font color="#A020F0">#if defined(__GNUC__) && (__GNUC__ >= 4) && !defined(__NEC__)</font>
<a name="line9"> 9: </a><font color="#A020F0"> #pragma GCC system_header</font>
<a name="line10"> 10: </a><font color="#A020F0">#endif</font>
<a name="line12"> 12: </a><font color="#B22222">/*</font>
<a name="line13"> 13: </a><font color="#B22222"> Defines additional operator overloading for the C++ complex class that are "missing" in the standard</font>
<a name="line14"> 14: </a><font color="#B22222"> include files. For example, the code fragment</font>
<a name="line16"> 16: </a><font color="#B22222"> std::complex<double> c = 22.0;</font>
<a name="line17"> 17: </a><font color="#B22222"> c = 11 + c;</font>
<a name="line19"> 19: </a><font color="#B22222"> will produce a compile time error such as</font>
<a name="line21"> 21: </a><font color="#B22222"> error: no match for 'operator+' (operand types are 'int' and 'std::complex<double>')</font>
<a name="line23"> 23: </a><font color="#B22222"> The code fragment</font>
<a name="line25"> 25: </a><font color="#B22222"> std::complex<float> c = 22.0;</font>
<a name="line26"> 26: </a><font color="#B22222"> c = 11.0 + c;</font>
<a name="line28"> 28: </a><font color="#B22222"> will produce a compile time error such as</font>
<a name="line30"> 30: </a><font color="#B22222"> error: no match for 'operator+' (operand types are 'double' and 'std::complex<float>')</font>
<a name="line32"> 32: </a><font color="#B22222"> This deficiency means one may need to write cumbersome code while working with the C++ complex classes.</font>
<a name="line34"> 34: </a><font color="#B22222"> This include file defines a few additional operator overload methods for the C++ complex classes to handle</font>
<a name="line35"> 35: </a><font color="#B22222"> these cases naturally within PETSc code.</font>
<a name="line37"> 37: </a><font color="#B22222"> This file is included in petscsystypes.h when feasible. In the small number of cases where these additional methods</font>
<a name="line38"> 38: </a><font color="#B22222"> may conflict with other code one may add '#define PETSC_SKIP_CXX_COMPLEX_FIX 1' before including any PETSc include</font>
<a name="line39"> 39: </a><font color="#B22222"> files to prevent these methods from being provided.</font>
<a name="line40"> 40: </a><font color="#B22222">*/</font>
<a name="line42"> 42: </a><strong><font color="#228B22">#define PETSC_CXX_COMPLEX_FIX(Type) \</font></strong>
<a name="line43"> 43: </a><strong><font color="#228B22"> static inline <a href="../manualpages/Sys/PetscComplex.html">PetscComplex</a> operator+(const <a href="../manualpages/Sys/PetscComplex.html">PetscComplex</a> &lhs, const Type &rhs) \</font></strong>
<a name="line44"> 44: </a><strong><font color="#228B22"> { \</font></strong>
<a name="line45"> 45: </a><strong><font color="#228B22"> return const_cast<<a href="../manualpages/Sys/PetscComplex.html">PetscComplex</a> &>(lhs) + <a href="../manualpages/Sys/PetscReal.html">PetscReal</a>(rhs); \</font></strong>
<a name="line46"> 46: </a><strong><font color="#228B22"> } \</font></strong>
<a name="line47"> 47: </a><strong><font color="#228B22"> static inline <a href="../manualpages/Sys/PetscComplex.html">PetscComplex</a> operator+(const Type &lhs, const <a href="../manualpages/Sys/PetscComplex.html">PetscComplex</a> &rhs) \</font></strong>
<a name="line48"> 48: </a><strong><font color="#228B22"> { \</font></strong>
<a name="line49"> 49: </a><strong><font color="#228B22"> return <a href="../manualpages/Sys/PetscReal.html">PetscReal</a>(lhs) + const_cast<<a href="../manualpages/Sys/PetscComplex.html">PetscComplex</a> &>(rhs); \</font></strong>
<a name="line50"> 50: </a><strong><font color="#228B22"> } \</font></strong>
<a name="line51"> 51: </a><strong><font color="#228B22"> static inline <a href="../manualpages/Sys/PetscComplex.html">PetscComplex</a> operator-(const <a href="../manualpages/Sys/PetscComplex.html">PetscComplex</a> &lhs, const Type &rhs) \</font></strong>
<a name="line52"> 52: </a><strong><font color="#228B22"> { \</font></strong>
<a name="line53"> 53: </a><strong><font color="#228B22"> return const_cast<<a href="../manualpages/Sys/PetscComplex.html">PetscComplex</a> &>(lhs) - <a href="../manualpages/Sys/PetscReal.html">PetscReal</a>(rhs); \</font></strong>
<a name="line54"> 54: </a><strong><font color="#228B22"> } \</font></strong>
<a name="line55"> 55: </a><strong><font color="#228B22"> static inline <a href="../manualpages/Sys/PetscComplex.html">PetscComplex</a> operator-(const Type &lhs, const <a href="../manualpages/Sys/PetscComplex.html">PetscComplex</a> &rhs) \</font></strong>
<a name="line56"> 56: </a><strong><font color="#228B22"> { \</font></strong>
<a name="line57"> 57: </a><strong><font color="#228B22"> return <a href="../manualpages/Sys/PetscReal.html">PetscReal</a>(lhs) - const_cast<<a href="../manualpages/Sys/PetscComplex.html">PetscComplex</a> &>(rhs); \</font></strong>
<a name="line58"> 58: </a><strong><font color="#228B22"> } \</font></strong>
<a name="line59"> 59: </a><strong><font color="#228B22"> static inline <a href="../manualpages/Sys/PetscComplex.html">PetscComplex</a> operator*(const <a href="../manualpages/Sys/PetscComplex.html">PetscComplex</a> &lhs, const Type &rhs) \</font></strong>
<a name="line60"> 60: </a><strong><font color="#228B22"> { \</font></strong>
<a name="line61"> 61: </a><strong><font color="#228B22"> return const_cast<<a href="../manualpages/Sys/PetscComplex.html">PetscComplex</a> &>(lhs) * <a href="../manualpages/Sys/PetscReal.html">PetscReal</a>(rhs); \</font></strong>
<a name="line62"> 62: </a><strong><font color="#228B22"> } \</font></strong>
<a name="line63"> 63: </a><strong><font color="#228B22"> static inline <a href="../manualpages/Sys/PetscComplex.html">PetscComplex</a> operator*(const Type &lhs, const <a href="../manualpages/Sys/PetscComplex.html">PetscComplex</a> &rhs) \</font></strong>
<a name="line64"> 64: </a><strong><font color="#228B22"> { \</font></strong>
<a name="line65"> 65: </a><strong><font color="#228B22"> return <a href="../manualpages/Sys/PetscReal.html">PetscReal</a>(lhs) * const_cast<<a href="../manualpages/Sys/PetscComplex.html">PetscComplex</a> &>(rhs); \</font></strong>
<a name="line66"> 66: </a><strong><font color="#228B22"> } \</font></strong>
<a name="line67"> 67: </a><strong><font color="#228B22"> static inline <a href="../manualpages/Sys/PetscComplex.html">PetscComplex</a> operator/(const <a href="../manualpages/Sys/PetscComplex.html">PetscComplex</a> &lhs, const Type &rhs) \</font></strong>
<a name="line68"> 68: </a><strong><font color="#228B22"> { \</font></strong>
<a name="line69"> 69: </a><strong><font color="#228B22"> return const_cast<<a href="../manualpages/Sys/PetscComplex.html">PetscComplex</a> &>(lhs) / <a href="../manualpages/Sys/PetscReal.html">PetscReal</a>(rhs); \</font></strong>
<a name="line70"> 70: </a><strong><font color="#228B22"> } \</font></strong>
<a name="line71"> 71: </a><strong><font color="#228B22"> static inline <a href="../manualpages/Sys/PetscComplex.html">PetscComplex</a> operator/(const Type &lhs, const <a href="../manualpages/Sys/PetscComplex.html">PetscComplex</a> &rhs) \</font></strong>
<a name="line72"> 72: </a><strong><font color="#228B22"> { \</font></strong>
<a name="line73"> 73: </a><strong><font color="#228B22"> return <a href="../manualpages/Sys/PetscReal.html">PetscReal</a>(lhs) / const_cast<<a href="../manualpages/Sys/PetscComplex.html">PetscComplex</a> &>(rhs); \</font></strong>
<a name="line74"> 74: </a><strong><font color="#228B22"> } \</font></strong>
<a name="line75"> 75: </a><strong><font color="#228B22"> static inline bool operator==(const <a href="../manualpages/Sys/PetscComplex.html">PetscComplex</a> &lhs, const Type &rhs) \</font></strong>
<a name="line76"> 76: </a><strong><font color="#228B22"> { \</font></strong>
<a name="line77"> 77: </a><strong><font color="#228B22"> return const_cast<<a href="../manualpages/Sys/PetscComplex.html">PetscComplex</a> &>(lhs).imag() == <a href="../manualpages/Sys/PetscReal.html">PetscReal</a>(0) && const_cast<<a href="../manualpages/Sys/PetscComplex.html">PetscComplex</a> &>(lhs).real() == <a href="../manualpages/Sys/PetscReal.html">PetscReal</a>(rhs); \</font></strong>
<a name="line78"> 78: </a><strong><font color="#228B22"> } \</font></strong>
<a name="line79"> 79: </a><strong><font color="#228B22"> static inline bool operator==(const Type &lhs, const <a href="../manualpages/Sys/PetscComplex.html">PetscComplex</a> &rhs) \</font></strong>
<a name="line80"> 80: </a><strong><font color="#228B22"> { \</font></strong>
<a name="line81"> 81: </a><strong><font color="#228B22"> return const_cast<<a href="../manualpages/Sys/PetscComplex.html">PetscComplex</a> &>(rhs).imag() == <a href="../manualpages/Sys/PetscReal.html">PetscReal</a>(0) && const_cast<<a href="../manualpages/Sys/PetscComplex.html">PetscComplex</a> &>(rhs).real() == <a href="../manualpages/Sys/PetscReal.html">PetscReal</a>(lhs); \</font></strong>
<a name="line82"> 82: </a><strong><font color="#228B22"> } \</font></strong>
<a name="line83"> 83: </a><strong><font color="#228B22"> static inline bool operator!=(const <a href="../manualpages/Sys/PetscComplex.html">PetscComplex</a> &lhs, const Type &rhs) \</font></strong>
<a name="line84"> 84: </a><strong><font color="#228B22"> { \</font></strong>
<a name="line85"> 85: </a><strong><font color="#228B22"> return const_cast<<a href="../manualpages/Sys/PetscComplex.html">PetscComplex</a> &>(lhs).imag() != <a href="../manualpages/Sys/PetscReal.html">PetscReal</a>(0) || const_cast<<a href="../manualpages/Sys/PetscComplex.html">PetscComplex</a> &>(lhs).real() != <a href="../manualpages/Sys/PetscReal.html">PetscReal</a>(rhs); \</font></strong>
<a name="line86"> 86: </a><strong><font color="#228B22"> } \</font></strong>
<a name="line87"> 87: </a><strong><font color="#228B22"> static inline bool operator!=(const Type &lhs, const <a href="../manualpages/Sys/PetscComplex.html">PetscComplex</a> &rhs) \</font></strong>
<a name="line88"> 88: </a><strong><font color="#228B22"> { \</font></strong>
<a name="line89"> 89: </a><strong><font color="#228B22"> return const_cast<<a href="../manualpages/Sys/PetscComplex.html">PetscComplex</a> &>(rhs).imag() != <a href="../manualpages/Sys/PetscReal.html">PetscReal</a>(0) || const_cast<<a href="../manualpages/Sys/PetscComplex.html">PetscComplex</a> &>(rhs).real() != <a href="../manualpages/Sys/PetscReal.html">PetscReal</a>(lhs); \</font></strong>
<a name="line90"> 90: </a><strong><font color="#228B22"> } \</font></strong>
<a name="line91"> 91: </a><strong><font color="#228B22"><font color="#B22222">/* PETSC_CXX_COMPLEX_FIX */</font><font color="#228B22"></font></strong>
<a name="line93"> 93: </a><font color="#B22222">/*</font>
<a name="line94"> 94: </a><font color="#B22222"> Due to the C++ automatic promotion rules for floating point and integer values only the two cases below</font>
<a name="line95"> 95: </a><font color="#B22222"> need to be handled.</font>
<a name="line96"> 96: </a><font color="#B22222">*/</font>
<a name="line97"> 97: </a><font color="#A020F0">#if defined(PETSC_USE_REAL_SINGLE)</font>
<a name="line98"> 98: </a><strong><font color="#4169E1"><a name="ETSC_CXX_COMPLEX_FIX"></a>PETSC_CXX_COMPLEX_FIX(double)</font></strong>
<a name="line99"> 99: </a><font color="#A020F0">#elif defined(PETSC_USE_REAL_DOUBLE)</font>
<a name="line100">100: </a><strong><font color="#4169E1"><a name="ETSC_CXX_COMPLEX_FIX"></a>PETSC_CXX_COMPLEX_FIX(<a href="../manualpages/Sys/PetscInt.html">PetscInt</a>)</font></strong>
<a name="line101">101: </a><font color="#A020F0">#endif </font><font color="#B22222">/* PETSC_USE_REAL_* */</font><font color="#A020F0"></font>
</pre>
</body>
</html>
|