1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 2 /* */ 3 /* This file is part of the class library */ 4 /* SoPlex --- the Sequential object-oriented simPlex. */ 5 /* */ 6 /* Copyright (c) 1996-2023 Zuse Institute Berlin (ZIB) */ 7 /* */ 8 /* Licensed under the Apache License, Version 2.0 (the "License"); */ 9 /* you may not use this file except in compliance with the License. */ 10 /* You may obtain a copy of the License at */ 11 /* */ 12 /* http://www.apache.org/licenses/LICENSE-2.0 */ 13 /* */ 14 /* Unless required by applicable law or agreed to in writing, software */ 15 /* distributed under the License is distributed on an "AS IS" BASIS, */ 16 /* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */ 17 /* See the License for the specific language governing permissions and */ 18 /* limitations under the License. */ 19 /* */ 20 /* You should have received a copy of the Apache-2.0 license */ 21 /* along with SoPlex; see the file LICENSE. If not email to soplex@zib.de. */ 22 /* */ 23 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 24 25 /**@file spxdefines.hpp 26 * @brief General templated functions for SoPlex 27 */ 28 29 // Defining the static members of the Param class 30 31 namespace soplex 32 { 33 34 /// returns \c true iff |a-b| <= eps 35 template <class R, class S, class T> 36 inline bool EQ(R a, S b, T eps) 37 { 38 return spxAbs(R(a - b)) <= eps; 39 } 40 41 /// returns \c true iff |a-b| > eps 42 template <class R, class S, class T> 43 inline bool NE(R a, S b, T eps) 44 { 45 return spxAbs(a - b) > eps; 46 } 47 48 /// returns \c true iff a < b + eps 49 template <class R, class S, class T> 50 inline bool LT(R a, S b, T eps) 51 { 52 return (a - b) < -eps; 53 } 54 55 /// returns \c true iff a <= b + eps 56 template <class R, class S, class T> 57 inline bool LE(R a, S b, T eps) 58 { 59 return (a - b) < eps; 60 } 61 62 /// returns \c true iff a > b + eps 63 template <class R, class S, class T> 64 inline bool GT(R a, S b, T eps) 65 { 66 return (a - b) > eps; 67 } 68 69 /// returns \c true iff a >= b + eps 70 template <class R, class S, class T> 71 inline bool GE(R a, S b, T eps) 72 { 73 return (a - b) > -eps; 74 } 75 76 /// returns \c true iff |a| <= eps 77 template <class R, class T> 78 inline bool isZero(R a, T eps) 79 { 80 return spxAbs(a) <= eps; 81 } 82 83 /// returns \c true iff |a| > eps 84 template <class R, class T> 85 inline bool isNotZero(R a, T eps) 86 { 87 return spxAbs(a) > eps; 88 } 89 90 /// returns \c true iff |relDiff(a,b)| <= eps 91 template <class R, class S, class T> 92 inline bool EQrel(R a, S b, T eps) 93 { 94 return spxAbs(relDiff(a, b)) <= eps; 95 } 96 97 /// returns \c true iff |relDiff(a,b)| > eps 98 template <class R, class S, class T> 99 inline bool NErel(R a, S b, T eps) 100 { 101 return spxAbs(relDiff(a, b)) > eps; 102 } 103 104 /// returns \c true iff relDiff(a,b) <= -eps 105 template <class R, class S, class T> 106 inline bool LTrel(R a, S b, T eps) 107 { 108 return relDiff(a, b) <= -eps; 109 } 110 111 /// returns \c true iff relDiff(a,b) <= eps 112 template <class R, class S, class T> 113 inline bool LErel(R a, S b, T eps) 114 { 115 return relDiff(a, b) <= eps; 116 } 117 118 /// returns \c true iff relDiff(a,b) > eps 119 template <class R, class S, class T> 120 inline bool GTrel(R a, S b, T eps) 121 { 122 return relDiff(a, b) > eps; 123 } 124 125 /// returns \c true iff relDiff(a,b) > -eps 126 template <class R, class S, class T> 127 inline bool GErel(R a, S b, T eps) 128 { 129 return relDiff(a, b) > -eps; 130 } 131 132 // Instantiation for Real 133 inline Real spxLdexp(Real x, int exp) 134 { 135 return std::ldexp(x, exp); 136 } 137 138 inline Real spxFrexp(Real x, int* exp) 139 { 140 return std::frexp(x, exp); 141 } 142 143 } // namespace soplex 144