VirtualFluids 0.2.0
Parallel CFD LBM Solver
Loading...
Searching...
No Matches
UbInfinity.h
Go to the documentation of this file.
1//=======================================================================================
2// ____ ____ __ ______ __________ __ __ __ __
3// \ \ | | | | | _ \ |___ ___| | | | | / \ | |
4// \ \ | | | | | |_) | | | | | | | / \ | |
5// \ \ | | | | | _ / | | | | | | / /\ \ | |
6// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____
7// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______|
8// \ \ | | ________________________________________________________________
9// \ \ | | | ______________________________________________________________|
10// \ \| | | | __ __ __ __ ______ _______
11// \ | | |_____ | | | | | | | | | _ \ / _____)
12// \ | | _____| | | | | | | | | | | \ \ \_______
13// \ | | | | |_____ | \_/ | | | | |_/ / _____ |
14// \ _____| |__| |________| \_______/ |__| |______/ (_______/
15//
16// This file is part of VirtualFluids. VirtualFluids is free software: you can
17// redistribute it and/or modify it under the terms of the GNU General Public
18// License as published by the Free Software Foundation, either version 3 of
19// the License, or (at your option) any later version.
20//
21// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT
22// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
23// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24// for more details.
25//
26// SPDX-License-Identifier: GPL-3.0-or-later
27// SPDX-FileCopyrightText: Copyright © VirtualFluids Project contributors, see AUTHORS.md in root folder
28//
33//=======================================================================================
34#ifndef UB_INFINITY_H
35#define UB_INFINITY_H
36#include <limits>
37
40
48
50{
51public:
52 // name Conversion operators
53 inline operator signed char() const { return UbLimits<signed char>::ninf(); }
54 inline operator char() const { return UbLimits<char>::ninf(); }
55 inline operator wchar_t() const { return UbLimits<wchar_t>::ninf(); }
56 inline operator short() const { return UbLimits<short>::ninf(); }
57 inline operator int() const { return UbLimits<int>::ninf(); }
58 inline operator long() const { return UbLimits<long>::ninf(); }
59 inline operator float() const { return UbLimits<float>::ninf(); }
60 inline operator double() const { return UbLimits<double>::ninf(); }
61 inline operator long double() const { return UbLimits<long double>::ninf(); }
62
66 template <typename T>
67 inline bool equal(const T &rhs) const
68 {
69 UB_STATIC_ASSERT(std::numeric_limits<T>::is_specialized);
70 return UbLimits<T>::ninf() == rhs;
71 }
72
73protected:
74 inline UbNegInfinity() = default;
75
76private:
77 UbNegInfinity(const UbNegInfinity &ninf); // copy constructor (private & undefined)
78 UbNegInfinity &operator=(const UbNegInfinity &ninf); // copy assignment operator (private & undefined)
79 void *operator&() const; // address operator (private & undefined)
80};
81
82//=================================================================================================
83//
84// GLOBAL OPERATORS
85//
86//=================================================================================================
87template <typename T>
88inline bool operator==(const UbNegInfinity &lhs, const T &rhs)
89{
90 return lhs.equal(rhs);
91}
92//*************************************************************************************************
93template <typename T>
94inline bool operator==(const T &lhs, const UbNegInfinity &rhs)
95{
96 return rhs.equal(lhs);
97}
98//*************************************************************************************************
99template <typename T>
100inline bool operator!=(const UbNegInfinity &lhs, const T &rhs)
101{
102 return !lhs.equal(rhs);
103}
104//*************************************************************************************************
105template <typename T>
106inline bool operator!=(const T &lhs, const UbNegInfinity &rhs)
107{
108 return !rhs.equal(lhs);
109}
110
112//
113// UbInfinity
114//
116class UbInfinity : public UbNegInfinity // um spaeter -UbInfinity leichter zu implementieren!!!
117{
118public:
119 inline UbInfinity() : UbNegInfinity() {}
120
121 inline operator unsigned char() const { return UbLimits<unsigned char>::inf(); }
122 inline operator signed char() const { return UbLimits<signed char>::inf(); }
123 inline operator char() const { return UbLimits<char>::inf(); }
124 inline operator wchar_t() const { return UbLimits<wchar_t>::inf(); }
125 inline operator unsigned short() const { return UbLimits<unsigned short>::inf(); }
126 inline operator short() const { return UbLimits<short>::inf(); }
127 inline operator unsigned int() const { return UbLimits<unsigned int>::inf(); }
128 inline operator int() const { return UbLimits<int>::inf(); }
129 inline operator unsigned long() const { return UbLimits<unsigned long>::inf(); }
130 inline operator long() const { return UbLimits<long>::inf(); }
131 inline operator float() const { return UbLimits<float>::inf(); }
132 inline operator double() const { return UbLimits<double>::inf(); }
133 inline operator long double() const { return UbLimits<long double>::inf(); }
134
135 inline const UbNegInfinity &operator-() const { return static_cast<const UbNegInfinity &>(*this); }
136
137 /*==========================================================*/
138 template <typename T>
139 inline bool equal(const T &rhs) const
140 {
141 UB_STATIC_ASSERT(std::numeric_limits<T>::is_specialized);
142 return UbLimits<T>::inf() == rhs;
143 }
144
145private:
146 UbInfinity(const UbInfinity &inf); // Copy constructor (private & undefined)
147 UbInfinity &operator=(const UbInfinity &inf); // Copy assignment operator (private & undefined)
148 void *operator&() const; // Address operator (private & undefined)
149};
150
152// GLOBAL OPERATORS
154template <typename T>
155inline bool operator==(const UbInfinity &lhs, const T &rhs);
156
157template <typename T>
158inline bool operator==(const T &lhs, const UbInfinity &rhs);
159
160template <typename T>
161inline bool operator!=(const UbInfinity &lhs, const T &rhs);
162
163template <typename T>
164inline bool operator!=(const T &lhs, const UbInfinity &rhs);
166//*************************************************************************************************
167
168//*************************************************************************************************
174template <typename T>
175inline bool operator==(const UbInfinity &lhs, const T &rhs)
176{
177 return lhs.equal(rhs);
178}
179//*************************************************************************************************
180template <typename T>
181inline bool operator==(const T &lhs, const UbInfinity &rhs)
182{
183 return rhs.equal(lhs);
184}
185//*************************************************************************************************
186template <typename T>
187inline bool operator!=(const UbInfinity &lhs, const T &rhs)
188{
189 return !lhs.equal(rhs);
190}
191//*************************************************************************************************
192template <typename T>
193inline bool operator!=(const T &lhs, const UbInfinity &rhs)
194{
195 return !rhs.equal(lhs);
196}
197//*************************************************************************************************
198
200// GLOBAL INFINITY VALUE
202namespace ub_math
203{
204// e.g. double x = ub_system::inf; float x = -ub_math::inf;
205const UbInfinity inf;
206} // namespace ub_math
207
208#endif // UB_INFINITY_H
209
const UbNegInfinity & operator-() const
Definition UbInfinity.h:135
bool equal(const T &rhs) const
Definition UbInfinity.h:139
UbNegInfinity.
Definition UbInfinity.h:50
UbNegInfinity()=default
bool equal(const T &rhs) const
Definition UbInfinity.h:67
std::shared_ptr< T > SPtr
#define UB_STATIC_ASSERT(expr)
Definition UbSystem.h:527
bool operator==(const UbNegInfinity &lhs, const T &rhs)
Definition UbInfinity.h:88
bool operator!=(const UbNegInfinity &lhs, const T &rhs)
Definition UbInfinity.h:100