| 1 |
/* ExtendedReal_def.h |
| 2 |
* |
| 3 |
* Copyright (C) 2025 David Weenink |
| 4 |
* |
| 5 |
* This code is free software; you can redistribute it and/or modify |
| 6 |
* it under the terms of the GNU General Public License as published by |
| 7 |
* the Free Software Foundation; either version 3 of the License, or (at |
| 8 |
* your option) any later version. |
| 9 |
* |
| 10 |
* This code is distributed in the hope that it will be useful, but |
| 11 |
* WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 |
* General Public License for more details. |
| 14 |
* |
| 15 |
* You should have received a copy of the GNU General Public License |
| 16 |
* along with this work. If not, see <http://www.gnu.org/licenses/>. |
| 17 |
*/ |
| 18 |
|
| 19 |
/* |
| 20 |
An ExtendedReal has two parts (real,extension) |
| 21 |
The number in the extension part represents: power (epsilon, power (2, extension)), |
| 22 |
where epsilon is a number larger than zero but smaller than any real number r. |
| 23 |
r.epsilon < epsilon^2. |
| 24 |
*/ |
| 25 |
|
| 26 |
#define ooSTRUCT ExtendedReal |
| 27 |
oo_DEFINE_STRUCT (ExtendedReal) |
| 28 |
|
| 29 |
oo_DOUBLE (real) |
| 30 |
oo_INTEGER (extension) |
| 31 |
|
| 32 |
#if oo_DECLARING |
| 33 |
|
| 34 |
constexpr void operator+= (const structExtendedReal& other) { |
| 35 |
real += other.real; |
| 36 |
extension = std::max (extension, other.extension); |
| 37 |
} |
| 38 |
|
| 39 |
constexpr void operator-= (const structExtendedReal& other) { |
| 40 |
this -> real -= other.real; |
| 41 |
this -> extension = this -> extension <= other.extension ? this -> extension : - other.extension; |
| 42 |
} |
| 43 |
|
| 44 |
friend inline bool operator< (const structExtendedReal& lhs, const structExtendedReal& rhs) { |
| 45 |
return std::tie (lhs.real, rhs.extension) < std::tie (rhs.real, lhs.extension); |
| 46 |
} |
| 47 |
|
| 48 |
friend inline bool operator> (const structExtendedReal& lhs, const structExtendedReal& rhs) { |
| 49 |
return rhs < lhs; |
| 50 |
} |
| 51 |
friend inline bool operator<= (const structExtendedReal& lhs, const structExtendedReal& rhs) { |
| 52 |
return ! (lhs > rhs); |
| 53 |
} |
| 54 |
friend inline bool operator>= (const structExtendedReal& lhs, const structExtendedReal& rhs) { |
| 55 |
return ! (lhs < rhs); |
| 56 |
} |
| 57 |
friend inline bool operator== (const structExtendedReal& lhs, const structExtendedReal& rhs) { |
| 58 |
return std::tie (lhs.real, lhs.extension) == std::tie (rhs.real, rhs.extension); |
| 59 |
} |
| 60 |
friend inline bool operator!= (const structExtendedReal& lhs, const structExtendedReal& rhs) { |
| 61 |
return ! (lhs == rhs); |
| 62 |
} |
| 63 |
#endif |
| 64 |
|
| 65 |
oo_END_STRUCT (ExtendedReal) |
| 66 |
#undef ooSTRUCT |
| 67 |
|
| 68 |
/* End of file ExtendedReal_def.h */ |