00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00029 #if HAVE_DUNE_COMMON
00030 #ifdef DUNE_CLASSNAME_HH
00031 #error "Due to some trickery required for the linker, this file must be included _before_ Dune's classname.hh!"
00032 #endif
00033
00034 #include <dune/common/classname.hh>
00035 #endif // HAVE_DUNE_COMMON
00036
00037 #if !defined OPM_COMMON_QUAD_HPP && HAVE_QUAD
00038 #define OPM_COMMON_QUAD_HPP
00039
00040 #include <cmath>
00041 #include <string>
00042 #include <stdexcept>
00043 #include <limits>
00044 #include <iostream>
00045 #include <type_traits>
00046
00047 extern "C" {
00048 #include <quadmath.h>
00049 }
00050
00051 typedef __float128 quad;
00052
00053 namespace std {
00054
00055
00056 template <>
00057 class numeric_limits<quad>
00058 {
00059 public:
00060 static constexpr bool is_specialized = true;
00061
00062 static constexpr quad min() throw()
00063 { return FLT128_MIN; }
00064 static constexpr quad max() throw()
00065 { return FLT128_MAX; }
00066
00067
00068 static constexpr int digits = FLT128_MANT_DIG;
00069
00070 static constexpr int digits10 = FLT128_DIG;
00071 static constexpr bool is_signed = true;
00072 static constexpr bool is_integer = false;
00073 static constexpr bool is_exact = false;
00074 static constexpr int radix = 0;
00075 static constexpr quad epsilon() throw()
00076 { return FLT128_EPSILON; }
00077 static constexpr quad round_error() throw()
00078 { return 0.5; }
00079
00080 static constexpr int min_exponent = FLT128_MIN_EXP;
00081 static constexpr int min_exponent10 = FLT128_MIN_10_EXP;
00082 static constexpr int max_exponent = FLT128_MAX_EXP;
00083 static constexpr int max_exponent10 = FLT128_MAX_10_EXP;
00084
00085 static constexpr bool has_infinity = true;
00086 static constexpr bool has_quiet_NaN = true;
00087 static constexpr bool has_signaling_NaN = true;
00088 static constexpr float_denorm_style has_denorm = denorm_present;
00089 static constexpr bool has_denorm_loss = false;
00090 static constexpr quad infinity() throw()
00091 { return __builtin_huge_valq(); }
00092 static constexpr quad quiet_NaN() throw()
00093 { return __builtin_nan(""); }
00094 static constexpr quad signaling_NaN() throw()
00095 { return __builtin_nans(""); }
00096 static constexpr quad denorm_min() throw()
00097 { return FLT128_DENORM_MIN; }
00098
00099 static constexpr bool is_iec559 = true;
00100 static constexpr bool is_bounded = true;
00101 static constexpr bool is_modulo = false;
00102
00103 static constexpr bool traps = std::numeric_limits<double>::traps;
00104 static constexpr bool tinyness_before = std::numeric_limits<double>::tinyness_before;
00105 static constexpr float_round_style round_style = round_to_nearest;
00106 };
00107
00108
00109 template <>
00110 struct is_floating_point<quad>
00111 : public integral_constant<bool, true>
00112 {};
00113
00114 template <>
00115 struct is_arithmetic<quad>
00116 : public integral_constant<bool, true>
00117 {};
00118
00119 template <>
00120 struct is_fundamental<quad>
00121 : public integral_constant<bool, true>
00122 {};
00123
00124 template <>
00125 struct is_scalar<quad>
00126 : public integral_constant<bool, true>
00127 {};
00128
00129 template <>
00130 struct is_pod<quad>
00131 : public integral_constant<bool, true>
00132 {};
00133
00134 template <>
00135 struct is_signed<quad>
00136 : public integral_constant<bool, true>
00137 {};
00138
00139
00140 template <>
00141 struct is_standard_layout<quad>
00142 : public integral_constant<bool, true>
00143 {};
00144
00145 template <>
00146 struct is_trivial<quad>
00147 : public integral_constant<bool, true>
00148 {};
00149
00150
00151
00152
00153
00154
00155
00156
00157 template <class OtherType>
00158 struct is_assignable<quad, OtherType>
00159 : public integral_constant<bool, is_arithmetic<OtherType>::value>
00160 {};
00161
00162 template <class OtherType>
00163 struct is_nothrow_assignable<quad, OtherType>
00164 : public is_assignable<quad, OtherType>
00165 {};
00166
00167
00168
00169
00170
00171
00172
00173
00174 template <>
00175 struct is_copy_assignable<quad>
00176 : public integral_constant<bool, true>
00177 {};
00178
00179 template <>
00180 struct is_nothrow_copy_assignable<quad>
00181 : public integral_constant<bool, true>
00182 {};
00183
00184 template <>
00185 struct is_move_assignable<quad>
00186 : public integral_constant<bool, true>
00187 {};
00188
00189 template <>
00190 struct is_nothrow_move_assignable<quad>
00191 : public integral_constant<bool, true>
00192 {};
00193
00194 template <>
00195 struct is_constructible<quad>
00196 : public integral_constant<bool, true>
00197 {};
00198
00199 template <>
00200 struct is_nothrow_constructible<quad>
00201 : public integral_constant<bool, true>
00202 {};
00203
00204 template <>
00205 struct is_default_constructible<quad>
00206 : public integral_constant<bool, true>
00207 {};
00208
00209 template <>
00210 struct is_nothrow_default_constructible<quad>
00211 : public integral_constant<bool, true>
00212 {};
00213
00214
00215
00216
00217
00218
00219
00220
00221 template <>
00222 struct is_copy_constructible<quad>
00223 : public integral_constant<bool, true>
00224 {};
00225
00226 template <>
00227 struct is_move_constructible<quad>
00228 : public integral_constant<bool, true>
00229 {};
00230
00231 template <>
00232 struct is_nothrow_move_constructible<quad>
00233 : public integral_constant<bool, true>
00234 {};
00235
00236
00237 template <>
00238 struct is_destructible<quad>
00239 : public integral_constant<bool, true>
00240 {};
00241
00242 template <>
00243 struct is_nothrow_destructible<quad>
00244 : public integral_constant<bool, true>
00245 {};
00246
00247 template <class OtherType>
00248 struct is_convertible<quad, OtherType>
00249 : public is_arithmetic<OtherType>
00250 { };
00251
00252 inline std::ostream& operator<<(std::ostream& os, const quad& val)
00253 {
00254 if (os.precision() > std::numeric_limits<double>::digits10)
00255 throw std::runtime_error("The precision requested for output cannot "
00256 "be represented by a double precision floating "
00257 "point object");
00258
00259 return os << static_cast<double>(val);
00260 }
00261
00262 inline std::istream& operator>>(std::istream& is, quad& val)
00263 {
00264 double tmp;
00265 std::istream& ret = (is >> tmp);
00266 val = tmp;
00267 return ret;
00268 }
00269
00270 inline quad abs(quad val)
00271 { return (val < 0) ? -val : val; }
00272
00273 inline quad floor(quad val)
00274 { return floorq(val); }
00275
00276 inline quad ceil(quad val)
00277 { return ceilq(val); }
00278
00279 inline quad max(quad a, quad b)
00280 { return (a > b) ? a : b; }
00281
00282 inline quad min(quad a, quad b)
00283 { return (a < b) ? a : b; }
00284
00285 inline quad sqrt(quad val)
00286 { return sqrtq(val); }
00287
00288 template <class ExpType>
00289 inline quad pow(quad base, ExpType exp)
00290 { return powq(base, static_cast<quad>(exp)); }
00291
00292 template <class BaseType>
00293 inline quad pow(BaseType base, quad exp)
00294 { return powq(static_cast<quad>(base), exp); }
00295
00296 inline quad pow(quad base, quad exp)
00297 { return powq(base, exp); }
00298
00299 inline quad exp(quad val)
00300 { return expq(val); }
00301
00302 inline quad log(quad val)
00303 { return logq(val); }
00304
00305 inline quad sin(quad val)
00306 { return sinq(val); }
00307
00308 inline quad cos(quad val)
00309 { return cosq(val); }
00310
00311 inline quad tan(quad val)
00312 { return tanq(val); }
00313
00314 inline quad atan(quad val)
00315 { return atanq(val); }
00316
00317 inline quad atan2(quad a, quad b)
00318 { return atan2q(a, b); }
00319
00320 inline quad round(quad val)
00321 { return roundq(val); }
00322
00323 inline bool isfinite(quad val)
00324 { return finiteq(val); }
00325
00326 inline bool isnan(quad val)
00327 { return isnanq(val); }
00328
00329 inline bool isinf(quad val)
00330 { return isinfq(val); }
00331
00332 }
00333
00334 #if HAVE_DUNE_COMMON
00335
00336
00337 namespace Dune {
00338 template <>
00339 inline std::string className<__float128>()
00340 { return "quad"; }
00341 }
00342 #endif // HAVE_DUNE_COMMON
00343
00344 #endif // OPM_COMMON_QUAD_HPP