float128.hpp 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738
  1. ///////////////////////////////////////////////////////////////
  2. // Copyright 2013 John Maddock. Distributed under the Boost
  3. // Software License, Version 1.0. (See accompanying file
  4. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_
  5. #ifndef BOOST_MP_FLOAT128_HPP
  6. #define BOOST_MP_FLOAT128_HPP
  7. #include <boost/config.hpp>
  8. #include <boost/scoped_array.hpp>
  9. #include <boost/functional/hash.hpp>
  10. #include <boost/multiprecision/number.hpp>
  11. #if defined(BOOST_INTEL) && !defined(BOOST_MP_USE_FLOAT128) && !defined(BOOST_MP_USE_QUAD)
  12. # if defined(BOOST_INTEL_CXX_VERSION) && (BOOST_INTEL_CXX_VERSION >= 1310) && defined(__GNUC__)
  13. # if (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 6))
  14. # define BOOST_MP_USE_FLOAT128
  15. # endif
  16. # endif
  17. # ifndef BOOST_MP_USE_FLOAT128
  18. # define BOOST_MP_USE_QUAD
  19. # endif
  20. #endif
  21. #if defined(__GNUC__) && !defined(BOOST_MP_USE_FLOAT128) && !defined(BOOST_MP_USE_QUAD)
  22. # define BOOST_MP_USE_FLOAT128
  23. #endif
  24. #if !defined(BOOST_MP_USE_FLOAT128) && !defined(BOOST_MP_USE_QUAD)
  25. # error "Sorry compiler is neither GCC, not Intel, don't know how to configure this header."
  26. #endif
  27. #if defined(BOOST_MP_USE_FLOAT128) && defined(BOOST_MP_USE_QUAD)
  28. # error "Oh dear, both BOOST_MP_USE_FLOAT128 and BOOST_MP_USE_QUAD are defined, which one should I be using?"
  29. #endif
  30. #if defined(BOOST_MP_USE_FLOAT128)
  31. extern "C" {
  32. #include <quadmath.h>
  33. }
  34. typedef __float128 float128_type;
  35. #elif defined(BOOST_MP_USE_QUAD)
  36. #include <boost/multiprecision/detail/float_string_cvt.hpp>
  37. typedef _Quad float128_type;
  38. extern "C" {
  39. _Quad __ldexpq(_Quad, int);
  40. _Quad __frexpq(_Quad, int*);
  41. _Quad __fabsq(_Quad);
  42. _Quad __floorq(_Quad);
  43. _Quad __ceilq(_Quad);
  44. _Quad __sqrtq(_Quad);
  45. _Quad __truncq(_Quad);
  46. _Quad __expq(_Quad);
  47. _Quad __powq(_Quad, _Quad);
  48. _Quad __logq(_Quad);
  49. _Quad __log10q(_Quad);
  50. _Quad __sinq(_Quad);
  51. _Quad __cosq(_Quad);
  52. _Quad __tanq(_Quad);
  53. _Quad __asinq(_Quad);
  54. _Quad __acosq(_Quad);
  55. _Quad __atanq(_Quad);
  56. _Quad __sinhq(_Quad);
  57. _Quad __coshq(_Quad);
  58. _Quad __tanhq(_Quad);
  59. _Quad __fmodq(_Quad, _Quad);
  60. _Quad __atan2q(_Quad, _Quad);
  61. #define ldexpq __ldexpq
  62. #define frexpq __frexpq
  63. #define fabsq __fabsq
  64. #define floorq __floorq
  65. #define ceilq __ceilq
  66. #define sqrtq __sqrtq
  67. #define truncq __truncq
  68. #define expq __expq
  69. #define powq __powq
  70. #define logq __logq
  71. #define log10q __log10q
  72. #define sinq __sinq
  73. #define cosq __cosq
  74. #define tanq __tanq
  75. #define asinq __asinq
  76. #define acosq __acosq
  77. #define atanq __atanq
  78. #define sinhq __sinhq
  79. #define coshq __coshq
  80. #define tanhq __tanhq
  81. #define fmodq __fmodq
  82. #define atan2q __atan2q
  83. }
  84. inline _Quad isnanq(_Quad v)
  85. {
  86. return v != v;
  87. }
  88. inline _Quad isinfq(_Quad v)
  89. {
  90. return __fabsq(v) > 1.18973149535723176508575932662800702e4932Q;
  91. }
  92. #endif
  93. namespace boost{
  94. namespace multiprecision{
  95. namespace backends{
  96. struct float128_backend;
  97. }
  98. using backends::float128_backend;
  99. template<>
  100. struct number_category<backends::float128_backend> : public mpl::int_<number_kind_floating_point> {};
  101. #if defined(BOOST_MP_USE_QUAD)
  102. template<>
  103. struct number_category<float128_type> : public mpl::int_<number_kind_floating_point> {};
  104. #endif
  105. typedef number<float128_backend, et_off> float128;
  106. namespace backends{
  107. struct float128_backend
  108. {
  109. typedef mpl::list<signed char, short, int, long, boost::long_long_type> signed_types;
  110. typedef mpl::list<unsigned char, unsigned short,
  111. unsigned int, unsigned long, boost::ulong_long_type> unsigned_types;
  112. typedef mpl::list<float, double, long double> float_types;
  113. typedef int exponent_type;
  114. private:
  115. float128_type m_value;
  116. public:
  117. BOOST_CONSTEXPR float128_backend() BOOST_NOEXCEPT : m_value(0) {}
  118. BOOST_CONSTEXPR float128_backend(const float128_backend& o) BOOST_NOEXCEPT : m_value(o.m_value) {}
  119. float128_backend& operator = (const float128_backend& o) BOOST_NOEXCEPT
  120. {
  121. m_value = o.m_value;
  122. return *this;
  123. }
  124. template <class T>
  125. BOOST_CONSTEXPR float128_backend(const T& i, const typename enable_if_c<is_convertible<T, float128_type>::value>::type* = 0) BOOST_NOEXCEPT_IF(noexcept(std::declval<float128_type&>() = std::declval<const T&>()))
  126. : m_value(i) {}
  127. template <class T>
  128. typename enable_if_c<is_arithmetic<T>::value || is_convertible<T, float128_type>::value, float128_backend&>::type operator = (const T& i) BOOST_NOEXCEPT_IF(noexcept(std::declval<float128_type&>() = std::declval<const T&>()))
  129. {
  130. m_value = i;
  131. return *this;
  132. }
  133. float128_backend(long double const& f)
  134. {
  135. if(boost::math::isinf(f))
  136. m_value = (f < 0) ? -1.0Q / 0.0Q : 1.0Q / 0.0Q;
  137. else
  138. m_value = f;
  139. }
  140. float128_backend& operator=(long double const& f)
  141. {
  142. if(boost::math::isinf(f))
  143. m_value = (f < 0) ? -1.0Q / 0.0Q : 1.0Q / 0.0Q;
  144. else
  145. m_value = f;
  146. return *this;
  147. }
  148. float128_backend& operator = (const char* s)
  149. {
  150. #ifndef BOOST_MP_USE_QUAD
  151. char* p_end;
  152. m_value = strtoflt128(s, &p_end);
  153. if(p_end - s != (std::ptrdiff_t)std::strlen(s))
  154. {
  155. BOOST_THROW_EXCEPTION(std::runtime_error("Unable to interpret input string as a floating point value"));
  156. }
  157. #else
  158. boost::multiprecision::detail::convert_from_string(*this, s);
  159. #endif
  160. return *this;
  161. }
  162. void swap(float128_backend& o) BOOST_NOEXCEPT
  163. {
  164. std::swap(m_value, o.value());
  165. }
  166. std::string str(std::streamsize digits, std::ios_base::fmtflags f)const
  167. {
  168. #ifndef BOOST_MP_USE_QUAD
  169. char buf[100];
  170. boost::scoped_array<char> buf2;
  171. std::string format = "%";
  172. if(f & std::ios_base::showpos)
  173. format += "+";
  174. if(f & std::ios_base::showpoint)
  175. format += "#";
  176. format += ".*";
  177. if(digits == 0)
  178. digits = 36;
  179. format += "Q";
  180. if(f & std::ios_base::scientific)
  181. format += "e";
  182. else if(f & std::ios_base::fixed)
  183. format += "f";
  184. else
  185. format += "g";
  186. int v = quadmath_snprintf (buf, 100, format.c_str(), digits, m_value);
  187. if((v < 0) || (v >= 99))
  188. {
  189. int v_max = v;
  190. buf2.reset(new char[v+3]);
  191. v = quadmath_snprintf (&buf2[0], v_max + 3, format.c_str(), digits, m_value);
  192. if(v >= v_max + 3)
  193. {
  194. BOOST_THROW_EXCEPTION(std::runtime_error("Formatting of float128_type failed."));
  195. }
  196. return &buf2[0];
  197. }
  198. return buf;
  199. #else
  200. return boost::multiprecision::detail::convert_to_string(*this, digits ? digits : 37, f);
  201. #endif
  202. }
  203. void negate() BOOST_NOEXCEPT
  204. {
  205. m_value = -m_value;
  206. }
  207. int compare(const float128_backend& o)const
  208. {
  209. return m_value == o.m_value ? 0 : m_value < o.m_value ? -1 : 1;
  210. }
  211. template <class T>
  212. int compare(const T& i)const
  213. {
  214. return m_value == i ? 0 : m_value < i ? -1 : 1;
  215. }
  216. float128_type& value()
  217. {
  218. return m_value;
  219. }
  220. const float128_type& value()const
  221. {
  222. return m_value;
  223. }
  224. };
  225. inline void eval_add(float128_backend& result, const float128_backend& a)
  226. {
  227. result.value() += a.value();
  228. }
  229. template <class A>
  230. inline void eval_add(float128_backend& result, const A& a)
  231. {
  232. result.value() += a;
  233. }
  234. inline void eval_subtract(float128_backend& result, const float128_backend& a)
  235. {
  236. result.value() -= a.value();
  237. }
  238. template <class A>
  239. inline void eval_subtract(float128_backend& result, const A& a)
  240. {
  241. result.value() -= a;
  242. }
  243. inline void eval_multiply(float128_backend& result, const float128_backend& a)
  244. {
  245. result.value() *= a.value();
  246. }
  247. template <class A>
  248. inline void eval_multiply(float128_backend& result, const A& a)
  249. {
  250. result.value() *= a;
  251. }
  252. inline void eval_divide(float128_backend& result, const float128_backend& a)
  253. {
  254. result.value() /= a.value();
  255. }
  256. template <class A>
  257. inline void eval_divide(float128_backend& result, const A& a)
  258. {
  259. result.value() /= a;
  260. }
  261. inline void eval_add(float128_backend& result, const float128_backend& a, const float128_backend& b)
  262. {
  263. result.value() = a.value() + b.value();
  264. }
  265. template <class A>
  266. inline void eval_add(float128_backend& result, const float128_backend& a, const A& b)
  267. {
  268. result.value() = a.value() + b;
  269. }
  270. inline void eval_subtract(float128_backend& result, const float128_backend& a, const float128_backend& b)
  271. {
  272. result.value() = a.value() - b.value();
  273. }
  274. template <class A>
  275. inline void eval_subtract(float128_backend& result, const float128_backend& a, const A& b)
  276. {
  277. result.value() = a.value() - b;
  278. }
  279. template <class A>
  280. inline void eval_subtract(float128_backend& result, const A& a, const float128_backend& b)
  281. {
  282. result.value() = a - b.value();
  283. }
  284. inline void eval_multiply(float128_backend& result, const float128_backend& a, const float128_backend& b)
  285. {
  286. result.value() = a.value() * b.value();
  287. }
  288. template <class A>
  289. inline void eval_multiply(float128_backend& result, const float128_backend& a, const A& b)
  290. {
  291. result.value() = a.value() * b;
  292. }
  293. inline void eval_divide(float128_backend& result, const float128_backend& a, const float128_backend& b)
  294. {
  295. result.value() = a.value() / b.value();
  296. }
  297. template <class R>
  298. inline void eval_convert_to(R* result, const float128_backend& val)
  299. {
  300. *result = static_cast<R>(val.value());
  301. }
  302. inline void eval_frexp(float128_backend& result, const float128_backend& arg, int* exp)
  303. {
  304. result.value() = frexpq(arg.value(), exp);
  305. }
  306. inline void eval_ldexp(float128_backend& result, const float128_backend& arg, int exp)
  307. {
  308. result.value() = ldexpq(arg.value(), exp);
  309. }
  310. inline void eval_floor(float128_backend& result, const float128_backend& arg)
  311. {
  312. result.value() = floorq(arg.value());
  313. }
  314. inline void eval_ceil(float128_backend& result, const float128_backend& arg)
  315. {
  316. result.value() = ceilq(arg.value());
  317. }
  318. inline void eval_sqrt(float128_backend& result, const float128_backend& arg)
  319. {
  320. result.value() = sqrtq(arg.value());
  321. }
  322. inline int eval_fpclassify(const float128_backend& arg)
  323. {
  324. if(isnanq(arg.value()))
  325. return FP_NAN;
  326. else if(isinfq(arg.value()))
  327. return FP_INFINITE;
  328. else if(arg.value() == 0)
  329. return FP_ZERO;
  330. float128_backend t(arg);
  331. if(t.value() < 0)
  332. t.negate();
  333. if(t.value() < 3.36210314311209350626267781732175260e-4932Q)
  334. return FP_SUBNORMAL;
  335. return FP_NORMAL;
  336. }
  337. inline void eval_increment(float128_backend& arg)
  338. {
  339. ++arg.value();
  340. }
  341. inline void eval_decrement(float128_backend& arg)
  342. {
  343. --arg.value();
  344. }
  345. /*********************************************************************
  346. *
  347. * abs/fabs:
  348. *
  349. *********************************************************************/
  350. inline void eval_abs(float128_backend& result, const float128_backend& arg)
  351. {
  352. result.value() = fabsq(arg.value());
  353. }
  354. inline void eval_fabs(float128_backend& result, const float128_backend& arg)
  355. {
  356. result.value() = fabsq(arg.value());
  357. }
  358. /*********************************************************************
  359. *
  360. * Floating point functions:
  361. *
  362. *********************************************************************/
  363. inline void eval_trunc(float128_backend& result, const float128_backend& arg)
  364. {
  365. result.value() = truncq(arg.value());
  366. }
  367. /*
  368. //
  369. // This doesn't actually work... rely on our own default version instead.
  370. //
  371. inline void eval_round(float128_backend& result, const float128_backend& arg)
  372. {
  373. if(isnanq(arg.value()) || isinf(arg.value()))
  374. {
  375. result = boost::math::policies::raise_rounding_error(
  376. "boost::multiprecision::trunc<%1%>(%1%)", 0,
  377. number<float128_backend, et_off>(arg),
  378. number<float128_backend, et_off>(arg),
  379. boost::math::policies::policy<>()).backend();
  380. return;
  381. }
  382. result.value() = roundq(arg.value());
  383. }
  384. */
  385. inline void eval_exp(float128_backend& result, const float128_backend& arg)
  386. {
  387. result.value() = expq(arg.value());
  388. }
  389. inline void eval_log(float128_backend& result, const float128_backend& arg)
  390. {
  391. result.value() = logq(arg.value());
  392. }
  393. inline void eval_log10(float128_backend& result, const float128_backend& arg)
  394. {
  395. result.value() = log10q(arg.value());
  396. }
  397. inline void eval_sin(float128_backend& result, const float128_backend& arg)
  398. {
  399. result.value() = sinq(arg.value());
  400. }
  401. inline void eval_cos(float128_backend& result, const float128_backend& arg)
  402. {
  403. result.value() = cosq(arg.value());
  404. }
  405. inline void eval_tan(float128_backend& result, const float128_backend& arg)
  406. {
  407. result.value() = tanq(arg.value());
  408. }
  409. inline void eval_asin(float128_backend& result, const float128_backend& arg)
  410. {
  411. result.value() = asinq(arg.value());
  412. }
  413. inline void eval_acos(float128_backend& result, const float128_backend& arg)
  414. {
  415. result.value() = acosq(arg.value());
  416. }
  417. inline void eval_atan(float128_backend& result, const float128_backend& arg)
  418. {
  419. result.value() = atanq(arg.value());
  420. }
  421. inline void eval_sinh(float128_backend& result, const float128_backend& arg)
  422. {
  423. result.value() = sinhq(arg.value());
  424. }
  425. inline void eval_cosh(float128_backend& result, const float128_backend& arg)
  426. {
  427. result.value() = coshq(arg.value());
  428. }
  429. inline void eval_tanh(float128_backend& result, const float128_backend& arg)
  430. {
  431. result.value() = tanhq(arg.value());
  432. }
  433. inline void eval_fmod(float128_backend& result, const float128_backend& a, const float128_backend& b)
  434. {
  435. result.value() = fmodq(a.value(), b.value());
  436. }
  437. inline void eval_pow(float128_backend& result, const float128_backend& a, const float128_backend& b)
  438. {
  439. result.value() = powq(a.value(), b.value());
  440. }
  441. inline void eval_atan2(float128_backend& result, const float128_backend& a, const float128_backend& b)
  442. {
  443. result.value() = atan2q(a.value(), b.value());
  444. }
  445. #ifndef BOOST_MP_USE_QUAD
  446. inline void eval_multiply_add(float128_backend& result, const float128_backend& a, const float128_backend& b, const float128_backend& c)
  447. {
  448. result.value() = fmaq(a.value(), b.value(), c.value());
  449. }
  450. inline int eval_signbit BOOST_PREVENT_MACRO_SUBSTITUTION(const float128_backend& arg)
  451. {
  452. return ::signbitq(arg.value());
  453. }
  454. #endif
  455. inline std::size_t hash_value(const float128_backend& val)
  456. {
  457. return boost::hash_value(static_cast<double>(val.value()));
  458. }
  459. } // namespace backends
  460. template<boost::multiprecision::expression_template_option ExpressionTemplates>
  461. inline boost::multiprecision::number<float128_backend, ExpressionTemplates> asinh BOOST_PREVENT_MACRO_SUBSTITUTION(const boost::multiprecision::number<float128_backend, ExpressionTemplates>& arg)
  462. {
  463. return asinhq(arg.backend().value());
  464. }
  465. template<boost::multiprecision::expression_template_option ExpressionTemplates>
  466. inline boost::multiprecision::number<float128_backend, ExpressionTemplates> acosh BOOST_PREVENT_MACRO_SUBSTITUTION(const boost::multiprecision::number<float128_backend, ExpressionTemplates>& arg)
  467. {
  468. return acoshq(arg.backend().value());
  469. }
  470. template<boost::multiprecision::expression_template_option ExpressionTemplates>
  471. inline boost::multiprecision::number<float128_backend, ExpressionTemplates> atanh BOOST_PREVENT_MACRO_SUBSTITUTION(const boost::multiprecision::number<float128_backend, ExpressionTemplates>& arg)
  472. {
  473. return atanhq(arg.backend().value());
  474. }
  475. template<boost::multiprecision::expression_template_option ExpressionTemplates>
  476. inline boost::multiprecision::number<float128_backend, ExpressionTemplates> cbrt BOOST_PREVENT_MACRO_SUBSTITUTION(const boost::multiprecision::number<float128_backend, ExpressionTemplates>& arg)
  477. {
  478. return cbrtq(arg.backend().value());
  479. }
  480. template<boost::multiprecision::expression_template_option ExpressionTemplates>
  481. inline boost::multiprecision::number<float128_backend, ExpressionTemplates> erf BOOST_PREVENT_MACRO_SUBSTITUTION(const boost::multiprecision::number<float128_backend, ExpressionTemplates>& arg)
  482. {
  483. return erfq(arg.backend().value());
  484. }
  485. template<boost::multiprecision::expression_template_option ExpressionTemplates>
  486. inline boost::multiprecision::number<float128_backend, ExpressionTemplates> erfc BOOST_PREVENT_MACRO_SUBSTITUTION(const boost::multiprecision::number<float128_backend, ExpressionTemplates>& arg)
  487. {
  488. return erfcq(arg.backend().value());
  489. }
  490. template<boost::multiprecision::expression_template_option ExpressionTemplates>
  491. inline boost::multiprecision::number<float128_backend, ExpressionTemplates> expm1 BOOST_PREVENT_MACRO_SUBSTITUTION(const boost::multiprecision::number<float128_backend, ExpressionTemplates>& arg)
  492. {
  493. return expm1q(arg.backend().value());
  494. }
  495. template<boost::multiprecision::expression_template_option ExpressionTemplates>
  496. inline boost::multiprecision::number<float128_backend, ExpressionTemplates> lgamma BOOST_PREVENT_MACRO_SUBSTITUTION(const boost::multiprecision::number<float128_backend, ExpressionTemplates>& arg)
  497. {
  498. return lgammaq(arg.backend().value());
  499. }
  500. template<boost::multiprecision::expression_template_option ExpressionTemplates>
  501. inline boost::multiprecision::number<float128_backend, ExpressionTemplates> tgamma BOOST_PREVENT_MACRO_SUBSTITUTION(const boost::multiprecision::number<float128_backend, ExpressionTemplates>& arg)
  502. {
  503. return tgammaq(arg.backend().value());
  504. }
  505. template<boost::multiprecision::expression_template_option ExpressionTemplates>
  506. inline boost::multiprecision::number<float128_backend, ExpressionTemplates> log1p BOOST_PREVENT_MACRO_SUBSTITUTION(const boost::multiprecision::number<float128_backend, ExpressionTemplates>& arg)
  507. {
  508. return log1pq(arg.backend().value());
  509. }
  510. #ifndef BOOST_MP_USE_QUAD
  511. template <multiprecision::expression_template_option ExpressionTemplates>
  512. inline boost::multiprecision::number<boost::multiprecision::backends::float128_backend, ExpressionTemplates> copysign BOOST_PREVENT_MACRO_SUBSTITUTION(const boost::multiprecision::number<boost::multiprecision::backends::float128_backend, ExpressionTemplates>& a, const boost::multiprecision::number<boost::multiprecision::backends::float128_backend, ExpressionTemplates>& b)
  513. {
  514. return ::copysignq(a.backend().value(), b.backend().value());
  515. }
  516. inline void eval_remainder(float128_backend& result, const float128_backend& a, const float128_backend& b)
  517. {
  518. result.value() = remainderq(a.value(), b.value());
  519. }
  520. inline void eval_remainder(float128_backend& result, const float128_backend& a, const float128_backend& b, int* pi)
  521. {
  522. result.value() = remquoq(a.value(), b.value(), pi);
  523. }
  524. #endif
  525. } // namespace multiprecision
  526. namespace math {
  527. using boost::multiprecision::signbit;
  528. using boost::multiprecision::copysign;
  529. } // namespace math
  530. } // namespace boost
  531. namespace boost{
  532. namespace archive{
  533. class binary_oarchive;
  534. class binary_iarchive;
  535. }
  536. namespace serialization{ namespace float128_detail{
  537. template <class Archive>
  538. void do_serialize(Archive& ar, boost::multiprecision::backends::float128_backend& val, const mpl::false_&, const mpl::false_&)
  539. {
  540. // saving
  541. // non-binary
  542. std::string s(val.str(0, std::ios_base::scientific));
  543. ar & s;
  544. }
  545. template <class Archive>
  546. void do_serialize(Archive& ar, boost::multiprecision::backends::float128_backend& val, const mpl::true_&, const mpl::false_&)
  547. {
  548. // loading
  549. // non-binary
  550. std::string s;
  551. ar & s;
  552. val = s.c_str();
  553. }
  554. template <class Archive>
  555. void do_serialize(Archive& ar, boost::multiprecision::backends::float128_backend& val, const mpl::false_&, const mpl::true_&)
  556. {
  557. // saving
  558. // binary
  559. ar.save_binary(&val, sizeof(val));
  560. }
  561. template <class Archive>
  562. void do_serialize(Archive& ar, boost::multiprecision::backends::float128_backend& val, const mpl::true_&, const mpl::true_&)
  563. {
  564. // loading
  565. // binary
  566. ar.load_binary(&val, sizeof(val));
  567. }
  568. } // detail
  569. template <class Archive>
  570. void serialize(Archive& ar, boost::multiprecision::backends::float128_backend& val, unsigned int /*version*/)
  571. {
  572. typedef typename Archive::is_loading load_tag;
  573. typedef typename mpl::bool_<boost::is_same<Archive, boost::archive::binary_oarchive>::value || boost::is_same<Archive, boost::archive::binary_iarchive>::value> binary_tag;
  574. float128_detail::do_serialize(ar, val, load_tag(), binary_tag());
  575. }
  576. } // namepsace archive
  577. } // namespace boost
  578. namespace std{
  579. template <boost::multiprecision::expression_template_option ExpressionTemplates>
  580. class numeric_limits<boost::multiprecision::number<boost::multiprecision::backends::float128_backend, ExpressionTemplates> >
  581. {
  582. typedef boost::multiprecision::number<boost::multiprecision::backends::float128_backend, ExpressionTemplates> number_type;
  583. public:
  584. BOOST_STATIC_CONSTEXPR bool is_specialized = true;
  585. static number_type (min)() BOOST_NOEXCEPT { return 3.36210314311209350626267781732175260e-4932Q; }
  586. static number_type (max)() BOOST_NOEXCEPT { return 1.18973149535723176508575932662800702e4932Q; }
  587. static number_type lowest() BOOST_NOEXCEPT { return -(max)(); }
  588. BOOST_STATIC_CONSTEXPR int digits = 113;
  589. BOOST_STATIC_CONSTEXPR int digits10 = 33;
  590. BOOST_STATIC_CONSTEXPR int max_digits10 = 36;
  591. BOOST_STATIC_CONSTEXPR bool is_signed = true;
  592. BOOST_STATIC_CONSTEXPR bool is_integer = false;
  593. BOOST_STATIC_CONSTEXPR bool is_exact = false;
  594. BOOST_STATIC_CONSTEXPR int radix = 2;
  595. static number_type epsilon() { return 1.92592994438723585305597794258492732e-34Q; }
  596. static number_type round_error() { return 0.5; }
  597. BOOST_STATIC_CONSTEXPR int min_exponent = -16381;
  598. BOOST_STATIC_CONSTEXPR int min_exponent10 = min_exponent * 301L / 1000L;
  599. BOOST_STATIC_CONSTEXPR int max_exponent = 16384;
  600. BOOST_STATIC_CONSTEXPR int max_exponent10 = max_exponent * 301L / 1000L;
  601. BOOST_STATIC_CONSTEXPR bool has_infinity = true;
  602. BOOST_STATIC_CONSTEXPR bool has_quiet_NaN = true;
  603. BOOST_STATIC_CONSTEXPR bool has_signaling_NaN = false;
  604. BOOST_STATIC_CONSTEXPR float_denorm_style has_denorm = denorm_present;
  605. BOOST_STATIC_CONSTEXPR bool has_denorm_loss = true;
  606. static number_type infinity() { return 1.0q / 0.0q; }
  607. static number_type quiet_NaN() { return number_type("nan"); }
  608. static number_type signaling_NaN() { return 0; }
  609. static number_type denorm_min() { return 6.475175119438025110924438958227646552e-4966Q; }
  610. BOOST_STATIC_CONSTEXPR bool is_iec559 = true;
  611. BOOST_STATIC_CONSTEXPR bool is_bounded = false;
  612. BOOST_STATIC_CONSTEXPR bool is_modulo = false;
  613. BOOST_STATIC_CONSTEXPR bool traps = false;
  614. BOOST_STATIC_CONSTEXPR bool tinyness_before = false;
  615. BOOST_STATIC_CONSTEXPR float_round_style round_style = round_to_nearest;
  616. };
  617. template <boost::multiprecision::expression_template_option ExpressionTemplates>
  618. BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::backends::float128_backend, ExpressionTemplates> >::is_specialized;
  619. template <boost::multiprecision::expression_template_option ExpressionTemplates>
  620. BOOST_CONSTEXPR_OR_CONST int numeric_limits<boost::multiprecision::number<boost::multiprecision::backends::float128_backend, ExpressionTemplates> >::digits;
  621. template <boost::multiprecision::expression_template_option ExpressionTemplates>
  622. BOOST_CONSTEXPR_OR_CONST int numeric_limits<boost::multiprecision::number<boost::multiprecision::backends::float128_backend, ExpressionTemplates> >::digits10;
  623. template <boost::multiprecision::expression_template_option ExpressionTemplates>
  624. BOOST_CONSTEXPR_OR_CONST int numeric_limits<boost::multiprecision::number<boost::multiprecision::backends::float128_backend, ExpressionTemplates> >::max_digits10;
  625. template <boost::multiprecision::expression_template_option ExpressionTemplates>
  626. BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::backends::float128_backend, ExpressionTemplates> >::is_signed;
  627. template <boost::multiprecision::expression_template_option ExpressionTemplates>
  628. BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::backends::float128_backend, ExpressionTemplates> >::is_integer;
  629. template <boost::multiprecision::expression_template_option ExpressionTemplates>
  630. BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::backends::float128_backend, ExpressionTemplates> >::is_exact;
  631. template <boost::multiprecision::expression_template_option ExpressionTemplates>
  632. BOOST_CONSTEXPR_OR_CONST int numeric_limits<boost::multiprecision::number<boost::multiprecision::backends::float128_backend, ExpressionTemplates> >::radix;
  633. template <boost::multiprecision::expression_template_option ExpressionTemplates>
  634. BOOST_CONSTEXPR_OR_CONST int numeric_limits<boost::multiprecision::number<boost::multiprecision::backends::float128_backend, ExpressionTemplates> >::min_exponent;
  635. template <boost::multiprecision::expression_template_option ExpressionTemplates>
  636. BOOST_CONSTEXPR_OR_CONST int numeric_limits<boost::multiprecision::number<boost::multiprecision::backends::float128_backend, ExpressionTemplates> >::max_exponent;
  637. template <boost::multiprecision::expression_template_option ExpressionTemplates>
  638. BOOST_CONSTEXPR_OR_CONST int numeric_limits<boost::multiprecision::number<boost::multiprecision::backends::float128_backend, ExpressionTemplates> >::min_exponent10;
  639. template <boost::multiprecision::expression_template_option ExpressionTemplates>
  640. BOOST_CONSTEXPR_OR_CONST int numeric_limits<boost::multiprecision::number<boost::multiprecision::backends::float128_backend, ExpressionTemplates> >::max_exponent10;
  641. template <boost::multiprecision::expression_template_option ExpressionTemplates>
  642. BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::backends::float128_backend, ExpressionTemplates> >::has_infinity;
  643. template <boost::multiprecision::expression_template_option ExpressionTemplates>
  644. BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::backends::float128_backend, ExpressionTemplates> >::has_quiet_NaN;
  645. template <boost::multiprecision::expression_template_option ExpressionTemplates>
  646. BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::backends::float128_backend, ExpressionTemplates> >::has_signaling_NaN;
  647. template <boost::multiprecision::expression_template_option ExpressionTemplates>
  648. BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::backends::float128_backend, ExpressionTemplates> >::has_denorm_loss;
  649. template <boost::multiprecision::expression_template_option ExpressionTemplates>
  650. BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::backends::float128_backend, ExpressionTemplates> >::is_iec559;
  651. template <boost::multiprecision::expression_template_option ExpressionTemplates>
  652. BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::backends::float128_backend, ExpressionTemplates> >::is_bounded;
  653. template <boost::multiprecision::expression_template_option ExpressionTemplates>
  654. BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::backends::float128_backend, ExpressionTemplates> >::is_modulo;
  655. template <boost::multiprecision::expression_template_option ExpressionTemplates>
  656. BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::backends::float128_backend, ExpressionTemplates> >::traps;
  657. template <boost::multiprecision::expression_template_option ExpressionTemplates>
  658. BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::backends::float128_backend, ExpressionTemplates> >::tinyness_before;
  659. template <boost::multiprecision::expression_template_option ExpressionTemplates>
  660. BOOST_CONSTEXPR_OR_CONST float_round_style numeric_limits<boost::multiprecision::number<boost::multiprecision::backends::float128_backend, ExpressionTemplates> >::round_style;
  661. template <boost::multiprecision::expression_template_option ExpressionTemplates>
  662. BOOST_CONSTEXPR_OR_CONST float_denorm_style numeric_limits<boost::multiprecision::number<boost::multiprecision::backends::float128_backend, ExpressionTemplates> >::has_denorm;
  663. } // namespace std
  664. #endif