quad.hh
Go to the documentation of this file.
1 // -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 // vi: set et ts=4 sw=4 sts=4:
3 /*
4  Copyright (C) 2011-2013 by Andreas Lauser
5 
6  This file is part of the Open Porous Media project (OPM).
7 
8  OPM is free software: you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation, either version 2 of the License, or
11  (at your option) any later version.
12 
13  OPM is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with OPM. If not, see <http://www.gnu.org/licenses/>.
20 */
27 #ifdef DUNE_CLASSNAME_HH
28 #error "Due to some trickery required for the linker, this file must be included _before_ Dune's classname.hh!"
29 #endif
30 
31 #if !defined EWOMS_QUAD_HH && HAVE_QUAD
32 #define EWOMS_QUAD_HH
33 
34 #include <opm/material/common/ClassName.hpp>
35 
36 #include <cmath>
37 #include <string>
38 #include <limits>
39 #include <iostream>
40 #include <type_traits>
41 
42 extern "C" {
43 #include <quadmath.h>
44 }
45 
46 typedef __float128 quad;
47 
48 namespace std {
49 
50 // provide the numeric limits for the quad precision type
51 template <>
52 class numeric_limits<quad>
53 {
54 public:
55  static const bool is_specialized = true;
56 
57  static quad min() throw()
58  { return FLT128_MIN; }
59  static quad max() throw()
60  { return FLT128_MAX; }
61 
62  // number of bits in mantissa
63  static const int digits = FLT128_MANT_DIG;
64  // number of decimal digits
65  static const int digits10 = FLT128_DIG;
66  static const bool is_signed = true;
67  static const bool is_integer = false;
68  static const bool is_exact = false;
69  static const int radix = 0;
70  static quad epsilon() throw()
71  { return FLT128_EPSILON; }
72  static quad round_error() throw()
73  { return 0.5; }
74 
75  static const int min_exponent = FLT128_MIN_EXP;
76  static const int min_exponent10 = FLT128_MIN_10_EXP;
77  static const int max_exponent = FLT128_MAX_EXP;
78  static const int max_exponent10 = FLT128_MAX_10_EXP;
79 
80  static const bool has_infinity = true;
81  static const bool has_quiet_NaN = true;
82  static const bool has_signaling_NaN = true;
83  static const float_denorm_style has_denorm = denorm_present;
84  static const bool has_denorm_loss = false;
85  static quad infinity() throw()
86  { return __builtin_huge_valq(); }
87  static quad quiet_NaN() throw()
88  { return __builtin_nan(""); }
89  static quad signaling_NaN() throw()
90  { return __builtin_nans(""); }
91  static quad denorm_min() throw()
92  { return FLT128_DENORM_MIN; }
93 
94  static const bool is_iec559 = true;
95  static const bool is_bounded = true;
96  static const bool is_modulo = false;
97 
98  static const bool traps = std::numeric_limits<double>::traps;
99  static const bool tinyness_before = std::numeric_limits<double>::tinyness_before;
100  static const float_round_style round_style = round_to_nearest;
101 };
102 
103 // provide some type traits for the quadruple precision type
104 template <>
105 struct is_floating_point<quad>
106  : public integral_constant<bool, true>
107 {};
108 
109 template <>
110 struct is_arithmetic<quad>
111  : public integral_constant<bool, true>
112 {};
113 
114 template <>
115 struct is_fundamental<quad>
116  : public integral_constant<bool, true>
117 {};
118 
119 template <>
120 struct is_scalar<quad>
121  : public integral_constant<bool, true>
122 {};
123 
124 template <>
125 struct is_pod<quad>
126  : public integral_constant<bool, true>
127 {};
128 
129 template <>
130 struct is_signed<quad>
131  : public integral_constant<bool, true>
132 {};
133 
134 
135 template <>
136 struct is_standard_layout<quad>
137  : public integral_constant<bool, true>
138 {};
139 
140 template <>
141 struct is_trivial<quad>
142  : public integral_constant<bool, true>
143 {};
144 
145 /*
146 template <>
147 struct is_trivially_copyable<quad>
148  : public integral_constant<bool, true>
149 {};
150 */
151 
152 template <class OtherType>
153 struct is_assignable<quad, OtherType>
154  : public integral_constant<bool, is_arithmetic<OtherType>::value>
155 {};
156 
157 template <class OtherType>
158 struct is_nothrow_assignable<quad, OtherType>
159  : public is_assignable<quad, OtherType>
160 {};
161 
162 /*
163 template <class OtherType>
164 struct is_trivially_assignable<quad, OtherType>
165  : public integral_constant<bool, is_arithmetic<OtherType>::value>
166 {};
167 */
168 
169 template <>
170 struct is_copy_assignable<quad>
171  : public integral_constant<bool, true>
172 {};
173 
174 template <>
175 struct is_nothrow_copy_assignable<quad>
176  : public integral_constant<bool, true>
177 {};
178 
179 template <>
180 struct is_move_assignable<quad>
181  : public integral_constant<bool, true>
182 {};
183 
184 template <>
185 struct is_nothrow_move_assignable<quad>
186  : public integral_constant<bool, true>
187 {};
188 
189 template <>
190 struct is_constructible<quad>
191  : public integral_constant<bool, true>
192 {};
193 
194 template <>
195 struct is_nothrow_constructible<quad>
196  : public integral_constant<bool, true>
197 {};
198 
199 template <>
200 struct is_default_constructible<quad>
201  : public integral_constant<bool, true>
202 {};
203 
204 template <>
205 struct is_nothrow_default_constructible<quad>
206  : public integral_constant<bool, true>
207 {};
208 
209 /*
210 template <>
211 struct is_trivially_default_constructible<quad>
212  : public integral_constant<bool, true>
213 {};
214 */
215 
216 template <>
217 struct is_copy_constructible<quad>
218  : public integral_constant<bool, true>
219 {};
220 
221 template <>
222 struct is_move_constructible<quad>
223  : public integral_constant<bool, true>
224 {};
225 
226 template <>
227 struct is_nothrow_move_constructible<quad>
228  : public integral_constant<bool, true>
229 {};
230 
231 
232 template <>
233 struct is_destructible<quad>
234  : public integral_constant<bool, true>
235 {};
236 
237 template <>
238 struct is_nothrow_destructible<quad>
239  : public integral_constant<bool, true>
240 {};
241 
242 template <class OtherType>
243 struct is_convertible<quad, OtherType>
244  : public is_arithmetic<OtherType>
245 { };
246 
247 inline std::ostream &operator<<(std::ostream &os, const quad &val)
248 { return (os << double(val)); }
249 
250 inline std::istream &operator>>(std::istream &is, quad &val)
251 {
252  double tmp;
253  std::istream &ret = (is >> tmp);
254  val = tmp;
255  return ret;
256 }
257 
258 inline quad abs(quad val)
259 { return (val < 0) ? -val : val; }
260 
261 inline quad floor(quad val)
262 { return floorq(val); }
263 
264 inline quad ceil(quad val)
265 { return ceilq(val); }
266 
267 inline quad max(quad a, quad b)
268 { return (a > b) ? a : b; }
269 
270 inline quad min(quad a, quad b)
271 { return (a < b) ? a : b; }
272 
273 inline quad sqrt(quad val)
274 { return sqrtq(val); }
275 
276 template <class ExpType>
277 inline quad pow(quad base, ExpType exp)
278 { return powq(base, exp); }
279 
280 inline quad exp(quad val)
281 { return expq(val); }
282 
283 inline quad log(quad val)
284 { return logq(val); }
285 
286 inline quad sin(quad val)
287 { return sinq(val); }
288 
289 inline quad cos(quad val)
290 { return cosq(val); }
291 
292 inline quad tan(quad val)
293 { return tanq(val); }
294 
295 inline quad atan(quad val)
296 { return atanq(val); }
297 
298 inline quad atan2(quad a, quad b)
299 { return atan2q(a, b); }
300 
301 inline bool isfinite(quad val)
302 { return !isnanq(val) && !isinfq(val); }
303 
304 inline bool isnan(quad val)
305 { return isnanq(val); }
306 
307 inline bool isinf(quad val)
308 { return isinfq(val); }
309 
310 } // namespace std
311 
312 // replace Dune::className by Opm::className since the former does not work
313 // with __float128
314 #define DUNE_CLASSNAME_HH
315 namespace Dune {
316 template <class T>
317 std::string className()
318 { return Opm::className<T>(); }
319 
320 template <class T>
321 std::string className(const T &)
322 { return Opm::className<T>(); }
323 } // namespace Dune
324 
325 #endif // EWOMS_QUAD_HH
Definition: cartesianindexmapper.hh:31
STL namespace.