cpp_bin_float.hpp 96 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046
  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 https://www.boost.org/LICENSE_1_0.txt
  5. #ifndef BOOST_MATH_CPP_BIN_FLOAT_HPP
  6. #define BOOST_MATH_CPP_BIN_FLOAT_HPP
  7. #include <boost/multiprecision/cpp_int.hpp>
  8. #include <boost/multiprecision/integer.hpp>
  9. #include <boost/math/special_functions/trunc.hpp>
  10. #include <boost/multiprecision/detail/float_string_cvt.hpp>
  11. //
  12. // Some includes we need from Boost.Math, since we rely on that library to provide these functions:
  13. //
  14. #include <boost/math/special_functions/asinh.hpp>
  15. #include <boost/math/special_functions/acosh.hpp>
  16. #include <boost/math/special_functions/atanh.hpp>
  17. #include <boost/math/special_functions/cbrt.hpp>
  18. #include <boost/math/special_functions/expm1.hpp>
  19. #include <boost/math/special_functions/gamma.hpp>
  20. #ifdef BOOST_HAS_FLOAT128
  21. #include <quadmath.h>
  22. #endif
  23. namespace boost {
  24. namespace multiprecision {
  25. namespace backends {
  26. enum digit_base_type
  27. {
  28. digit_base_2 = 2,
  29. digit_base_10 = 10
  30. };
  31. #ifdef BOOST_MSVC
  32. #pragma warning(push)
  33. #pragma warning(disable : 4522 6326) // multiple assignment operators specified, comparison of two constants
  34. #endif
  35. namespace detail {
  36. template <class U>
  37. inline typename enable_if_c<is_unsigned<U>::value, bool>::type is_negative(U) { return false; }
  38. template <class S>
  39. inline typename disable_if_c<is_unsigned<S>::value, bool>::type is_negative(S s) { return s < 0; }
  40. template <class Float, int, bool = number_category<Float>::value == number_kind_floating_point>
  41. struct is_cpp_bin_float_implicitly_constructible_from_type
  42. {
  43. static const bool value = false;
  44. };
  45. template <class Float, int bit_count>
  46. struct is_cpp_bin_float_implicitly_constructible_from_type<Float, bit_count, true>
  47. {
  48. static const bool value = (std::numeric_limits<Float>::digits <= (int)bit_count) && (std::numeric_limits<Float>::radix == 2) && std::numeric_limits<Float>::is_specialized
  49. #ifdef BOOST_HAS_FLOAT128
  50. && !boost::is_same<Float, __float128>::value
  51. #endif
  52. && (is_floating_point<Float>::value || is_number<Float>::value);
  53. };
  54. template <class Float, int, bool = number_category<Float>::value == number_kind_floating_point>
  55. struct is_cpp_bin_float_explicitly_constructible_from_type
  56. {
  57. static const bool value = false;
  58. };
  59. template <class Float, int bit_count>
  60. struct is_cpp_bin_float_explicitly_constructible_from_type<Float, bit_count, true>
  61. {
  62. static const bool value = (std::numeric_limits<Float>::digits > (int)bit_count) && (std::numeric_limits<Float>::radix == 2) && std::numeric_limits<Float>::is_specialized
  63. #ifdef BOOST_HAS_FLOAT128
  64. && !boost::is_same<Float, __float128>::value
  65. #endif
  66. ;
  67. };
  68. } // namespace detail
  69. template <unsigned Digits, digit_base_type DigitBase = digit_base_10, class Allocator = void, class Exponent = int, Exponent MinExponent = 0, Exponent MaxExponent = 0>
  70. class cpp_bin_float
  71. {
  72. public:
  73. static const unsigned bit_count = DigitBase == digit_base_2 ? Digits : (Digits * 1000uL) / 301uL + (((Digits * 1000uL) % 301) ? 2u : 1u);
  74. typedef cpp_int_backend<is_void<Allocator>::value ? bit_count : 0, bit_count, is_void<Allocator>::value ? unsigned_magnitude : signed_magnitude, unchecked, Allocator> rep_type;
  75. typedef cpp_int_backend<is_void<Allocator>::value ? 2 * bit_count : 0, 2 * bit_count, is_void<Allocator>::value ? unsigned_magnitude : signed_magnitude, unchecked, Allocator> double_rep_type;
  76. typedef typename rep_type::signed_types signed_types;
  77. typedef typename rep_type::unsigned_types unsigned_types;
  78. typedef boost::mpl::list<float, double, long double> float_types;
  79. typedef Exponent exponent_type;
  80. static const exponent_type max_exponent_limit = boost::integer_traits<exponent_type>::const_max - 2 * static_cast<exponent_type>(bit_count);
  81. static const exponent_type min_exponent_limit = boost::integer_traits<exponent_type>::const_min + 2 * static_cast<exponent_type>(bit_count);
  82. BOOST_STATIC_ASSERT_MSG(MinExponent >= min_exponent_limit, "Template parameter MinExponent is too negative for our internal logic to function correctly, sorry!");
  83. BOOST_STATIC_ASSERT_MSG(MaxExponent <= max_exponent_limit, "Template parameter MaxExponent is too large for our internal logic to function correctly, sorry!");
  84. BOOST_STATIC_ASSERT_MSG(MinExponent <= 0, "Template parameter MinExponent can not be positive!");
  85. BOOST_STATIC_ASSERT_MSG(MaxExponent >= 0, "Template parameter MaxExponent can not be negative!");
  86. static const exponent_type max_exponent = MaxExponent == 0 ? max_exponent_limit : MaxExponent;
  87. static const exponent_type min_exponent = MinExponent == 0 ? min_exponent_limit : MinExponent;
  88. static const exponent_type exponent_zero = max_exponent + 1;
  89. static const exponent_type exponent_infinity = max_exponent + 2;
  90. static const exponent_type exponent_nan = max_exponent + 3;
  91. private:
  92. rep_type m_data;
  93. exponent_type m_exponent;
  94. bool m_sign;
  95. public:
  96. cpp_bin_float() BOOST_MP_NOEXCEPT_IF(noexcept(rep_type())) : m_data(), m_exponent(exponent_zero), m_sign(false) {}
  97. cpp_bin_float(const cpp_bin_float& o) BOOST_MP_NOEXCEPT_IF(noexcept(rep_type(std::declval<const rep_type&>())))
  98. : m_data(o.m_data), m_exponent(o.m_exponent), m_sign(o.m_sign) {}
  99. template <unsigned D, digit_base_type B, class A, class E, E MinE, E MaxE>
  100. cpp_bin_float(const cpp_bin_float<D, B, A, E, MinE, MaxE>& o, typename boost::enable_if_c<(bit_count >= cpp_bin_float<D, B, A, E, MinE, MaxE>::bit_count)>::type const* = 0)
  101. {
  102. *this = o;
  103. }
  104. template <unsigned D, digit_base_type B, class A, class E, E MinE, E MaxE>
  105. explicit cpp_bin_float(const cpp_bin_float<D, B, A, E, MinE, MaxE>& o, typename boost::disable_if_c<(bit_count >= cpp_bin_float<D, B, A, E, MinE, MaxE>::bit_count)>::type const* = 0)
  106. : m_exponent(o.exponent()), m_sign(o.sign())
  107. {
  108. *this = o;
  109. }
  110. template <class Float>
  111. cpp_bin_float(const Float& f,
  112. typename boost::enable_if_c<detail::is_cpp_bin_float_implicitly_constructible_from_type<Float, bit_count>::value>::type const* = 0)
  113. : m_data(), m_exponent(0), m_sign(false)
  114. {
  115. this->assign_float(f);
  116. }
  117. template <class Float>
  118. explicit cpp_bin_float(const Float& f,
  119. typename boost::enable_if_c<detail::is_cpp_bin_float_explicitly_constructible_from_type<Float, bit_count>::value>::type const* = 0)
  120. : m_data(), m_exponent(0), m_sign(false)
  121. {
  122. this->assign_float(f);
  123. }
  124. #ifdef BOOST_HAS_FLOAT128
  125. template <class Float>
  126. cpp_bin_float(const Float& f,
  127. typename boost::enable_if_c<
  128. boost::is_same<Float, __float128>::value && ((int)bit_count >= 113)>::type const* = 0)
  129. : m_data(), m_exponent(0), m_sign(false)
  130. {
  131. this->assign_float(f);
  132. }
  133. template <class Float>
  134. explicit cpp_bin_float(const Float& f,
  135. typename boost::enable_if_c<
  136. boost::is_same<Float, __float128>::value && ((int)bit_count < 113)>::type const* = 0)
  137. : m_data(), m_exponent(0), m_sign(false)
  138. {
  139. this->assign_float(f);
  140. }
  141. #endif
  142. cpp_bin_float& operator=(const cpp_bin_float& o) BOOST_MP_NOEXCEPT_IF(noexcept(std::declval<rep_type&>() = std::declval<const rep_type&>()))
  143. {
  144. m_data = o.m_data;
  145. m_exponent = o.m_exponent;
  146. m_sign = o.m_sign;
  147. return *this;
  148. }
  149. template <unsigned D, digit_base_type B, class A, class E, E MinE, E MaxE>
  150. cpp_bin_float& operator=(const cpp_bin_float<D, B, A, E, MinE, MaxE>& f)
  151. {
  152. switch (eval_fpclassify(f))
  153. {
  154. case FP_ZERO:
  155. m_data = limb_type(0);
  156. m_sign = f.sign();
  157. m_exponent = exponent_zero;
  158. break;
  159. case FP_NAN:
  160. m_data = limb_type(0);
  161. m_sign = false;
  162. m_exponent = exponent_nan;
  163. break;
  164. ;
  165. case FP_INFINITE:
  166. m_data = limb_type(0);
  167. m_sign = f.sign();
  168. m_exponent = exponent_infinity;
  169. break;
  170. default:
  171. typename cpp_bin_float<D, B, A, E, MinE, MaxE>::rep_type b(f.bits());
  172. this->exponent() = f.exponent() + (E)bit_count - (E)cpp_bin_float<D, B, A, E, MinE, MaxE>::bit_count;
  173. this->sign() = f.sign();
  174. copy_and_round(*this, b);
  175. }
  176. return *this;
  177. }
  178. #ifdef BOOST_HAS_FLOAT128
  179. template <class Float>
  180. typename boost::enable_if_c<
  181. (number_category<Float>::value == number_kind_floating_point)
  182. //&& (std::numeric_limits<Float>::digits <= (int)bit_count)
  183. && ((std::numeric_limits<Float>::radix == 2) || (boost::is_same<Float, __float128>::value)),
  184. cpp_bin_float&>::type
  185. operator=(const Float& f)
  186. #else
  187. template <class Float>
  188. typename boost::enable_if_c<
  189. (number_category<Float>::value == number_kind_floating_point)
  190. //&& (std::numeric_limits<Float>::digits <= (int)bit_count)
  191. && (std::numeric_limits<Float>::radix == 2),
  192. cpp_bin_float&>::type
  193. operator=(const Float& f)
  194. #endif
  195. {
  196. return assign_float(f);
  197. }
  198. #ifdef BOOST_HAS_FLOAT128
  199. template <class Float>
  200. typename boost::enable_if_c<boost::is_same<Float, __float128>::value, cpp_bin_float&>::type assign_float(Float f)
  201. {
  202. using default_ops::eval_add;
  203. typedef typename boost::multiprecision::detail::canonical<int, cpp_bin_float>::type bf_int_type;
  204. if (f == 0)
  205. {
  206. m_data = limb_type(0);
  207. m_sign = (signbitq(f) > 0);
  208. m_exponent = exponent_zero;
  209. return *this;
  210. }
  211. else if (isnanq(f))
  212. {
  213. m_data = limb_type(0);
  214. m_sign = false;
  215. m_exponent = exponent_nan;
  216. return *this;
  217. }
  218. else if (isinfq(f))
  219. {
  220. m_data = limb_type(0);
  221. m_sign = (f < 0);
  222. m_exponent = exponent_infinity;
  223. return *this;
  224. }
  225. if (f < 0)
  226. {
  227. *this = -f;
  228. this->negate();
  229. return *this;
  230. }
  231. typedef typename mpl::front<unsigned_types>::type ui_type;
  232. m_data = static_cast<ui_type>(0u);
  233. m_sign = false;
  234. m_exponent = 0;
  235. static const int bits = sizeof(int) * CHAR_BIT - 1;
  236. int e;
  237. f = frexpq(f, &e);
  238. while (f)
  239. {
  240. f = ldexpq(f, bits);
  241. e -= bits;
  242. int ipart = (int)truncq(f);
  243. f -= ipart;
  244. m_exponent += bits;
  245. cpp_bin_float t;
  246. t = static_cast<bf_int_type>(ipart);
  247. eval_add(*this, t);
  248. }
  249. m_exponent += static_cast<Exponent>(e);
  250. return *this;
  251. }
  252. #endif
  253. #ifdef BOOST_HAS_FLOAT128
  254. template <class Float>
  255. typename boost::enable_if_c<is_floating_point<Float>::value && !is_same<Float, __float128>::value, cpp_bin_float&>::type assign_float(Float f)
  256. #else
  257. template <class Float>
  258. typename boost::enable_if_c<is_floating_point<Float>::value, cpp_bin_float&>::type assign_float(Float f)
  259. #endif
  260. {
  261. BOOST_MATH_STD_USING
  262. using default_ops::eval_add;
  263. typedef typename boost::multiprecision::detail::canonical<int, cpp_bin_float>::type bf_int_type;
  264. switch ((boost::math::fpclassify)(f))
  265. {
  266. case FP_ZERO:
  267. m_data = limb_type(0);
  268. m_sign = ((boost::math::signbit)(f) > 0);
  269. m_exponent = exponent_zero;
  270. return *this;
  271. case FP_NAN:
  272. m_data = limb_type(0);
  273. m_sign = false;
  274. m_exponent = exponent_nan;
  275. return *this;
  276. case FP_INFINITE:
  277. m_data = limb_type(0);
  278. m_sign = (f < 0);
  279. m_exponent = exponent_infinity;
  280. return *this;
  281. }
  282. if (f < 0)
  283. {
  284. *this = -f;
  285. this->negate();
  286. return *this;
  287. }
  288. typedef typename mpl::front<unsigned_types>::type ui_type;
  289. m_data = static_cast<ui_type>(0u);
  290. m_sign = false;
  291. m_exponent = 0;
  292. static const int bits = sizeof(int) * CHAR_BIT - 1;
  293. int e;
  294. f = frexp(f, &e);
  295. while (f)
  296. {
  297. f = ldexp(f, bits);
  298. e -= bits;
  299. #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
  300. int ipart = itrunc(f);
  301. #else
  302. int ipart = static_cast<int>(f);
  303. #endif
  304. f -= ipart;
  305. m_exponent += bits;
  306. cpp_bin_float t;
  307. t = static_cast<bf_int_type>(ipart);
  308. eval_add(*this, t);
  309. }
  310. m_exponent += static_cast<Exponent>(e);
  311. return *this;
  312. }
  313. template <class Float>
  314. typename boost::enable_if_c<
  315. (number_category<Float>::value == number_kind_floating_point) && !boost::is_floating_point<Float>::value && (number_category<Float>::value == number_kind_floating_point),
  316. cpp_bin_float&>::type
  317. assign_float(Float f)
  318. {
  319. BOOST_MATH_STD_USING
  320. using default_ops::eval_add;
  321. using default_ops::eval_convert_to;
  322. using default_ops::eval_get_sign;
  323. using default_ops::eval_subtract;
  324. typedef typename boost::multiprecision::detail::canonical<int, Float>::type f_int_type;
  325. typedef typename boost::multiprecision::detail::canonical<int, cpp_bin_float>::type bf_int_type;
  326. switch (eval_fpclassify(f))
  327. {
  328. case FP_ZERO:
  329. m_data = limb_type(0);
  330. m_sign = (eval_get_sign(f) > 0);
  331. m_exponent = exponent_zero;
  332. return *this;
  333. case FP_NAN:
  334. m_data = limb_type(0);
  335. m_sign = false;
  336. m_exponent = exponent_nan;
  337. return *this;
  338. case FP_INFINITE:
  339. m_data = limb_type(0);
  340. m_sign = eval_get_sign(f) < 0;
  341. m_exponent = exponent_infinity;
  342. return *this;
  343. }
  344. if (eval_get_sign(f) < 0)
  345. {
  346. f.negate();
  347. *this = f;
  348. this->negate();
  349. return *this;
  350. }
  351. typedef typename mpl::front<unsigned_types>::type ui_type;
  352. m_data = static_cast<ui_type>(0u);
  353. m_sign = false;
  354. m_exponent = 0;
  355. static const int bits = sizeof(int) * CHAR_BIT - 1;
  356. int e;
  357. eval_frexp(f, f, &e);
  358. while (eval_get_sign(f) != 0)
  359. {
  360. eval_ldexp(f, f, bits);
  361. e -= bits;
  362. int ipart;
  363. eval_convert_to(&ipart, f);
  364. eval_subtract(f, static_cast<f_int_type>(ipart));
  365. m_exponent += bits;
  366. eval_add(*this, static_cast<bf_int_type>(ipart));
  367. }
  368. m_exponent += e;
  369. if (m_exponent > max_exponent)
  370. m_exponent = exponent_infinity;
  371. if (m_exponent < min_exponent)
  372. {
  373. m_data = limb_type(0u);
  374. m_exponent = exponent_zero;
  375. m_sign = (eval_get_sign(f) > 0);
  376. }
  377. else if (eval_get_sign(m_data) == 0)
  378. {
  379. m_exponent = exponent_zero;
  380. m_sign = (eval_get_sign(f) > 0);
  381. }
  382. return *this;
  383. }
  384. template <class B, expression_template_option et>
  385. cpp_bin_float& assign_float(const number<B, et>& f)
  386. {
  387. return assign_float(f.backend());
  388. }
  389. template <class I>
  390. typename boost::enable_if<is_integral<I>, cpp_bin_float&>::type operator=(const I& i)
  391. {
  392. using default_ops::eval_bit_test;
  393. if (!i)
  394. {
  395. m_data = static_cast<limb_type>(0);
  396. m_exponent = exponent_zero;
  397. m_sign = false;
  398. }
  399. else
  400. {
  401. typedef typename make_unsigned<I>::type ui_type;
  402. ui_type fi = static_cast<ui_type>(boost::multiprecision::detail::unsigned_abs(i));
  403. typedef typename boost::multiprecision::detail::canonical<ui_type, rep_type>::type ar_type;
  404. m_data = static_cast<ar_type>(fi);
  405. unsigned shift = msb(fi);
  406. if (shift >= bit_count)
  407. {
  408. m_exponent = static_cast<Exponent>(shift);
  409. m_data = static_cast<ar_type>(fi >> (shift + 1 - bit_count));
  410. }
  411. else
  412. {
  413. m_exponent = static_cast<Exponent>(shift);
  414. eval_left_shift(m_data, bit_count - shift - 1);
  415. }
  416. BOOST_ASSERT(eval_bit_test(m_data, bit_count - 1));
  417. m_sign = detail::is_negative(i);
  418. }
  419. return *this;
  420. }
  421. cpp_bin_float& operator=(const char* s);
  422. void swap(cpp_bin_float& o) BOOST_NOEXCEPT
  423. {
  424. m_data.swap(o.m_data);
  425. std::swap(m_exponent, o.m_exponent);
  426. std::swap(m_sign, o.m_sign);
  427. }
  428. std::string str(std::streamsize dig, std::ios_base::fmtflags f) const;
  429. void negate()
  430. {
  431. if (m_exponent != exponent_nan)
  432. m_sign = !m_sign;
  433. }
  434. int compare(const cpp_bin_float& o) const BOOST_NOEXCEPT
  435. {
  436. if (m_sign != o.m_sign)
  437. return (m_exponent == exponent_zero) && (m_exponent == o.m_exponent) ? 0 : m_sign ? -1 : 1;
  438. int result;
  439. if (m_exponent == exponent_nan)
  440. return -1;
  441. else if (m_exponent != o.m_exponent)
  442. {
  443. if (m_exponent == exponent_zero)
  444. result = -1;
  445. else if (o.m_exponent == exponent_zero)
  446. result = 1;
  447. else
  448. result = m_exponent > o.m_exponent ? 1 : -1;
  449. }
  450. else
  451. result = m_data.compare(o.m_data);
  452. if (m_sign)
  453. result = -result;
  454. return result;
  455. }
  456. template <class A>
  457. int compare(const A& o) const BOOST_NOEXCEPT
  458. {
  459. cpp_bin_float b;
  460. b = o;
  461. return compare(b);
  462. }
  463. rep_type& bits() { return m_data; }
  464. const rep_type& bits() const { return m_data; }
  465. exponent_type& exponent() { return m_exponent; }
  466. const exponent_type& exponent() const { return m_exponent; }
  467. bool& sign() { return m_sign; }
  468. const bool& sign() const { return m_sign; }
  469. void check_invariants()
  470. {
  471. using default_ops::eval_bit_test;
  472. using default_ops::eval_is_zero;
  473. if ((m_exponent <= max_exponent) && (m_exponent >= min_exponent))
  474. {
  475. BOOST_ASSERT(eval_bit_test(m_data, bit_count - 1));
  476. }
  477. else
  478. {
  479. BOOST_ASSERT(m_exponent > max_exponent);
  480. BOOST_ASSERT(m_exponent <= exponent_nan);
  481. BOOST_ASSERT(eval_is_zero(m_data));
  482. }
  483. }
  484. template <class Archive>
  485. void serialize(Archive& ar, const unsigned int /*version*/)
  486. {
  487. ar& boost::make_nvp("data", m_data);
  488. ar& boost::make_nvp("exponent", m_exponent);
  489. ar& boost::make_nvp("sign", m_sign);
  490. }
  491. };
  492. #ifdef BOOST_MSVC
  493. #pragma warning(pop)
  494. #endif
  495. template <unsigned Digits, digit_base_type DigitBase, class Allocator, class Exponent, Exponent MinE, Exponent MaxE, class Int>
  496. inline void copy_and_round(cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>& res, Int& arg, int bits_to_keep = cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count)
  497. {
  498. // Precondition: exponent of res must have been set before this function is called
  499. // as we may need to adjust it based on how many bits_to_keep in arg are set.
  500. using default_ops::eval_bit_test;
  501. using default_ops::eval_get_sign;
  502. using default_ops::eval_increment;
  503. using default_ops::eval_left_shift;
  504. using default_ops::eval_lsb;
  505. using default_ops::eval_msb;
  506. using default_ops::eval_right_shift;
  507. // cancellation may have resulted in arg being all zeros:
  508. if (eval_get_sign(arg) == 0)
  509. {
  510. res.exponent() = cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_zero;
  511. res.sign() = false;
  512. res.bits() = static_cast<limb_type>(0u);
  513. return;
  514. }
  515. int msb = eval_msb(arg);
  516. if (static_cast<int>(bits_to_keep) > msb + 1)
  517. {
  518. // Must have had cancellation in subtraction,
  519. // or be converting from a narrower type, so shift left:
  520. res.bits() = arg;
  521. eval_left_shift(res.bits(), bits_to_keep - msb - 1);
  522. res.exponent() -= static_cast<Exponent>(bits_to_keep - msb - 1);
  523. }
  524. else if (static_cast<int>(bits_to_keep) < msb + 1)
  525. {
  526. // We have more bits_to_keep than we need, so round as required,
  527. // first get the rounding bit:
  528. bool roundup = eval_bit_test(arg, msb - bits_to_keep);
  529. // Then check for a tie:
  530. if (roundup && (msb - bits_to_keep == (int)eval_lsb(arg)))
  531. {
  532. // Ties round towards even:
  533. if (!eval_bit_test(arg, msb - bits_to_keep + 1))
  534. roundup = false;
  535. }
  536. // Shift off the bits_to_keep we don't need:
  537. eval_right_shift(arg, msb - bits_to_keep + 1);
  538. res.exponent() += static_cast<Exponent>(msb - bits_to_keep + 1);
  539. if (roundup)
  540. {
  541. eval_increment(arg);
  542. if (bits_to_keep)
  543. {
  544. if (eval_bit_test(arg, bits_to_keep))
  545. {
  546. // This happens very very rairly, all the bits left after
  547. // truncation must be 1's and we're rounding up an order of magnitude:
  548. eval_right_shift(arg, 1u);
  549. ++res.exponent();
  550. }
  551. }
  552. else
  553. {
  554. // We get here when bits_to_keep is zero but we're rounding up,
  555. // as a result we end up with a single digit that is a 1:
  556. ++bits_to_keep;
  557. }
  558. }
  559. if (bits_to_keep != cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count)
  560. {
  561. // Normalize result when we're rounding to fewer bits than we can hold, only happens in conversions
  562. // to narrower types:
  563. eval_left_shift(arg, cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count - bits_to_keep);
  564. res.exponent() -= static_cast<Exponent>(cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count - bits_to_keep);
  565. }
  566. res.bits() = arg;
  567. }
  568. else
  569. {
  570. res.bits() = arg;
  571. }
  572. if (!bits_to_keep && !res.bits().limbs()[0])
  573. {
  574. // We're keeping zero bits and did not round up, so result is zero:
  575. res.exponent() = cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_zero;
  576. return;
  577. }
  578. // Result must be normalized:
  579. BOOST_ASSERT(((int)eval_msb(res.bits()) == cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count - 1));
  580. if (res.exponent() > cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::max_exponent)
  581. {
  582. // Overflow:
  583. res.exponent() = cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_infinity;
  584. res.bits() = static_cast<limb_type>(0u);
  585. }
  586. else if (res.exponent() < cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::min_exponent)
  587. {
  588. // Underflow:
  589. res.exponent() = cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_zero;
  590. res.bits() = static_cast<limb_type>(0u);
  591. }
  592. }
  593. template <unsigned Digits, digit_base_type DigitBase, class Allocator, class Exponent, Exponent MinE, Exponent MaxE>
  594. inline void do_eval_add(cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>& res, const cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>& a, const cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>& b)
  595. {
  596. if (a.exponent() < b.exponent())
  597. {
  598. bool s = a.sign();
  599. do_eval_add(res, b, a);
  600. if (res.sign() != s)
  601. res.negate();
  602. return;
  603. }
  604. using default_ops::eval_add;
  605. using default_ops::eval_bit_test;
  606. typedef typename cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_type exponent_type;
  607. typename cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::double_rep_type dt;
  608. // Special cases first:
  609. switch (a.exponent())
  610. {
  611. case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_zero:
  612. {
  613. bool s = a.sign();
  614. res = b;
  615. res.sign() = s;
  616. return;
  617. }
  618. case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_infinity:
  619. if (b.exponent() == cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_nan)
  620. res = b;
  621. else
  622. res = a;
  623. return; // result is still infinite.
  624. case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_nan:
  625. res = a;
  626. return; // result is still a NaN.
  627. }
  628. switch (b.exponent())
  629. {
  630. case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_zero:
  631. res = a;
  632. return;
  633. case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_infinity:
  634. res = b;
  635. if (res.sign())
  636. res.negate();
  637. return; // result is infinite.
  638. case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_nan:
  639. res = b;
  640. return; // result is a NaN.
  641. }
  642. BOOST_STATIC_ASSERT(boost::integer_traits<exponent_type>::const_max - cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count > cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::max_exponent);
  643. bool s = a.sign();
  644. dt = a.bits();
  645. if (a.exponent() > (int)cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count + b.exponent())
  646. {
  647. res.exponent() = a.exponent();
  648. }
  649. else
  650. {
  651. exponent_type e_diff = a.exponent() - b.exponent();
  652. BOOST_ASSERT(e_diff >= 0);
  653. eval_left_shift(dt, e_diff);
  654. res.exponent() = a.exponent() - e_diff;
  655. eval_add(dt, b.bits());
  656. }
  657. copy_and_round(res, dt);
  658. res.check_invariants();
  659. if (res.sign() != s)
  660. res.negate();
  661. }
  662. template <unsigned Digits, digit_base_type DigitBase, class Allocator, class Exponent, Exponent MinE, Exponent MaxE>
  663. inline void do_eval_subtract(cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>& res, const cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>& a, const cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>& b)
  664. {
  665. using default_ops::eval_bit_test;
  666. using default_ops::eval_decrement;
  667. using default_ops::eval_subtract;
  668. typename cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::double_rep_type dt;
  669. // Special cases first:
  670. switch (a.exponent())
  671. {
  672. case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_zero:
  673. if (b.exponent() == cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_nan)
  674. res = std::numeric_limits<number<cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE> > >::quiet_NaN().backend();
  675. else
  676. {
  677. bool s = a.sign();
  678. res = b;
  679. if (res.exponent() == cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_zero)
  680. res.sign() = false;
  681. else if (res.sign() == s)
  682. res.negate();
  683. }
  684. return;
  685. case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_infinity:
  686. if ((b.exponent() == cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_nan) || (b.exponent() == cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_infinity))
  687. res = std::numeric_limits<number<cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE> > >::quiet_NaN().backend();
  688. else
  689. res = a;
  690. return;
  691. case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_nan:
  692. res = a;
  693. return; // result is still a NaN.
  694. }
  695. switch (b.exponent())
  696. {
  697. case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_zero:
  698. res = a;
  699. return;
  700. case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_infinity:
  701. res.exponent() = cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_infinity;
  702. res.sign() = !a.sign();
  703. res.bits() = static_cast<limb_type>(0u);
  704. return; // result is a NaN.
  705. case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_nan:
  706. res = b;
  707. return; // result is still a NaN.
  708. }
  709. bool s = a.sign();
  710. if ((a.exponent() > b.exponent()) || ((a.exponent() == b.exponent()) && a.bits().compare(b.bits()) >= 0))
  711. {
  712. dt = a.bits();
  713. if (a.exponent() <= (int)cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count + b.exponent())
  714. {
  715. typename cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_type e_diff = a.exponent() - b.exponent();
  716. eval_left_shift(dt, e_diff);
  717. res.exponent() = a.exponent() - e_diff;
  718. eval_subtract(dt, b.bits());
  719. }
  720. else if (a.exponent() == (int)cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count + b.exponent() + 1)
  721. {
  722. if (eval_lsb(b.bits()) != cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count - 1)
  723. {
  724. eval_left_shift(dt, 1);
  725. eval_decrement(dt);
  726. res.exponent() = a.exponent() - 1;
  727. }
  728. else
  729. res.exponent() = a.exponent();
  730. }
  731. else
  732. res.exponent() = a.exponent();
  733. }
  734. else
  735. {
  736. dt = b.bits();
  737. if (b.exponent() <= (int)cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count + a.exponent())
  738. {
  739. typename cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_type e_diff = a.exponent() - b.exponent();
  740. eval_left_shift(dt, -e_diff);
  741. res.exponent() = b.exponent() + e_diff;
  742. eval_subtract(dt, a.bits());
  743. }
  744. else if (b.exponent() == (int)cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count + a.exponent() + 1)
  745. {
  746. if (eval_lsb(a.bits()) != cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count - 1)
  747. {
  748. eval_left_shift(dt, 1);
  749. eval_decrement(dt);
  750. res.exponent() = b.exponent() - 1;
  751. }
  752. else
  753. res.exponent() = b.exponent();
  754. }
  755. else
  756. res.exponent() = b.exponent();
  757. s = !s;
  758. }
  759. copy_and_round(res, dt);
  760. if (res.exponent() == cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_zero)
  761. res.sign() = false;
  762. else if (res.sign() != s)
  763. res.negate();
  764. res.check_invariants();
  765. }
  766. template <unsigned Digits, digit_base_type DigitBase, class Allocator, class Exponent, Exponent MinE, Exponent MaxE>
  767. inline void eval_add(cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>& res, const cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>& a, const cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>& b)
  768. {
  769. if (a.sign() == b.sign())
  770. do_eval_add(res, a, b);
  771. else
  772. do_eval_subtract(res, a, b);
  773. }
  774. template <unsigned Digits, digit_base_type DigitBase, class Allocator, class Exponent, Exponent MinE, Exponent MaxE>
  775. inline void eval_add(cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>& res, const cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>& a)
  776. {
  777. return eval_add(res, res, a);
  778. }
  779. template <unsigned Digits, digit_base_type DigitBase, class Allocator, class Exponent, Exponent MinE, Exponent MaxE>
  780. inline void eval_subtract(cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>& res, const cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>& a, const cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>& b)
  781. {
  782. if (a.sign() != b.sign())
  783. do_eval_add(res, a, b);
  784. else
  785. do_eval_subtract(res, a, b);
  786. }
  787. template <unsigned Digits, digit_base_type DigitBase, class Allocator, class Exponent, Exponent MinE, Exponent MaxE>
  788. inline void eval_subtract(cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>& res, const cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>& a)
  789. {
  790. return eval_subtract(res, res, a);
  791. }
  792. template <unsigned Digits, digit_base_type DigitBase, class Allocator, class Exponent, Exponent MinE, Exponent MaxE>
  793. inline void eval_multiply(cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>& res, const cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>& a, const cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>& b)
  794. {
  795. using default_ops::eval_bit_test;
  796. using default_ops::eval_multiply;
  797. // Special cases first:
  798. switch (a.exponent())
  799. {
  800. case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_zero:
  801. {
  802. if (b.exponent() == cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_nan)
  803. res = b;
  804. else if (b.exponent() == cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_infinity)
  805. res = std::numeric_limits<number<cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE> > >::quiet_NaN().backend();
  806. else
  807. {
  808. bool s = a.sign() != b.sign();
  809. res = a;
  810. res.sign() = s;
  811. }
  812. return;
  813. }
  814. case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_infinity:
  815. switch (b.exponent())
  816. {
  817. case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_zero:
  818. res = std::numeric_limits<number<cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE> > >::quiet_NaN().backend();
  819. break;
  820. case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_nan:
  821. res = b;
  822. break;
  823. default:
  824. bool s = a.sign() != b.sign();
  825. res = a;
  826. res.sign() = s;
  827. break;
  828. }
  829. return;
  830. case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_nan:
  831. res = a;
  832. return;
  833. }
  834. if (b.exponent() > cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::max_exponent)
  835. {
  836. bool s = a.sign() != b.sign();
  837. res = b;
  838. res.sign() = s;
  839. return;
  840. }
  841. if ((a.exponent() > 0) && (b.exponent() > 0))
  842. {
  843. if (cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::max_exponent + 2 - a.exponent() < b.exponent())
  844. {
  845. // We will certainly overflow:
  846. bool s = a.sign() != b.sign();
  847. res.exponent() = cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_infinity;
  848. res.sign() = s;
  849. res.bits() = static_cast<limb_type>(0u);
  850. return;
  851. }
  852. }
  853. if ((a.exponent() < 0) && (b.exponent() < 0))
  854. {
  855. if (cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::min_exponent - 2 - a.exponent() > b.exponent())
  856. {
  857. // We will certainly underflow:
  858. res.exponent() = cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_zero;
  859. res.sign() = a.sign() != b.sign();
  860. res.bits() = static_cast<limb_type>(0u);
  861. return;
  862. }
  863. }
  864. typename cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::double_rep_type dt;
  865. eval_multiply(dt, a.bits(), b.bits());
  866. res.exponent() = a.exponent() + b.exponent() - (Exponent)cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count + 1;
  867. copy_and_round(res, dt);
  868. res.check_invariants();
  869. res.sign() = a.sign() != b.sign();
  870. }
  871. template <unsigned Digits, digit_base_type DigitBase, class Allocator, class Exponent, Exponent MinE, Exponent MaxE>
  872. inline void eval_multiply(cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>& res, const cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>& a)
  873. {
  874. eval_multiply(res, res, a);
  875. }
  876. template <unsigned Digits, digit_base_type DigitBase, class Allocator, class Exponent, Exponent MinE, Exponent MaxE, class U>
  877. inline typename enable_if_c<is_unsigned<U>::value>::type eval_multiply(cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>& res, const cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>& a, const U& b)
  878. {
  879. using default_ops::eval_bit_test;
  880. using default_ops::eval_multiply;
  881. // Special cases first:
  882. switch (a.exponent())
  883. {
  884. case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_zero:
  885. {
  886. bool s = a.sign();
  887. res = a;
  888. res.sign() = s;
  889. return;
  890. }
  891. case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_infinity:
  892. if (b == 0)
  893. res = std::numeric_limits<number<cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE> > >::quiet_NaN().backend();
  894. else
  895. res = a;
  896. return;
  897. case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_nan:
  898. res = a;
  899. return;
  900. }
  901. typename cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::double_rep_type dt;
  902. typedef typename boost::multiprecision::detail::canonical<U, typename cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::double_rep_type>::type canon_ui_type;
  903. eval_multiply(dt, a.bits(), static_cast<canon_ui_type>(b));
  904. res.exponent() = a.exponent();
  905. copy_and_round(res, dt);
  906. res.check_invariants();
  907. res.sign() = a.sign();
  908. }
  909. template <unsigned Digits, digit_base_type DigitBase, class Allocator, class Exponent, Exponent MinE, Exponent MaxE, class U>
  910. inline typename enable_if_c<is_unsigned<U>::value>::type eval_multiply(cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>& res, const U& b)
  911. {
  912. eval_multiply(res, res, b);
  913. }
  914. template <unsigned Digits, digit_base_type DigitBase, class Allocator, class Exponent, Exponent MinE, Exponent MaxE, class S>
  915. inline typename enable_if_c<is_signed<S>::value>::type eval_multiply(cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>& res, const cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>& a, const S& b)
  916. {
  917. typedef typename make_unsigned<S>::type ui_type;
  918. eval_multiply(res, a, static_cast<ui_type>(boost::multiprecision::detail::unsigned_abs(b)));
  919. if (b < 0)
  920. res.negate();
  921. }
  922. template <unsigned Digits, digit_base_type DigitBase, class Allocator, class Exponent, Exponent MinE, Exponent MaxE, class S>
  923. inline typename enable_if_c<is_signed<S>::value>::type eval_multiply(cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>& res, const S& b)
  924. {
  925. eval_multiply(res, res, b);
  926. }
  927. template <unsigned Digits, digit_base_type DigitBase, class Allocator, class Exponent, Exponent MinE, Exponent MaxE>
  928. inline void eval_divide(cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>& res, const cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>& u, const cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>& v)
  929. {
  930. #ifdef BOOST_MSVC
  931. #pragma warning(push)
  932. #pragma warning(disable : 6326) // comparison of two constants
  933. #endif
  934. using default_ops::eval_bit_test;
  935. using default_ops::eval_get_sign;
  936. using default_ops::eval_increment;
  937. using default_ops::eval_qr;
  938. using default_ops::eval_subtract;
  939. //
  940. // Special cases first:
  941. //
  942. switch (u.exponent())
  943. {
  944. case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_zero:
  945. {
  946. switch (v.exponent())
  947. {
  948. case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_zero:
  949. case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_nan:
  950. res = std::numeric_limits<number<cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE> > >::quiet_NaN().backend();
  951. return;
  952. }
  953. bool s = u.sign() != v.sign();
  954. res = u;
  955. res.sign() = s;
  956. return;
  957. }
  958. case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_infinity:
  959. {
  960. switch (v.exponent())
  961. {
  962. case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_infinity:
  963. case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_nan:
  964. res = std::numeric_limits<number<cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE> > >::quiet_NaN().backend();
  965. return;
  966. }
  967. bool s = u.sign() != v.sign();
  968. res = u;
  969. res.sign() = s;
  970. return;
  971. }
  972. case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_nan:
  973. res = std::numeric_limits<number<cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE> > >::quiet_NaN().backend();
  974. return;
  975. }
  976. switch (v.exponent())
  977. {
  978. case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_zero:
  979. {
  980. bool s = u.sign() != v.sign();
  981. res = std::numeric_limits<number<cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE> > >::infinity().backend();
  982. res.sign() = s;
  983. return;
  984. }
  985. case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_infinity:
  986. res.exponent() = cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_zero;
  987. res.bits() = limb_type(0);
  988. res.sign() = u.sign() != v.sign();
  989. return;
  990. case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_nan:
  991. res = std::numeric_limits<number<cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE> > >::quiet_NaN().backend();
  992. return;
  993. }
  994. // We can scale u and v so that both are integers, then perform integer
  995. // division to obtain quotient q and remainder r, such that:
  996. //
  997. // q * v + r = u
  998. //
  999. // and hense:
  1000. //
  1001. // q + r/v = u/v
  1002. //
  1003. // From this, assuming q has cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count
  1004. // bits we only need to determine whether
  1005. // r/v is less than, equal to, or greater than 0.5 to determine rounding -
  1006. // this we can do with a shift and comparison.
  1007. //
  1008. // We can set the exponent and sign of the result up front:
  1009. //
  1010. if ((v.exponent() < 0) && (u.exponent() > 0))
  1011. {
  1012. // Check for overflow:
  1013. if (cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::max_exponent + v.exponent() < u.exponent() - 1)
  1014. {
  1015. res.exponent() = cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_infinity;
  1016. res.sign() = u.sign() != v.sign();
  1017. res.bits() = static_cast<limb_type>(0u);
  1018. return;
  1019. }
  1020. }
  1021. else if ((v.exponent() > 0) && (u.exponent() < 0))
  1022. {
  1023. // Check for underflow:
  1024. if (cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::min_exponent + v.exponent() > u.exponent())
  1025. {
  1026. // We will certainly underflow:
  1027. res.exponent() = cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_zero;
  1028. res.sign() = u.sign() != v.sign();
  1029. res.bits() = static_cast<limb_type>(0u);
  1030. return;
  1031. }
  1032. }
  1033. res.exponent() = u.exponent() - v.exponent() - 1;
  1034. res.sign() = u.sign() != v.sign();
  1035. //
  1036. // Now get the quotient and remainder:
  1037. //
  1038. typename cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::double_rep_type t(u.bits()), t2(v.bits()), q, r;
  1039. eval_left_shift(t, cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count);
  1040. eval_qr(t, t2, q, r);
  1041. //
  1042. // We now have either "cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count"
  1043. // or "cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count+1" significant
  1044. // bits in q.
  1045. //
  1046. static const unsigned limb_bits = sizeof(limb_type) * CHAR_BIT;
  1047. if (eval_bit_test(q, cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count))
  1048. {
  1049. //
  1050. // OK we have cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count+1 bits,
  1051. // so we already have rounding info,
  1052. // we just need to changes things if the last bit is 1 and either the
  1053. // remainder is non-zero (ie we do not have a tie) or the quotient would
  1054. // be odd if it were shifted to the correct number of bits (ie a tiebreak).
  1055. //
  1056. BOOST_ASSERT((eval_msb(q) == cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count));
  1057. if ((q.limbs()[0] & 1u) && (eval_get_sign(r) || (q.limbs()[0] & 2u)))
  1058. {
  1059. eval_increment(q);
  1060. }
  1061. }
  1062. else
  1063. {
  1064. //
  1065. // We have exactly "cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count" bits in q.
  1066. // Get rounding info, which we can get by comparing 2r with v.
  1067. // We want to call copy_and_round to handle rounding and general cleanup,
  1068. // so we'll left shift q and add some fake digits on the end to represent
  1069. // how we'll be rounding.
  1070. //
  1071. BOOST_ASSERT((eval_msb(q) == cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count - 1));
  1072. static const unsigned lshift = (cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count < limb_bits) ? 2 : limb_bits;
  1073. eval_left_shift(q, lshift);
  1074. res.exponent() -= lshift;
  1075. eval_left_shift(r, 1u);
  1076. int c = r.compare(v.bits());
  1077. if (c == 0)
  1078. q.limbs()[0] |= static_cast<limb_type>(1u) << (lshift - 1);
  1079. else if (c > 0)
  1080. q.limbs()[0] |= (static_cast<limb_type>(1u) << (lshift - 1)) + static_cast<limb_type>(1u);
  1081. }
  1082. copy_and_round(res, q);
  1083. #ifdef BOOST_MSVC
  1084. #pragma warning(pop)
  1085. #endif
  1086. }
  1087. template <unsigned Digits, digit_base_type DigitBase, class Allocator, class Exponent, Exponent MinE, Exponent MaxE>
  1088. inline void eval_divide(cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>& res, const cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>& arg)
  1089. {
  1090. eval_divide(res, res, arg);
  1091. }
  1092. template <unsigned Digits, digit_base_type DigitBase, class Allocator, class Exponent, Exponent MinE, Exponent MaxE, class U>
  1093. inline typename enable_if_c<is_unsigned<U>::value>::type eval_divide(cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>& res, const cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>& u, const U& v)
  1094. {
  1095. #ifdef BOOST_MSVC
  1096. #pragma warning(push)
  1097. #pragma warning(disable : 6326) // comparison of two constants
  1098. #endif
  1099. using default_ops::eval_bit_test;
  1100. using default_ops::eval_get_sign;
  1101. using default_ops::eval_increment;
  1102. using default_ops::eval_qr;
  1103. using default_ops::eval_subtract;
  1104. //
  1105. // Special cases first:
  1106. //
  1107. switch (u.exponent())
  1108. {
  1109. case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_zero:
  1110. {
  1111. if (v == 0)
  1112. {
  1113. res = std::numeric_limits<number<cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE> > >::quiet_NaN().backend();
  1114. return;
  1115. }
  1116. bool s = u.sign() != (v < 0);
  1117. res = u;
  1118. res.sign() = s;
  1119. return;
  1120. }
  1121. case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_infinity:
  1122. res = u;
  1123. return;
  1124. case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_nan:
  1125. res = std::numeric_limits<number<cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE> > >::quiet_NaN().backend();
  1126. return;
  1127. }
  1128. if (v == 0)
  1129. {
  1130. bool s = u.sign();
  1131. res = std::numeric_limits<number<cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE> > >::infinity().backend();
  1132. res.sign() = s;
  1133. return;
  1134. }
  1135. // We can scale u and v so that both are integers, then perform integer
  1136. // division to obtain quotient q and remainder r, such that:
  1137. //
  1138. // q * v + r = u
  1139. //
  1140. // and hense:
  1141. //
  1142. // q + r/v = u/v
  1143. //
  1144. // From this, assuming q has "cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count" cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count, we only need to determine whether
  1145. // r/v is less than, equal to, or greater than 0.5 to determine rounding -
  1146. // this we can do with a shift and comparison.
  1147. //
  1148. // We can set the exponent and sign of the result up front:
  1149. //
  1150. int gb = msb(v);
  1151. res.exponent() = u.exponent() - static_cast<Exponent>(gb) - static_cast<Exponent>(1);
  1152. res.sign() = u.sign();
  1153. //
  1154. // Now get the quotient and remainder:
  1155. //
  1156. typename cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::double_rep_type t(u.bits()), q, r;
  1157. eval_left_shift(t, gb + 1);
  1158. eval_qr(t, number<typename cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::double_rep_type>::canonical_value(v), q, r);
  1159. //
  1160. // We now have either "cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count" or "cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count+1" significant cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count in q.
  1161. //
  1162. static const unsigned limb_bits = sizeof(limb_type) * CHAR_BIT;
  1163. if (eval_bit_test(q, cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count))
  1164. {
  1165. //
  1166. // OK we have cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count+1 cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count, so we already have rounding info,
  1167. // we just need to changes things if the last bit is 1 and the
  1168. // remainder is non-zero (ie we do not have a tie).
  1169. //
  1170. BOOST_ASSERT((eval_msb(q) == cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count));
  1171. if ((q.limbs()[0] & 1u) && eval_get_sign(r))
  1172. {
  1173. eval_increment(q);
  1174. }
  1175. }
  1176. else
  1177. {
  1178. //
  1179. // We have exactly "cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count" cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count in q.
  1180. // Get rounding info, which we can get by comparing 2r with v.
  1181. // We want to call copy_and_round to handle rounding and general cleanup,
  1182. // so we'll left shift q and add some fake cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count on the end to represent
  1183. // how we'll be rounding.
  1184. //
  1185. BOOST_ASSERT((eval_msb(q) == cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count - 1));
  1186. static const unsigned lshift = cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count < limb_bits ? 2 : limb_bits;
  1187. eval_left_shift(q, lshift);
  1188. res.exponent() -= lshift;
  1189. eval_left_shift(r, 1u);
  1190. int c = r.compare(number<typename cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::double_rep_type>::canonical_value(v));
  1191. if (c == 0)
  1192. q.limbs()[0] |= static_cast<limb_type>(1u) << (lshift - 1);
  1193. else if (c > 0)
  1194. q.limbs()[0] |= (static_cast<limb_type>(1u) << (lshift - 1)) + static_cast<limb_type>(1u);
  1195. }
  1196. copy_and_round(res, q);
  1197. #ifdef BOOST_MSVC
  1198. #pragma warning(pop)
  1199. #endif
  1200. }
  1201. template <unsigned Digits, digit_base_type DigitBase, class Allocator, class Exponent, Exponent MinE, Exponent MaxE, class U>
  1202. inline typename enable_if_c<is_unsigned<U>::value>::type eval_divide(cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>& res, const U& v)
  1203. {
  1204. eval_divide(res, res, v);
  1205. }
  1206. template <unsigned Digits, digit_base_type DigitBase, class Allocator, class Exponent, Exponent MinE, Exponent MaxE, class S>
  1207. inline typename enable_if_c<is_signed<S>::value>::type eval_divide(cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>& res, const cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>& u, const S& v)
  1208. {
  1209. typedef typename make_unsigned<S>::type ui_type;
  1210. eval_divide(res, u, static_cast<ui_type>(boost::multiprecision::detail::unsigned_abs(v)));
  1211. if (v < 0)
  1212. res.negate();
  1213. }
  1214. template <unsigned Digits, digit_base_type DigitBase, class Allocator, class Exponent, Exponent MinE, Exponent MaxE, class S>
  1215. inline typename enable_if_c<is_signed<S>::value>::type eval_divide(cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>& res, const S& v)
  1216. {
  1217. eval_divide(res, res, v);
  1218. }
  1219. template <unsigned Digits, digit_base_type DigitBase, class Allocator, class Exponent, Exponent MinE, Exponent MaxE>
  1220. inline int eval_get_sign(const cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>& arg)
  1221. {
  1222. return arg.exponent() == cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_zero ? 0 : arg.sign() ? -1 : 1;
  1223. }
  1224. template <unsigned Digits, digit_base_type DigitBase, class Allocator, class Exponent, Exponent MinE, Exponent MaxE>
  1225. inline bool eval_is_zero(const cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>& arg)
  1226. {
  1227. return arg.exponent() == cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_zero;
  1228. }
  1229. template <unsigned Digits, digit_base_type DigitBase, class Allocator, class Exponent, Exponent MinE, Exponent MaxE>
  1230. inline bool eval_eq(const cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>& a, cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>& b)
  1231. {
  1232. if (a.exponent() == b.exponent())
  1233. {
  1234. if (a.exponent() == cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_zero)
  1235. return true;
  1236. return (a.sign() == b.sign()) && (a.bits().compare(b.bits()) == 0) && (a.exponent() != cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_nan);
  1237. }
  1238. return false;
  1239. }
  1240. template <unsigned Digits, digit_base_type DigitBase, class Allocator, class Exponent, Exponent MinE, Exponent MaxE>
  1241. inline void eval_convert_to(boost::long_long_type* res, const cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>& arg)
  1242. {
  1243. switch (arg.exponent())
  1244. {
  1245. case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_zero:
  1246. *res = 0;
  1247. return;
  1248. case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_nan:
  1249. BOOST_THROW_EXCEPTION(std::runtime_error("Could not convert NaN to integer."));
  1250. case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_infinity:
  1251. *res = (std::numeric_limits<boost::long_long_type>::max)();
  1252. if (arg.sign())
  1253. *res = -*res;
  1254. return;
  1255. }
  1256. typedef typename mpl::if_c<sizeof(typename cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_type) < sizeof(int), int, typename cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_type>::type shift_type;
  1257. typename cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::rep_type man(arg.bits());
  1258. shift_type shift = (shift_type)cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count - 1 - arg.exponent();
  1259. if (shift > (shift_type)cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count - 1)
  1260. {
  1261. *res = 0;
  1262. return;
  1263. }
  1264. if (arg.sign() && (arg.compare((std::numeric_limits<boost::long_long_type>::min)()) <= 0))
  1265. {
  1266. *res = (std::numeric_limits<boost::long_long_type>::min)();
  1267. return;
  1268. }
  1269. else if (!arg.sign() && (arg.compare((std::numeric_limits<boost::long_long_type>::max)()) >= 0))
  1270. {
  1271. *res = (std::numeric_limits<boost::long_long_type>::max)();
  1272. return;
  1273. }
  1274. if (shift < 0)
  1275. {
  1276. if (cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count - shift <= std::numeric_limits<boost::long_long_type>::digits)
  1277. {
  1278. // We have more bits in long_long_type than the float, so it's OK to left shift:
  1279. eval_convert_to(res, man);
  1280. *res <<= -shift;
  1281. }
  1282. else
  1283. {
  1284. *res = (std::numeric_limits<boost::long_long_type>::max)();
  1285. return;
  1286. }
  1287. }
  1288. else
  1289. {
  1290. eval_right_shift(man, shift);
  1291. eval_convert_to(res, man);
  1292. }
  1293. if (arg.sign())
  1294. {
  1295. *res = -*res;
  1296. }
  1297. }
  1298. template <unsigned Digits, digit_base_type DigitBase, class Allocator, class Exponent, Exponent MinE, Exponent MaxE>
  1299. inline void eval_convert_to(boost::ulong_long_type* res, const cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>& arg)
  1300. {
  1301. switch (arg.exponent())
  1302. {
  1303. case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_zero:
  1304. *res = 0;
  1305. return;
  1306. case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_nan:
  1307. BOOST_THROW_EXCEPTION(std::runtime_error("Could not convert NaN to integer."));
  1308. case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_infinity:
  1309. *res = (std::numeric_limits<boost::ulong_long_type>::max)();
  1310. return;
  1311. }
  1312. typename cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::rep_type man(arg.bits());
  1313. typedef typename mpl::if_c<sizeof(typename cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_type) < sizeof(int), int, typename cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_type>::type shift_type;
  1314. shift_type shift = (shift_type)cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count - 1 - arg.exponent();
  1315. if (shift > (shift_type)cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count - 1)
  1316. {
  1317. *res = 0;
  1318. return;
  1319. }
  1320. else if (shift < 0)
  1321. {
  1322. if (cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count - shift <= std::numeric_limits<boost::ulong_long_type>::digits)
  1323. {
  1324. // We have more bits in ulong_long_type than the float, so it's OK to left shift:
  1325. eval_convert_to(res, man);
  1326. *res <<= -shift;
  1327. return;
  1328. }
  1329. *res = (std::numeric_limits<boost::ulong_long_type>::max)();
  1330. return;
  1331. }
  1332. eval_right_shift(man, shift);
  1333. eval_convert_to(res, man);
  1334. }
  1335. template <class Float, unsigned Digits, digit_base_type DigitBase, class Allocator, class Exponent, Exponent MinE, Exponent MaxE>
  1336. inline typename boost::enable_if_c<boost::is_float<Float>::value>::type eval_convert_to(Float* res, const cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>& original_arg)
  1337. {
  1338. typedef cpp_bin_float<std::numeric_limits<Float>::digits, digit_base_2, void, Exponent, MinE, MaxE> conv_type;
  1339. typedef typename common_type<typename conv_type::exponent_type, int>::type common_exp_type;
  1340. //
  1341. // Special cases first:
  1342. //
  1343. switch (original_arg.exponent())
  1344. {
  1345. case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_zero:
  1346. *res = 0;
  1347. if (original_arg.sign())
  1348. *res = -*res;
  1349. return;
  1350. case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_nan:
  1351. *res = std::numeric_limits<Float>::quiet_NaN();
  1352. return;
  1353. case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_infinity:
  1354. *res = (std::numeric_limits<Float>::infinity)();
  1355. if (original_arg.sign())
  1356. *res = -*res;
  1357. return;
  1358. }
  1359. //
  1360. // Check for super large exponent that must be converted to infinity:
  1361. //
  1362. if (original_arg.exponent() > std::numeric_limits<Float>::max_exponent)
  1363. {
  1364. *res = std::numeric_limits<Float>::has_infinity ? std::numeric_limits<Float>::infinity() : (std::numeric_limits<Float>::max)();
  1365. if (original_arg.sign())
  1366. *res = -*res;
  1367. return;
  1368. }
  1369. //
  1370. // Figure out how many digits we will have in our result,
  1371. // allowing for a possibly denormalized result:
  1372. //
  1373. common_exp_type digits_to_round_to = std::numeric_limits<Float>::digits;
  1374. if (original_arg.exponent() < std::numeric_limits<Float>::min_exponent - 1)
  1375. {
  1376. common_exp_type diff = original_arg.exponent();
  1377. diff -= std::numeric_limits<Float>::min_exponent - 1;
  1378. digits_to_round_to += diff;
  1379. }
  1380. if (digits_to_round_to < 0)
  1381. {
  1382. // Result must be zero:
  1383. *res = 0;
  1384. if (original_arg.sign())
  1385. *res = -*res;
  1386. return;
  1387. }
  1388. //
  1389. // Perform rounding first, then afterwards extract the digits:
  1390. //
  1391. cpp_bin_float<std::numeric_limits<Float>::digits, digit_base_2, Allocator, Exponent, MinE, MaxE> arg;
  1392. typename cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::rep_type bits(original_arg.bits());
  1393. arg.exponent() = original_arg.exponent();
  1394. copy_and_round(arg, bits, (int)digits_to_round_to);
  1395. common_exp_type e = arg.exponent();
  1396. e -= cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count - 1;
  1397. static const unsigned limbs_needed = std::numeric_limits<Float>::digits / (sizeof(*arg.bits().limbs()) * CHAR_BIT) + (std::numeric_limits<Float>::digits % (sizeof(*arg.bits().limbs()) * CHAR_BIT) ? 1 : 0);
  1398. unsigned first_limb_needed = arg.bits().size() - limbs_needed;
  1399. *res = 0;
  1400. e += first_limb_needed * sizeof(*arg.bits().limbs()) * CHAR_BIT;
  1401. while (first_limb_needed < arg.bits().size())
  1402. {
  1403. *res += std::ldexp(static_cast<Float>(arg.bits().limbs()[first_limb_needed]), static_cast<int>(e));
  1404. ++first_limb_needed;
  1405. e += sizeof(*arg.bits().limbs()) * CHAR_BIT;
  1406. }
  1407. if (original_arg.sign())
  1408. *res = -*res;
  1409. }
  1410. template <unsigned Digits, digit_base_type DigitBase, class Allocator, class Exponent, Exponent MinE, Exponent MaxE>
  1411. inline void eval_frexp(cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>& res, const cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>& arg, Exponent* e)
  1412. {
  1413. switch (arg.exponent())
  1414. {
  1415. case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_zero:
  1416. case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_nan:
  1417. case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_infinity:
  1418. *e = 0;
  1419. res = arg;
  1420. return;
  1421. }
  1422. res = arg;
  1423. *e = arg.exponent() + 1;
  1424. res.exponent() = -1;
  1425. }
  1426. template <unsigned Digits, digit_base_type DigitBase, class Allocator, class Exponent, Exponent MinE, Exponent MaxE, class I>
  1427. inline void eval_frexp(cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>& res, const cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>& arg, I* pe)
  1428. {
  1429. Exponent e;
  1430. eval_frexp(res, arg, &e);
  1431. if ((e > (std::numeric_limits<I>::max)()) || (e < (std::numeric_limits<I>::min)()))
  1432. {
  1433. BOOST_THROW_EXCEPTION(std::runtime_error("Exponent was outside of the range of the argument type to frexp."));
  1434. }
  1435. *pe = static_cast<I>(e);
  1436. }
  1437. template <unsigned Digits, digit_base_type DigitBase, class Allocator, class Exponent, Exponent MinE, Exponent MaxE>
  1438. inline void eval_ldexp(cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>& res, const cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>& arg, Exponent e)
  1439. {
  1440. switch (arg.exponent())
  1441. {
  1442. case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_zero:
  1443. case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_nan:
  1444. case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_infinity:
  1445. res = arg;
  1446. return;
  1447. }
  1448. if ((e > 0) && (cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::max_exponent - e < arg.exponent()))
  1449. {
  1450. // Overflow:
  1451. res = std::numeric_limits<number<cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE> > >::infinity().backend();
  1452. res.sign() = arg.sign();
  1453. }
  1454. else if ((e < 0) && (cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::min_exponent - e > arg.exponent()))
  1455. {
  1456. // Underflow:
  1457. res = limb_type(0);
  1458. }
  1459. else
  1460. {
  1461. res = arg;
  1462. res.exponent() += e;
  1463. }
  1464. }
  1465. template <unsigned Digits, digit_base_type DigitBase, class Allocator, class Exponent, Exponent MinE, Exponent MaxE, class I>
  1466. inline typename enable_if_c<is_unsigned<I>::value>::type eval_ldexp(cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>& res, const cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>& arg, I e)
  1467. {
  1468. typedef typename make_signed<I>::type si_type;
  1469. if (e > static_cast<I>((std::numeric_limits<si_type>::max)()))
  1470. res = std::numeric_limits<number<cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE> > >::infinity().backend();
  1471. else
  1472. eval_ldexp(res, arg, static_cast<si_type>(e));
  1473. }
  1474. template <unsigned Digits, digit_base_type DigitBase, class Allocator, class Exponent, Exponent MinE, Exponent MaxE, class I>
  1475. inline typename enable_if_c<is_signed<I>::value>::type eval_ldexp(cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>& res, const cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>& arg, I e)
  1476. {
  1477. if ((e > (std::numeric_limits<Exponent>::max)()) || (e < (std::numeric_limits<Exponent>::min)()))
  1478. {
  1479. res = std::numeric_limits<number<cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE> > >::infinity().backend();
  1480. if (e < 0)
  1481. res.negate();
  1482. }
  1483. else
  1484. eval_ldexp(res, arg, static_cast<Exponent>(e));
  1485. }
  1486. /*
  1487. * Sign manipulation
  1488. */
  1489. template <unsigned Digits, digit_base_type DigitBase, class Allocator, class Exponent, Exponent MinE, Exponent MaxE>
  1490. inline void eval_abs(cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>& res, const cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>& arg)
  1491. {
  1492. res = arg;
  1493. res.sign() = false;
  1494. }
  1495. template <unsigned Digits, digit_base_type DigitBase, class Allocator, class Exponent, Exponent MinE, Exponent MaxE>
  1496. inline void eval_fabs(cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>& res, const cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>& arg)
  1497. {
  1498. res = arg;
  1499. res.sign() = false;
  1500. }
  1501. template <unsigned Digits, digit_base_type DigitBase, class Allocator, class Exponent, Exponent MinE, Exponent MaxE>
  1502. inline int eval_fpclassify(const cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>& arg)
  1503. {
  1504. switch (arg.exponent())
  1505. {
  1506. case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_zero:
  1507. return FP_ZERO;
  1508. case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_infinity:
  1509. return FP_INFINITE;
  1510. case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_nan:
  1511. return FP_NAN;
  1512. }
  1513. return FP_NORMAL;
  1514. }
  1515. template <unsigned Digits, digit_base_type DigitBase, class Allocator, class Exponent, Exponent MinE, Exponent MaxE>
  1516. inline void eval_sqrt(cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>& res, const cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>& arg)
  1517. {
  1518. using default_ops::eval_bit_test;
  1519. using default_ops::eval_increment;
  1520. using default_ops::eval_integer_sqrt;
  1521. switch (arg.exponent())
  1522. {
  1523. case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_nan:
  1524. errno = EDOM;
  1525. // fallthrough...
  1526. case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_zero:
  1527. res = arg;
  1528. return;
  1529. case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_infinity:
  1530. if (arg.sign())
  1531. {
  1532. res = std::numeric_limits<number<cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE> > >::quiet_NaN().backend();
  1533. errno = EDOM;
  1534. }
  1535. else
  1536. res = arg;
  1537. return;
  1538. }
  1539. if (arg.sign())
  1540. {
  1541. res = std::numeric_limits<number<cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE> > >::quiet_NaN().backend();
  1542. errno = EDOM;
  1543. return;
  1544. }
  1545. typename cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::double_rep_type t(arg.bits()), r, s;
  1546. eval_left_shift(t, arg.exponent() & 1 ? cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count : cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count - 1);
  1547. eval_integer_sqrt(s, r, t);
  1548. if (!eval_bit_test(s, cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count))
  1549. {
  1550. // We have exactly the right number of cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count in the result, round as required:
  1551. if (s.compare(r) < 0)
  1552. {
  1553. eval_increment(s);
  1554. }
  1555. }
  1556. typename cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_type ae = arg.exponent();
  1557. res.exponent() = ae / 2;
  1558. if ((ae & 1) && (ae < 0))
  1559. --res.exponent();
  1560. copy_and_round(res, s);
  1561. }
  1562. template <unsigned Digits, digit_base_type DigitBase, class Allocator, class Exponent, Exponent MinE, Exponent MaxE>
  1563. inline void eval_floor(cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>& res, const cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>& arg)
  1564. {
  1565. using default_ops::eval_increment;
  1566. switch (arg.exponent())
  1567. {
  1568. case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_nan:
  1569. errno = EDOM;
  1570. // fallthrough...
  1571. case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_zero:
  1572. case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_infinity:
  1573. res = arg;
  1574. return;
  1575. }
  1576. typedef typename mpl::if_c<sizeof(typename cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_type) < sizeof(int), int, typename cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_type>::type shift_type;
  1577. shift_type shift =
  1578. (shift_type)cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count - arg.exponent() - 1;
  1579. if ((arg.exponent() > (shift_type)cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::max_exponent) || (shift <= 0))
  1580. {
  1581. // Either arg is already an integer, or a special value:
  1582. res = arg;
  1583. return;
  1584. }
  1585. if (shift >= (shift_type)cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count)
  1586. {
  1587. res = static_cast<signed_limb_type>(arg.sign() ? -1 : 0);
  1588. return;
  1589. }
  1590. bool fractional = (shift_type)eval_lsb(arg.bits()) < shift;
  1591. res = arg;
  1592. eval_right_shift(res.bits(), shift);
  1593. if (fractional && res.sign())
  1594. {
  1595. eval_increment(res.bits());
  1596. if (eval_msb(res.bits()) != cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count - 1 - shift)
  1597. {
  1598. // Must have extended result by one bit in the increment:
  1599. --shift;
  1600. ++res.exponent();
  1601. }
  1602. }
  1603. eval_left_shift(res.bits(), shift);
  1604. }
  1605. template <unsigned Digits, digit_base_type DigitBase, class Allocator, class Exponent, Exponent MinE, Exponent MaxE>
  1606. inline void eval_ceil(cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>& res, const cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>& arg)
  1607. {
  1608. using default_ops::eval_increment;
  1609. switch (arg.exponent())
  1610. {
  1611. case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_infinity:
  1612. errno = EDOM;
  1613. // fallthrough...
  1614. case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_zero:
  1615. case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_nan:
  1616. res = arg;
  1617. return;
  1618. }
  1619. typedef typename mpl::if_c<sizeof(typename cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_type) < sizeof(int), int, typename cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_type>::type shift_type;
  1620. shift_type shift = (shift_type)cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count - arg.exponent() - 1;
  1621. if ((arg.exponent() > (shift_type)cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::max_exponent) || (shift <= 0))
  1622. {
  1623. // Either arg is already an integer, or a special value:
  1624. res = arg;
  1625. return;
  1626. }
  1627. if (shift >= (shift_type)cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count)
  1628. {
  1629. bool s = arg.sign(); // takes care of signed zeros
  1630. res = static_cast<signed_limb_type>(arg.sign() ? 0 : 1);
  1631. res.sign() = s;
  1632. return;
  1633. }
  1634. bool fractional = (shift_type)eval_lsb(arg.bits()) < shift;
  1635. res = arg;
  1636. eval_right_shift(res.bits(), shift);
  1637. if (fractional && !res.sign())
  1638. {
  1639. eval_increment(res.bits());
  1640. if (eval_msb(res.bits()) != cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count - 1 - shift)
  1641. {
  1642. // Must have extended result by one bit in the increment:
  1643. --shift;
  1644. ++res.exponent();
  1645. }
  1646. }
  1647. eval_left_shift(res.bits(), shift);
  1648. }
  1649. template <unsigned D1, backends::digit_base_type B1, class A1, class E1, E1 M1, E1 M2>
  1650. int eval_signbit(const cpp_bin_float<D1, B1, A1, E1, M1, M2>& val)
  1651. {
  1652. return val.sign();
  1653. }
  1654. template <unsigned D1, backends::digit_base_type B1, class A1, class E1, E1 M1, E1 M2>
  1655. inline std::size_t hash_value(const cpp_bin_float<D1, B1, A1, E1, M1, M2>& val)
  1656. {
  1657. std::size_t result = hash_value(val.bits());
  1658. boost::hash_combine(result, val.exponent());
  1659. boost::hash_combine(result, val.sign());
  1660. return result;
  1661. }
  1662. } // namespace backends
  1663. #ifdef BOOST_NO_SFINAE_EXPR
  1664. namespace detail {
  1665. template <unsigned D1, backends::digit_base_type B1, class A1, class E1, E1 M1, E1 M2, unsigned D2, backends::digit_base_type B2, class A2, class E2, E2 M3, E2 M4>
  1666. struct is_explicitly_convertible<backends::cpp_bin_float<D1, B1, A1, E1, M1, M2>, backends::cpp_bin_float<D2, B2, A2, E2, M3, M4> > : public mpl::true_
  1667. {};
  1668. template <class FloatT, unsigned D2, backends::digit_base_type B2, class A2, class E2, E2 M3, E2 M4>
  1669. struct is_explicitly_convertible<FloatT, backends::cpp_bin_float<D2, B2, A2, E2, M3, M4> > : public boost::is_floating_point<FloatT>
  1670. {};
  1671. } // namespace detail
  1672. #endif
  1673. template <unsigned Digits, boost::multiprecision::backends::digit_base_type DigitBase, class Exponent, Exponent MinE, Exponent MaxE, class Allocator, boost::multiprecision::expression_template_option ExpressionTemplates>
  1674. inline boost::multiprecision::number<boost::multiprecision::backends::cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>, ExpressionTemplates>
  1675. copysign BOOST_PREVENT_MACRO_SUBSTITUTION(
  1676. const boost::multiprecision::number<boost::multiprecision::backends::cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>, ExpressionTemplates>& a,
  1677. const boost::multiprecision::number<boost::multiprecision::backends::cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>, ExpressionTemplates>& b)
  1678. {
  1679. boost::multiprecision::number<boost::multiprecision::backends::cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>, ExpressionTemplates> res(a);
  1680. res.backend().sign() = b.backend().sign();
  1681. return res;
  1682. }
  1683. using backends::cpp_bin_float;
  1684. using backends::digit_base_10;
  1685. using backends::digit_base_2;
  1686. template <unsigned Digits, backends::digit_base_type DigitBase, class Exponent, Exponent MinE, Exponent MaxE, class Allocator>
  1687. struct number_category<cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE> > : public boost::mpl::int_<boost::multiprecision::number_kind_floating_point>
  1688. {};
  1689. template <unsigned Digits, backends::digit_base_type DigitBase, class Allocator, class Exponent, Exponent MinE, Exponent MaxE>
  1690. struct expression_template_default<cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE> >
  1691. {
  1692. static const expression_template_option value = is_void<Allocator>::value ? et_off : et_on;
  1693. };
  1694. typedef number<backends::cpp_bin_float<50> > cpp_bin_float_50;
  1695. typedef number<backends::cpp_bin_float<100> > cpp_bin_float_100;
  1696. typedef number<backends::cpp_bin_float<24, backends::digit_base_2, void, boost::int16_t, -126, 127>, et_off> cpp_bin_float_single;
  1697. typedef number<backends::cpp_bin_float<53, backends::digit_base_2, void, boost::int16_t, -1022, 1023>, et_off> cpp_bin_float_double;
  1698. typedef number<backends::cpp_bin_float<64, backends::digit_base_2, void, boost::int16_t, -16382, 16383>, et_off> cpp_bin_float_double_extended;
  1699. typedef number<backends::cpp_bin_float<113, backends::digit_base_2, void, boost::int16_t, -16382, 16383>, et_off> cpp_bin_float_quad;
  1700. typedef number<backends::cpp_bin_float<237, backends::digit_base_2, void, boost::int32_t, -262142, 262143>, et_off> cpp_bin_float_oct;
  1701. } // namespace multiprecision
  1702. namespace math {
  1703. using boost::multiprecision::copysign;
  1704. using boost::multiprecision::signbit;
  1705. } // namespace math
  1706. } // namespace boost
  1707. #include <boost/multiprecision/cpp_bin_float/io.hpp>
  1708. #include <boost/multiprecision/cpp_bin_float/transcendental.hpp>
  1709. namespace std {
  1710. //
  1711. // numeric_limits [partial] specializations for the types declared in this header:
  1712. //
  1713. template <unsigned Digits, boost::multiprecision::backends::digit_base_type DigitBase, class Allocator, class Exponent, Exponent MinE, Exponent MaxE, boost::multiprecision::expression_template_option ExpressionTemplates>
  1714. class numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>, ExpressionTemplates> >
  1715. {
  1716. typedef boost::multiprecision::number<boost::multiprecision::cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>, ExpressionTemplates> number_type;
  1717. public:
  1718. BOOST_STATIC_CONSTEXPR bool is_specialized = true;
  1719. static number_type(min)()
  1720. {
  1721. initializer.do_nothing();
  1722. static std::pair<bool, number_type> value;
  1723. if (!value.first)
  1724. {
  1725. value.first = true;
  1726. typedef typename boost::mpl::front<typename number_type::backend_type::unsigned_types>::type ui_type;
  1727. value.second.backend() = ui_type(1u);
  1728. value.second.backend().exponent() = boost::multiprecision::cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::min_exponent;
  1729. }
  1730. return value.second;
  1731. }
  1732. static number_type(max)()
  1733. {
  1734. initializer.do_nothing();
  1735. static std::pair<bool, number_type> value;
  1736. if (!value.first)
  1737. {
  1738. value.first = true;
  1739. if (boost::is_void<Allocator>::value)
  1740. eval_complement(value.second.backend().bits(), value.second.backend().bits());
  1741. else
  1742. {
  1743. // We jump through hoops here using the backend type directly just to keep VC12 happy
  1744. // (ie compiler workaround, for very strange compiler bug):
  1745. using boost::multiprecision::default_ops::eval_add;
  1746. using boost::multiprecision::default_ops::eval_decrement;
  1747. using boost::multiprecision::default_ops::eval_left_shift;
  1748. typedef typename number_type::backend_type::rep_type int_backend_type;
  1749. typedef typename boost::mpl::front<typename int_backend_type::unsigned_types>::type ui_type;
  1750. int_backend_type i;
  1751. i = ui_type(1u);
  1752. eval_left_shift(i, boost::multiprecision::cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count - 1);
  1753. int_backend_type j(i);
  1754. eval_decrement(i);
  1755. eval_add(j, i);
  1756. value.second.backend().bits() = j;
  1757. }
  1758. value.second.backend().exponent() = boost::multiprecision::cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::max_exponent;
  1759. }
  1760. return value.second;
  1761. }
  1762. BOOST_STATIC_CONSTEXPR number_type lowest()
  1763. {
  1764. return -(max)();
  1765. }
  1766. BOOST_STATIC_CONSTEXPR int digits = boost::multiprecision::cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count;
  1767. BOOST_STATIC_CONSTEXPR int digits10 = (digits - 1) * 301 / 1000;
  1768. // Is this really correct???
  1769. BOOST_STATIC_CONSTEXPR int max_digits10 = (digits * 301 / 1000) + 3;
  1770. BOOST_STATIC_CONSTEXPR bool is_signed = true;
  1771. BOOST_STATIC_CONSTEXPR bool is_integer = false;
  1772. BOOST_STATIC_CONSTEXPR bool is_exact = false;
  1773. BOOST_STATIC_CONSTEXPR int radix = 2;
  1774. static number_type epsilon()
  1775. {
  1776. initializer.do_nothing();
  1777. static std::pair<bool, number_type> value;
  1778. if (!value.first)
  1779. {
  1780. // We jump through hoops here just to keep VC12 happy (ie compiler workaround, for very strange compiler bug):
  1781. typedef typename boost::mpl::front<typename number_type::backend_type::unsigned_types>::type ui_type;
  1782. value.first = true;
  1783. value.second.backend() = ui_type(1u);
  1784. value.second = ldexp(value.second, 1 - (int)digits);
  1785. }
  1786. return value.second;
  1787. }
  1788. // What value should this be????
  1789. static number_type round_error()
  1790. {
  1791. // returns 0.5
  1792. initializer.do_nothing();
  1793. static std::pair<bool, number_type> value;
  1794. if (!value.first)
  1795. {
  1796. value.first = true;
  1797. // We jump through hoops here just to keep VC12 happy (ie compiler workaround, for very strange compiler bug):
  1798. typedef typename boost::mpl::front<typename number_type::backend_type::unsigned_types>::type ui_type;
  1799. value.second.backend() = ui_type(1u);
  1800. value.second = ldexp(value.second, -1);
  1801. }
  1802. return value.second;
  1803. }
  1804. BOOST_STATIC_CONSTEXPR typename boost::multiprecision::cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_type min_exponent = boost::multiprecision::cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::min_exponent;
  1805. BOOST_STATIC_CONSTEXPR typename boost::multiprecision::cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_type min_exponent10 = (min_exponent / 1000) * 301L;
  1806. BOOST_STATIC_CONSTEXPR typename boost::multiprecision::cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_type max_exponent = boost::multiprecision::cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::max_exponent;
  1807. BOOST_STATIC_CONSTEXPR typename boost::multiprecision::cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_type max_exponent10 = (max_exponent / 1000) * 301L;
  1808. BOOST_STATIC_CONSTEXPR bool has_infinity = true;
  1809. BOOST_STATIC_CONSTEXPR bool has_quiet_NaN = true;
  1810. BOOST_STATIC_CONSTEXPR bool has_signaling_NaN = false;
  1811. BOOST_STATIC_CONSTEXPR float_denorm_style has_denorm = denorm_absent;
  1812. BOOST_STATIC_CONSTEXPR bool has_denorm_loss = false;
  1813. static number_type infinity()
  1814. {
  1815. initializer.do_nothing();
  1816. static std::pair<bool, number_type> value;
  1817. if (!value.first)
  1818. {
  1819. value.first = true;
  1820. value.second.backend().exponent() = boost::multiprecision::cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_infinity;
  1821. }
  1822. return value.second;
  1823. }
  1824. static number_type quiet_NaN()
  1825. {
  1826. initializer.do_nothing();
  1827. static std::pair<bool, number_type> value;
  1828. if (!value.first)
  1829. {
  1830. value.first = true;
  1831. value.second.backend().exponent() = boost::multiprecision::cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_nan;
  1832. }
  1833. return value.second;
  1834. }
  1835. BOOST_STATIC_CONSTEXPR number_type signaling_NaN()
  1836. {
  1837. return number_type(0);
  1838. }
  1839. BOOST_STATIC_CONSTEXPR number_type denorm_min() { return number_type(0); }
  1840. BOOST_STATIC_CONSTEXPR bool is_iec559 = false;
  1841. BOOST_STATIC_CONSTEXPR bool is_bounded = true;
  1842. BOOST_STATIC_CONSTEXPR bool is_modulo = false;
  1843. BOOST_STATIC_CONSTEXPR bool traps = true;
  1844. BOOST_STATIC_CONSTEXPR bool tinyness_before = false;
  1845. BOOST_STATIC_CONSTEXPR float_round_style round_style = round_to_nearest;
  1846. private:
  1847. struct data_initializer
  1848. {
  1849. data_initializer()
  1850. {
  1851. std::numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE> > >::epsilon();
  1852. std::numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE> > >::round_error();
  1853. (std::numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE> > >::min)();
  1854. (std::numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE> > >::max)();
  1855. std::numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE> > >::infinity();
  1856. std::numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE> > >::quiet_NaN();
  1857. }
  1858. void do_nothing() const {}
  1859. };
  1860. static const data_initializer initializer;
  1861. };
  1862. template <unsigned Digits, boost::multiprecision::backends::digit_base_type DigitBase, class Allocator, class Exponent, Exponent MinE, Exponent MaxE, boost::multiprecision::expression_template_option ExpressionTemplates>
  1863. const typename numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>, ExpressionTemplates> >::data_initializer numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>, ExpressionTemplates> >::initializer;
  1864. #ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
  1865. template <unsigned Digits, boost::multiprecision::backends::digit_base_type DigitBase, class Allocator, class Exponent, Exponent MinE, Exponent MaxE, boost::multiprecision::expression_template_option ExpressionTemplates>
  1866. BOOST_CONSTEXPR_OR_CONST int numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>, ExpressionTemplates> >::digits;
  1867. template <unsigned Digits, boost::multiprecision::backends::digit_base_type DigitBase, class Allocator, class Exponent, Exponent MinE, Exponent MaxE, boost::multiprecision::expression_template_option ExpressionTemplates>
  1868. BOOST_CONSTEXPR_OR_CONST int numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>, ExpressionTemplates> >::digits10;
  1869. template <unsigned Digits, boost::multiprecision::backends::digit_base_type DigitBase, class Allocator, class Exponent, Exponent MinE, Exponent MaxE, boost::multiprecision::expression_template_option ExpressionTemplates>
  1870. BOOST_CONSTEXPR_OR_CONST int numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>, ExpressionTemplates> >::max_digits10;
  1871. template <unsigned Digits, boost::multiprecision::backends::digit_base_type DigitBase, class Allocator, class Exponent, Exponent MinE, Exponent MaxE, boost::multiprecision::expression_template_option ExpressionTemplates>
  1872. BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>, ExpressionTemplates> >::is_signed;
  1873. template <unsigned Digits, boost::multiprecision::backends::digit_base_type DigitBase, class Allocator, class Exponent, Exponent MinE, Exponent MaxE, boost::multiprecision::expression_template_option ExpressionTemplates>
  1874. BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>, ExpressionTemplates> >::is_integer;
  1875. template <unsigned Digits, boost::multiprecision::backends::digit_base_type DigitBase, class Allocator, class Exponent, Exponent MinE, Exponent MaxE, boost::multiprecision::expression_template_option ExpressionTemplates>
  1876. BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>, ExpressionTemplates> >::is_exact;
  1877. template <unsigned Digits, boost::multiprecision::backends::digit_base_type DigitBase, class Allocator, class Exponent, Exponent MinE, Exponent MaxE, boost::multiprecision::expression_template_option ExpressionTemplates>
  1878. BOOST_CONSTEXPR_OR_CONST int numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>, ExpressionTemplates> >::radix;
  1879. template <unsigned Digits, boost::multiprecision::backends::digit_base_type DigitBase, class Allocator, class Exponent, Exponent MinE, Exponent MaxE, boost::multiprecision::expression_template_option ExpressionTemplates>
  1880. BOOST_CONSTEXPR_OR_CONST typename boost::multiprecision::cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_type numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>, ExpressionTemplates> >::min_exponent;
  1881. template <unsigned Digits, boost::multiprecision::backends::digit_base_type DigitBase, class Allocator, class Exponent, Exponent MinE, Exponent MaxE, boost::multiprecision::expression_template_option ExpressionTemplates>
  1882. BOOST_CONSTEXPR_OR_CONST typename boost::multiprecision::cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_type numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>, ExpressionTemplates> >::min_exponent10;
  1883. template <unsigned Digits, boost::multiprecision::backends::digit_base_type DigitBase, class Allocator, class Exponent, Exponent MinE, Exponent MaxE, boost::multiprecision::expression_template_option ExpressionTemplates>
  1884. BOOST_CONSTEXPR_OR_CONST typename boost::multiprecision::cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_type numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>, ExpressionTemplates> >::max_exponent;
  1885. template <unsigned Digits, boost::multiprecision::backends::digit_base_type DigitBase, class Allocator, class Exponent, Exponent MinE, Exponent MaxE, boost::multiprecision::expression_template_option ExpressionTemplates>
  1886. BOOST_CONSTEXPR_OR_CONST typename boost::multiprecision::cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_type numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>, ExpressionTemplates> >::max_exponent10;
  1887. template <unsigned Digits, boost::multiprecision::backends::digit_base_type DigitBase, class Allocator, class Exponent, Exponent MinE, Exponent MaxE, boost::multiprecision::expression_template_option ExpressionTemplates>
  1888. BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>, ExpressionTemplates> >::has_infinity;
  1889. template <unsigned Digits, boost::multiprecision::backends::digit_base_type DigitBase, class Allocator, class Exponent, Exponent MinE, Exponent MaxE, boost::multiprecision::expression_template_option ExpressionTemplates>
  1890. BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>, ExpressionTemplates> >::has_quiet_NaN;
  1891. template <unsigned Digits, boost::multiprecision::backends::digit_base_type DigitBase, class Allocator, class Exponent, Exponent MinE, Exponent MaxE, boost::multiprecision::expression_template_option ExpressionTemplates>
  1892. BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>, ExpressionTemplates> >::has_signaling_NaN;
  1893. template <unsigned Digits, boost::multiprecision::backends::digit_base_type DigitBase, class Allocator, class Exponent, Exponent MinE, Exponent MaxE, boost::multiprecision::expression_template_option ExpressionTemplates>
  1894. BOOST_CONSTEXPR_OR_CONST float_denorm_style numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>, ExpressionTemplates> >::has_denorm;
  1895. template <unsigned Digits, boost::multiprecision::backends::digit_base_type DigitBase, class Allocator, class Exponent, Exponent MinE, Exponent MaxE, boost::multiprecision::expression_template_option ExpressionTemplates>
  1896. BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>, ExpressionTemplates> >::has_denorm_loss;
  1897. template <unsigned Digits, boost::multiprecision::backends::digit_base_type DigitBase, class Allocator, class Exponent, Exponent MinE, Exponent MaxE, boost::multiprecision::expression_template_option ExpressionTemplates>
  1898. BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>, ExpressionTemplates> >::is_iec559;
  1899. template <unsigned Digits, boost::multiprecision::backends::digit_base_type DigitBase, class Allocator, class Exponent, Exponent MinE, Exponent MaxE, boost::multiprecision::expression_template_option ExpressionTemplates>
  1900. BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>, ExpressionTemplates> >::is_bounded;
  1901. template <unsigned Digits, boost::multiprecision::backends::digit_base_type DigitBase, class Allocator, class Exponent, Exponent MinE, Exponent MaxE, boost::multiprecision::expression_template_option ExpressionTemplates>
  1902. BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>, ExpressionTemplates> >::is_modulo;
  1903. template <unsigned Digits, boost::multiprecision::backends::digit_base_type DigitBase, class Allocator, class Exponent, Exponent MinE, Exponent MaxE, boost::multiprecision::expression_template_option ExpressionTemplates>
  1904. BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>, ExpressionTemplates> >::traps;
  1905. template <unsigned Digits, boost::multiprecision::backends::digit_base_type DigitBase, class Allocator, class Exponent, Exponent MinE, Exponent MaxE, boost::multiprecision::expression_template_option ExpressionTemplates>
  1906. BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>, ExpressionTemplates> >::tinyness_before;
  1907. template <unsigned Digits, boost::multiprecision::backends::digit_base_type DigitBase, class Allocator, class Exponent, Exponent MinE, Exponent MaxE, boost::multiprecision::expression_template_option ExpressionTemplates>
  1908. BOOST_CONSTEXPR_OR_CONST float_round_style numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>, ExpressionTemplates> >::round_style;
  1909. #endif
  1910. } // namespace std
  1911. #endif