29 #if !defined OPM_COMMON_QUAD_HPP && HAVE_QUAD
30 #define OPM_COMMON_QUAD_HPP
40 #include <type_traits>
46 typedef __float128 quad;
52 class numeric_limits<quad>
55 static constexpr
bool is_specialized =
true;
57 static constexpr quad min() throw()
58 {
return FLT128_MIN; }
59 static constexpr quad max() throw()
60 {
return FLT128_MAX; }
63 static constexpr
int digits = FLT128_MANT_DIG;
65 static constexpr
int digits10 = FLT128_DIG;
66 static constexpr
bool is_signed =
true;
67 static constexpr
bool is_integer =
false;
68 static constexpr
bool is_exact =
false;
69 static constexpr
int radix = 0;
70 static constexpr quad epsilon() throw()
71 {
return FLT128_EPSILON; }
72 static constexpr quad round_error() throw()
75 static constexpr
int min_exponent = FLT128_MIN_EXP;
76 static constexpr
int min_exponent10 = FLT128_MIN_10_EXP;
77 static constexpr
int max_exponent = FLT128_MAX_EXP;
78 static constexpr
int max_exponent10 = FLT128_MAX_10_EXP;
80 static constexpr
bool has_infinity =
true;
81 static constexpr
bool has_quiet_NaN =
true;
82 static constexpr
bool has_signaling_NaN =
true;
83 static constexpr float_denorm_style has_denorm = denorm_present;
84 static constexpr
bool has_denorm_loss =
false;
85 static constexpr quad infinity() throw()
86 {
return __builtin_huge_valq(); }
87 static constexpr quad quiet_NaN() throw()
88 {
return __builtin_nan(
""); }
89 static constexpr quad signaling_NaN() throw()
90 {
return __builtin_nans(
""); }
91 static constexpr quad denorm_min() throw()
92 {
return FLT128_DENORM_MIN; }
94 static constexpr
bool is_iec559 =
true;
95 static constexpr
bool is_bounded =
true;
96 static constexpr
bool is_modulo =
false;
98 static constexpr
bool traps = std::numeric_limits<double>::traps;
99 static constexpr
bool tinyness_before = std::numeric_limits<double>::tinyness_before;
100 static constexpr float_round_style round_style = round_to_nearest;
105 struct is_floating_point<quad>
106 :
public integral_constant<bool, true>
110 struct is_arithmetic<quad>
111 :
public integral_constant<bool, true>
115 struct is_fundamental<quad>
116 :
public integral_constant<bool, true>
120 struct is_scalar<quad>
121 :
public integral_constant<bool, true>
126 :
public integral_constant<bool, true>
130 struct is_signed<quad>
131 :
public integral_constant<bool, true>
136 struct is_standard_layout<quad>
137 :
public integral_constant<bool, true>
141 struct is_trivial<quad>
142 :
public integral_constant<bool, true>
152 template <
class OtherType>
153 struct is_assignable<quad, OtherType>
154 :
public integral_constant<bool, is_arithmetic<OtherType>::value>
157 template <
class OtherType>
158 struct is_nothrow_assignable<quad, OtherType>
159 :
public is_assignable<quad, OtherType>
170 struct is_copy_assignable<quad>
171 :
public integral_constant<bool, true>
175 struct is_nothrow_copy_assignable<quad>
176 :
public integral_constant<bool, true>
180 struct is_move_assignable<quad>
181 :
public integral_constant<bool, true>
185 struct is_nothrow_move_assignable<quad>
186 :
public integral_constant<bool, true>
190 struct is_constructible<quad>
191 :
public integral_constant<bool, true>
195 struct is_nothrow_constructible<quad>
196 :
public integral_constant<bool, true>
200 struct is_default_constructible<quad>
201 :
public integral_constant<bool, true>
205 struct is_nothrow_default_constructible<quad>
206 :
public integral_constant<bool, true>
217 struct is_copy_constructible<quad>
218 :
public integral_constant<bool, true>
222 struct is_move_constructible<quad>
223 :
public integral_constant<bool, true>
227 struct is_nothrow_move_constructible<quad>
228 :
public integral_constant<bool, true>
233 struct is_destructible<quad>
234 :
public integral_constant<bool, true>
238 struct is_nothrow_destructible<quad>
239 :
public integral_constant<bool, true>
242 template <
class OtherType>
243 struct is_convertible<quad, OtherType>
244 :
public is_arithmetic<OtherType>
247 inline std::ostream& operator<<(std::ostream& os,
const quad& val)
249 if (os.precision() > std::numeric_limits<double>::digits10)
250 throw std::runtime_error(
"The precision requested for output cannot "
251 "be represented by a double precision floating "
254 return os << static_cast<double>(val);
257 inline std::istream& operator>>(std::istream& is, quad& val)
260 std::istream& ret = (is >> tmp);
265 inline quad real(quad val)
268 inline quad real(
const std::complex<quad>& val)
269 {
return val.real(); }
271 inline quad imag(quad)
274 inline quad imag(
const std::complex<quad>& val)
275 {
return val.imag(); }
277 inline quad abs(quad val)
278 {
return (val < 0) ? -val : val; }
280 inline quad floor(quad val)
281 {
return floorq(val); }
283 inline quad ceil(quad val)
284 {
return ceilq(val); }
286 inline quad max(quad a, quad b)
287 {
return (a > b) ? a : b; }
289 inline quad min(quad a, quad b)
290 {
return (a < b) ? a : b; }
292 inline quad sqrt(quad val)
293 {
return sqrtq(val); }
295 template <
class ExpType>
296 inline quad pow(quad base, ExpType exp)
297 {
return powq(base,
static_cast<quad
>(exp)); }
299 template <
class BaseType>
300 inline quad pow(BaseType base, quad exp)
301 {
return powq(
static_cast<quad
>(base), exp); }
303 inline quad pow(quad base, quad exp)
304 {
return powq(base, exp); }
306 inline quad exp(quad val)
307 {
return expq(val); }
309 inline quad log(quad val)
310 {
return logq(val); }
312 inline quad sin(quad val)
313 {
return sinq(val); }
315 inline quad cos(quad val)
316 {
return cosq(val); }
318 inline quad tan(quad val)
319 {
return tanq(val); }
321 inline quad atan(quad val)
322 {
return atanq(val); }
324 inline quad atan2(quad a, quad b)
325 {
return atan2q(a, b); }
327 inline quad round(quad val)
328 {
return roundq(val); }
330 inline bool isfinite(quad val)
331 {
return finiteq(val); }
333 inline bool isnan(quad val)
334 {
return isnanq(val); }
336 inline bool isinf(quad val)
337 {
return isinfq(val); }
343 #include <dune/common/classname.hh>
347 inline std::string className<__float128>()
352 #include <dune/fem/io/streams/streams_inline.hh>
356 template <
class Traits>
357 inline OutStreamInterface<Traits>&
358 operator<<(OutStreamInterface<Traits>& out, quad value)
360 out.writeDouble(
static_cast<double>(value));
364 template <
class Traits>
365 inline InStreamInterface<Traits>&
366 operator>>(InStreamInterface<Traits>& in, quad& value)
Provides the OPM_UNUSED macro.