cpp_bin_float.hpp 92 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048
  1. ///////////////////////////////////////////////////////////////
  2. // Copyright 2013 John Maddock. Distributed under the Boost
  3. // Software License, Version 1.0. (See accompanying file
  4. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_
  5. #ifndef BOOST_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{ namespace multiprecision{ namespace backends{
  24. enum digit_base_type
  25. {
  26. digit_base_2 = 2,
  27. digit_base_10 = 10
  28. };
  29. #ifdef BOOST_MSVC
  30. #pragma warning(push)
  31. #pragma warning(disable:4522 6326) // multiple assignment operators specified, comparison of two constants
  32. #endif
  33. namespace detail{
  34. template <class U>
  35. inline typename enable_if_c<is_unsigned<U>::value, bool>::type is_negative(U) { return false; }
  36. template <class S>
  37. inline typename disable_if_c<is_unsigned<S>::value, bool>::type is_negative(S s) { return s < 0; }
  38. template <class Float, int, bool = number_category<Float>::value == number_kind_floating_point>
  39. struct is_cpp_bin_float_implicitly_constructible_from_type
  40. {
  41. static const bool value = false;
  42. };
  43. template <class Float, int bit_count>
  44. struct is_cpp_bin_float_implicitly_constructible_from_type<Float, bit_count, true>
  45. {
  46. static const bool value = (std::numeric_limits<Float>::digits <= (int)bit_count)
  47. && (std::numeric_limits<Float>::radix == 2)
  48. && 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. };
  55. template <class Float, int, bool = number_category<Float>::value == number_kind_floating_point>
  56. struct is_cpp_bin_float_explicitly_constructible_from_type
  57. {
  58. static const bool value = false;
  59. };
  60. template <class Float, int bit_count>
  61. struct is_cpp_bin_float_explicitly_constructible_from_type<Float, bit_count, true>
  62. {
  63. static const bool value = (std::numeric_limits<Float>::digits > (int)bit_count)
  64. && (std::numeric_limits<Float>::radix == 2)
  65. && std::numeric_limits<Float>::is_specialized
  66. #ifdef BOOST_HAS_FLOAT128
  67. && !boost::is_same<Float, __float128>::value
  68. #endif
  69. ;
  70. };
  71. }
  72. template <unsigned Digits, digit_base_type DigitBase = digit_base_10, class Allocator = void, class Exponent = int, Exponent MinExponent = 0, Exponent MaxExponent = 0>
  73. class cpp_bin_float
  74. {
  75. public:
  76. static const unsigned bit_count = DigitBase == digit_base_2 ? Digits : (Digits * 1000uL) / 301uL + (((Digits * 1000uL) % 301) ? 2u : 1u);
  77. 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;
  78. 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;
  79. typedef typename rep_type::signed_types signed_types;
  80. typedef typename rep_type::unsigned_types unsigned_types;
  81. typedef boost::mpl::list<float, double, long double> float_types;
  82. typedef Exponent exponent_type;
  83. static const exponent_type max_exponent_limit = boost::integer_traits<exponent_type>::const_max - 2 * static_cast<exponent_type>(bit_count);
  84. static const exponent_type min_exponent_limit = boost::integer_traits<exponent_type>::const_min + 2 * static_cast<exponent_type>(bit_count);
  85. BOOST_STATIC_ASSERT_MSG(MinExponent >= min_exponent_limit, "Template parameter MinExponent is too negative for our internal logic to function correctly, sorry!");
  86. BOOST_STATIC_ASSERT_MSG(MaxExponent <= max_exponent_limit, "Template parameter MaxExponent is too large for our internal logic to function correctly, sorry!");
  87. BOOST_STATIC_ASSERT_MSG(MinExponent <= 0, "Template parameter MinExponent can not be positive!");
  88. BOOST_STATIC_ASSERT_MSG(MaxExponent >= 0, "Template parameter MaxExponent can not be negative!");
  89. static const exponent_type max_exponent = MaxExponent == 0 ? max_exponent_limit : MaxExponent;
  90. static const exponent_type min_exponent = MinExponent == 0 ? min_exponent_limit : MinExponent;
  91. static const exponent_type exponent_zero = max_exponent + 1;
  92. static const exponent_type exponent_infinity = max_exponent + 2;
  93. static const exponent_type exponent_nan = max_exponent + 3;
  94. private:
  95. rep_type m_data;
  96. exponent_type m_exponent;
  97. bool m_sign;
  98. public:
  99. cpp_bin_float() BOOST_MP_NOEXCEPT_IF(noexcept(rep_type())) : m_data(), m_exponent(exponent_zero), m_sign(false) {}
  100. cpp_bin_float(const cpp_bin_float &o) BOOST_MP_NOEXCEPT_IF(noexcept(rep_type(std::declval<const rep_type&>())))
  101. : m_data(o.m_data), m_exponent(o.m_exponent), m_sign(o.m_sign) {}
  102. template <unsigned D, digit_base_type B, class A, class E, E MinE, E MaxE>
  103. 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)
  104. {
  105. *this = o;
  106. }
  107. template <unsigned D, digit_base_type B, class A, class E, E MinE, E MaxE>
  108. 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)
  109. : m_exponent(o.exponent()), m_sign(o.sign())
  110. {
  111. *this = o;
  112. }
  113. template <class Float>
  114. cpp_bin_float(const Float& f,
  115. typename boost::enable_if_c<detail::is_cpp_bin_float_implicitly_constructible_from_type<Float, bit_count>::value>::type const* = 0)
  116. : m_data(), m_exponent(0), m_sign(false)
  117. {
  118. this->assign_float(f);
  119. }
  120. template <class Float>
  121. explicit cpp_bin_float(const Float& f,
  122. typename boost::enable_if_c<detail::is_cpp_bin_float_explicitly_constructible_from_type<Float, bit_count>::value>::type const* = 0)
  123. : m_data(), m_exponent(0), m_sign(false)
  124. {
  125. this->assign_float(f);
  126. }
  127. #ifdef BOOST_HAS_FLOAT128
  128. template <class Float>
  129. cpp_bin_float(const Float& f,
  130. typename boost::enable_if_c<
  131. boost::is_same<Float, __float128>::value
  132. && ((int)bit_count >= 113)
  133. >::type const* = 0)
  134. : m_data(), m_exponent(0), m_sign(false)
  135. {
  136. this->assign_float(f);
  137. }
  138. template <class Float>
  139. explicit cpp_bin_float(const Float& f,
  140. typename boost::enable_if_c<
  141. boost::is_same<Float, __float128>::value
  142. && ((int)bit_count < 113)
  143. >::type const* = 0)
  144. : m_data(), m_exponent(0), m_sign(false)
  145. {
  146. this->assign_float(f);
  147. }
  148. #endif
  149. cpp_bin_float& operator=(const cpp_bin_float &o) BOOST_MP_NOEXCEPT_IF(noexcept(std::declval<rep_type&>() = std::declval<const rep_type&>()))
  150. {
  151. m_data = o.m_data;
  152. m_exponent = o.m_exponent;
  153. m_sign = o.m_sign;
  154. return *this;
  155. }
  156. template <unsigned D, digit_base_type B, class A, class E, E MinE, E MaxE>
  157. cpp_bin_float& operator=(const cpp_bin_float<D, B, A, E, MinE, MaxE> &f)
  158. {
  159. switch(eval_fpclassify(f))
  160. {
  161. case FP_ZERO:
  162. m_data = limb_type(0);
  163. m_sign = f.sign();
  164. m_exponent = exponent_zero;
  165. break;
  166. case FP_NAN:
  167. m_data = limb_type(0);
  168. m_sign = false;
  169. m_exponent = exponent_nan;
  170. break;;
  171. case FP_INFINITE:
  172. m_data = limb_type(0);
  173. m_sign = f.sign();
  174. m_exponent = exponent_infinity;
  175. break;
  176. default:
  177. typename cpp_bin_float<D, B, A, E, MinE, MaxE>::rep_type b(f.bits());
  178. this->exponent() = f.exponent() + (E)bit_count - (E)cpp_bin_float<D, B, A, E, MinE, MaxE>::bit_count;
  179. this->sign() = f.sign();
  180. copy_and_round(*this, b);
  181. }
  182. return *this;
  183. }
  184. #ifdef BOOST_HAS_FLOAT128
  185. template <class Float>
  186. typename boost::enable_if_c<
  187. (number_category<Float>::value == number_kind_floating_point)
  188. //&& (std::numeric_limits<Float>::digits <= (int)bit_count)
  189. && ((std::numeric_limits<Float>::radix == 2) || (boost::is_same<Float, __float128>::value)), cpp_bin_float&>::type
  190. operator=(const Float& f)
  191. #else
  192. template <class Float>
  193. typename boost::enable_if_c<
  194. (number_category<Float>::value == number_kind_floating_point)
  195. //&& (std::numeric_limits<Float>::digits <= (int)bit_count)
  196. && (std::numeric_limits<Float>::radix == 2), cpp_bin_float&>::type
  197. operator=(const Float& f)
  198. #endif
  199. {
  200. return assign_float(f);
  201. }
  202. #ifdef BOOST_HAS_FLOAT128
  203. template <class Float>
  204. typename boost::enable_if_c<boost::is_same<Float, __float128>::value, cpp_bin_float& >::type assign_float(Float f)
  205. {
  206. using default_ops::eval_add;
  207. typedef typename boost::multiprecision::detail::canonical<int, cpp_bin_float>::type bf_int_type;
  208. if(f == 0)
  209. {
  210. m_data = limb_type(0);
  211. m_sign = (signbitq(f) > 0);
  212. m_exponent = exponent_zero;
  213. return *this;
  214. }
  215. else if(isnanq(f))
  216. {
  217. m_data = limb_type(0);
  218. m_sign = false;
  219. m_exponent = exponent_nan;
  220. return *this;
  221. }
  222. else if(isinfq(f))
  223. {
  224. m_data = limb_type(0);
  225. m_sign = (f < 0);
  226. m_exponent = exponent_infinity;
  227. return *this;
  228. }
  229. if(f < 0)
  230. {
  231. *this = -f;
  232. this->negate();
  233. return *this;
  234. }
  235. typedef typename mpl::front<unsigned_types>::type ui_type;
  236. m_data = static_cast<ui_type>(0u);
  237. m_sign = false;
  238. m_exponent = 0;
  239. static const int bits = sizeof(int) * CHAR_BIT - 1;
  240. int e;
  241. f = frexpq(f, &e);
  242. while(f)
  243. {
  244. f = ldexpq(f, bits);
  245. e -= bits;
  246. int ipart = (int)truncq(f);
  247. f -= ipart;
  248. m_exponent += bits;
  249. cpp_bin_float t;
  250. t = static_cast<bf_int_type>(ipart);
  251. eval_add(*this, t);
  252. }
  253. m_exponent += static_cast<Exponent>(e);
  254. return *this;
  255. }
  256. #endif
  257. #ifdef BOOST_HAS_FLOAT128
  258. template <class Float>
  259. typename boost::enable_if_c<is_floating_point<Float>::value && !is_same<Float, __float128>::value, cpp_bin_float&>::type assign_float(Float f)
  260. #else
  261. template <class Float>
  262. typename boost::enable_if_c<is_floating_point<Float>::value, cpp_bin_float&>::type assign_float(Float f)
  263. #endif
  264. {
  265. BOOST_MATH_STD_USING
  266. using default_ops::eval_add;
  267. typedef typename boost::multiprecision::detail::canonical<int, cpp_bin_float>::type bf_int_type;
  268. switch((boost::math::fpclassify)(f))
  269. {
  270. case FP_ZERO:
  271. m_data = limb_type(0);
  272. m_sign = ((boost::math::signbit)(f) > 0);
  273. m_exponent = exponent_zero;
  274. return *this;
  275. case FP_NAN:
  276. m_data = limb_type(0);
  277. m_sign = false;
  278. m_exponent = exponent_nan;
  279. return *this;
  280. case FP_INFINITE:
  281. m_data = limb_type(0);
  282. m_sign = (f < 0);
  283. m_exponent = exponent_infinity;
  284. return *this;
  285. }
  286. if(f < 0)
  287. {
  288. *this = -f;
  289. this->negate();
  290. return *this;
  291. }
  292. typedef typename mpl::front<unsigned_types>::type ui_type;
  293. m_data = static_cast<ui_type>(0u);
  294. m_sign = false;
  295. m_exponent = 0;
  296. static const int bits = sizeof(int) * CHAR_BIT - 1;
  297. int e;
  298. f = frexp(f, &e);
  299. while(f)
  300. {
  301. f = ldexp(f, bits);
  302. e -= bits;
  303. #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
  304. int ipart = itrunc(f);
  305. #else
  306. int ipart = static_cast<int>(f);
  307. #endif
  308. f -= ipart;
  309. m_exponent += bits;
  310. cpp_bin_float t;
  311. t = static_cast<bf_int_type>(ipart);
  312. eval_add(*this, t);
  313. }
  314. m_exponent += static_cast<Exponent>(e);
  315. return *this;
  316. }
  317. template <class Float>
  318. typename boost::enable_if_c<
  319. (number_category<Float>::value == number_kind_floating_point)
  320. && !boost::is_floating_point<Float>::value
  321. && is_number<Float>::value,
  322. cpp_bin_float&>::type assign_float(Float f)
  323. {
  324. BOOST_MATH_STD_USING
  325. using default_ops::eval_add;
  326. using default_ops::eval_get_sign;
  327. using default_ops::eval_convert_to;
  328. using default_ops::eval_subtract;
  329. typedef typename boost::multiprecision::detail::canonical<int, Float>::type f_int_type;
  330. typedef typename boost::multiprecision::detail::canonical<int, cpp_bin_float>::type bf_int_type;
  331. switch(eval_fpclassify(f))
  332. {
  333. case FP_ZERO:
  334. m_data = limb_type(0);
  335. m_sign = ((boost::math::signbit)(f) > 0);
  336. m_exponent = exponent_zero;
  337. return *this;
  338. case FP_NAN:
  339. m_data = limb_type(0);
  340. m_sign = false;
  341. m_exponent = exponent_nan;
  342. return *this;
  343. case FP_INFINITE:
  344. m_data = limb_type(0);
  345. m_sign = (f < 0);
  346. m_exponent = exponent_infinity;
  347. return *this;
  348. }
  349. if(eval_get_sign(f) < 0)
  350. {
  351. f.negate();
  352. *this = f;
  353. this->negate();
  354. return *this;
  355. }
  356. typedef typename mpl::front<unsigned_types>::type ui_type;
  357. m_data = static_cast<ui_type>(0u);
  358. m_sign = false;
  359. m_exponent = 0;
  360. static const int bits = sizeof(int) * CHAR_BIT - 1;
  361. int e;
  362. eval_frexp(f, f, &e);
  363. while(eval_get_sign(f) != 0)
  364. {
  365. eval_ldexp(f, f, bits);
  366. e -= bits;
  367. int ipart;
  368. eval_convert_to(&ipart, f);
  369. eval_subtract(f, static_cast<f_int_type>(ipart));
  370. m_exponent += bits;
  371. eval_add(*this, static_cast<bf_int_type>(ipart));
  372. }
  373. m_exponent += e;
  374. if(m_exponent > max_exponent)
  375. m_exponent = exponent_infinity;
  376. if(m_exponent < min_exponent)
  377. {
  378. m_data = limb_type(0u);
  379. m_exponent = exponent_zero;
  380. m_sign = ((boost::math::signbit)(f) > 0);
  381. }
  382. else if(eval_get_sign(m_data) == 0)
  383. {
  384. m_exponent = exponent_zero;
  385. m_sign = ((boost::math::signbit)(f) > 0);
  386. }
  387. return *this;
  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::serialization::make_nvp("data", m_data);
  488. ar & boost::serialization::make_nvp("exponent", m_exponent);
  489. ar & boost::serialization::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_msb;
  501. using default_ops::eval_lsb;
  502. using default_ops::eval_left_shift;
  503. using default_ops::eval_bit_test;
  504. using default_ops::eval_right_shift;
  505. using default_ops::eval_increment;
  506. using default_ops::eval_get_sign;
  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_subtract;
  666. using default_ops::eval_bit_test;
  667. using default_ops::eval_decrement;
  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_subtract;
  935. using default_ops::eval_qr;
  936. using default_ops::eval_bit_test;
  937. using default_ops::eval_get_sign;
  938. using default_ops::eval_increment;
  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_subtract;
  1100. using default_ops::eval_qr;
  1101. using default_ops::eval_bit_test;
  1102. using default_ops::eval_get_sign;
  1103. using default_ops::eval_increment;
  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())
  1237. && (a.bits().compare(b.bits()) == 0)
  1238. && (a.exponent() != cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_nan);
  1239. }
  1240. return false;
  1241. }
  1242. template <unsigned Digits, digit_base_type DigitBase, class Allocator, class Exponent, Exponent MinE, Exponent MaxE>
  1243. inline void eval_convert_to(boost::long_long_type *res, const cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE> &arg)
  1244. {
  1245. switch(arg.exponent())
  1246. {
  1247. case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_zero:
  1248. *res = 0;
  1249. return;
  1250. case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_nan:
  1251. BOOST_THROW_EXCEPTION(std::runtime_error("Could not convert NaN to integer."));
  1252. case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_infinity:
  1253. *res = (std::numeric_limits<boost::long_long_type>::max)();
  1254. if(arg.sign())
  1255. *res = -*res;
  1256. return;
  1257. }
  1258. 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;
  1259. typename cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::rep_type man(arg.bits());
  1260. shift_type shift
  1261. = (shift_type)cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count - 1 - arg.exponent();
  1262. if(shift > (shift_type)cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count - 1)
  1263. {
  1264. *res = 0;
  1265. return;
  1266. }
  1267. if(arg.sign() && (arg.compare((std::numeric_limits<boost::long_long_type>::min)()) <= 0))
  1268. {
  1269. *res = (std::numeric_limits<boost::long_long_type>::min)();
  1270. return;
  1271. }
  1272. else if(!arg.sign() && (arg.compare((std::numeric_limits<boost::long_long_type>::max)()) >= 0))
  1273. {
  1274. *res = (std::numeric_limits<boost::long_long_type>::max)();
  1275. return;
  1276. }
  1277. if (shift < 0)
  1278. {
  1279. if (cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count - shift <= std::numeric_limits<boost::long_long_type>::digits)
  1280. {
  1281. // We have more bits in long_long_type than the float, so it's OK to left shift:
  1282. eval_convert_to(res, man);
  1283. *res <<= -shift;
  1284. }
  1285. else
  1286. {
  1287. *res = (std::numeric_limits<boost::long_long_type>::max)();
  1288. return;
  1289. }
  1290. }
  1291. else
  1292. {
  1293. eval_right_shift(man, shift);
  1294. eval_convert_to(res, man);
  1295. }
  1296. if(arg.sign())
  1297. {
  1298. *res = -*res;
  1299. }
  1300. }
  1301. template <unsigned Digits, digit_base_type DigitBase, class Allocator, class Exponent, Exponent MinE, Exponent MaxE>
  1302. inline void eval_convert_to(boost::ulong_long_type *res, const cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE> &arg)
  1303. {
  1304. switch(arg.exponent())
  1305. {
  1306. case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_zero:
  1307. *res = 0;
  1308. return;
  1309. case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_nan:
  1310. BOOST_THROW_EXCEPTION(std::runtime_error("Could not convert NaN to integer."));
  1311. case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_infinity:
  1312. *res = (std::numeric_limits<boost::ulong_long_type>::max)();
  1313. return;
  1314. }
  1315. typename cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::rep_type man(arg.bits());
  1316. 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;
  1317. shift_type shift
  1318. = (shift_type)cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count - 1 - arg.exponent();
  1319. if(shift > (shift_type)cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count - 1)
  1320. {
  1321. *res = 0;
  1322. return;
  1323. }
  1324. else if(shift < 0)
  1325. {
  1326. if (cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count - shift <= std::numeric_limits<boost::ulong_long_type>::digits)
  1327. {
  1328. // We have more bits in ulong_long_type than the float, so it's OK to left shift:
  1329. eval_convert_to(res, man);
  1330. *res <<= -shift;
  1331. return;
  1332. }
  1333. *res = (std::numeric_limits<boost::ulong_long_type>::max)();
  1334. return;
  1335. }
  1336. eval_right_shift(man, shift);
  1337. eval_convert_to(res, man);
  1338. }
  1339. template <class Float, unsigned Digits, digit_base_type DigitBase, class Allocator, class Exponent, Exponent MinE, Exponent MaxE>
  1340. 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)
  1341. {
  1342. typedef cpp_bin_float<std::numeric_limits<Float>::digits, digit_base_2, void, Exponent, MinE, MaxE> conv_type;
  1343. typedef typename common_type<typename conv_type::exponent_type, int>::type common_exp_type;
  1344. //
  1345. // Special cases first:
  1346. //
  1347. switch(original_arg.exponent())
  1348. {
  1349. case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_zero:
  1350. *res = 0;
  1351. if(original_arg.sign())
  1352. *res = -*res;
  1353. return;
  1354. case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_nan:
  1355. *res = std::numeric_limits<Float>::quiet_NaN();
  1356. return;
  1357. case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_infinity:
  1358. *res = (std::numeric_limits<Float>::infinity)();
  1359. if(original_arg.sign())
  1360. *res = -*res;
  1361. return;
  1362. }
  1363. //
  1364. // Check for super large exponent that must be converted to infinity:
  1365. //
  1366. if(original_arg.exponent() > std::numeric_limits<Float>::max_exponent)
  1367. {
  1368. *res = std::numeric_limits<Float>::has_infinity ? std::numeric_limits<Float>::infinity() : (std::numeric_limits<Float>::max)();
  1369. if(original_arg.sign())
  1370. *res = -*res;
  1371. return;
  1372. }
  1373. //
  1374. // Figure out how many digits we will have in our result,
  1375. // allowing for a possibly denormalized result:
  1376. //
  1377. common_exp_type digits_to_round_to = std::numeric_limits<Float>::digits;
  1378. if(original_arg.exponent() < std::numeric_limits<Float>::min_exponent - 1)
  1379. {
  1380. common_exp_type diff = original_arg.exponent();
  1381. diff -= std::numeric_limits<Float>::min_exponent - 1;
  1382. digits_to_round_to += diff;
  1383. }
  1384. if(digits_to_round_to < 0)
  1385. {
  1386. // Result must be zero:
  1387. *res = 0;
  1388. if(original_arg.sign())
  1389. *res = -*res;
  1390. return;
  1391. }
  1392. //
  1393. // Perform rounding first, then afterwards extract the digits:
  1394. //
  1395. cpp_bin_float<std::numeric_limits<Float>::digits, digit_base_2, Allocator, Exponent, MinE, MaxE> arg;
  1396. typename cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::rep_type bits(original_arg.bits());
  1397. arg.exponent() = original_arg.exponent();
  1398. copy_and_round(arg, bits, (int)digits_to_round_to);
  1399. common_exp_type e = arg.exponent();
  1400. e -= cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count - 1;
  1401. static const unsigned limbs_needed = std::numeric_limits<Float>::digits / (sizeof(*arg.bits().limbs()) * CHAR_BIT)
  1402. + (std::numeric_limits<Float>::digits % (sizeof(*arg.bits().limbs()) * CHAR_BIT) ? 1 : 0);
  1403. unsigned first_limb_needed = arg.bits().size() - limbs_needed;
  1404. *res = 0;
  1405. e += first_limb_needed * sizeof(*arg.bits().limbs()) * CHAR_BIT;
  1406. while(first_limb_needed < arg.bits().size())
  1407. {
  1408. *res += std::ldexp(static_cast<Float>(arg.bits().limbs()[first_limb_needed]), static_cast<int>(e));
  1409. ++first_limb_needed;
  1410. e += sizeof(*arg.bits().limbs()) * CHAR_BIT;
  1411. }
  1412. if(original_arg.sign())
  1413. *res = -*res;
  1414. }
  1415. template <unsigned Digits, digit_base_type DigitBase, class Allocator, class Exponent, Exponent MinE, Exponent MaxE>
  1416. 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)
  1417. {
  1418. switch(arg.exponent())
  1419. {
  1420. case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_zero:
  1421. case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_nan:
  1422. case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_infinity:
  1423. *e = 0;
  1424. res = arg;
  1425. return;
  1426. }
  1427. res = arg;
  1428. *e = arg.exponent() + 1;
  1429. res.exponent() = -1;
  1430. }
  1431. template <unsigned Digits, digit_base_type DigitBase, class Allocator, class Exponent, Exponent MinE, Exponent MaxE, class I>
  1432. 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)
  1433. {
  1434. Exponent e;
  1435. eval_frexp(res, arg, &e);
  1436. if((e > (std::numeric_limits<I>::max)()) || (e < (std::numeric_limits<I>::min)()))
  1437. {
  1438. BOOST_THROW_EXCEPTION(std::runtime_error("Exponent was outside of the range of the argument type to frexp."));
  1439. }
  1440. *pe = static_cast<I>(e);
  1441. }
  1442. template <unsigned Digits, digit_base_type DigitBase, class Allocator, class Exponent, Exponent MinE, Exponent MaxE>
  1443. 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)
  1444. {
  1445. switch(arg.exponent())
  1446. {
  1447. case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_zero:
  1448. case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_nan:
  1449. case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_infinity:
  1450. res = arg;
  1451. return;
  1452. }
  1453. if((e > 0) && (cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::max_exponent - e < arg.exponent()))
  1454. {
  1455. // Overflow:
  1456. res = std::numeric_limits<number<cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE> > >::infinity().backend();
  1457. res.sign() = arg.sign();
  1458. }
  1459. else if((e < 0) && (cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::min_exponent - e > arg.exponent()))
  1460. {
  1461. // Underflow:
  1462. res = limb_type(0);
  1463. }
  1464. else
  1465. {
  1466. res = arg;
  1467. res.exponent() += e;
  1468. }
  1469. }
  1470. template <unsigned Digits, digit_base_type DigitBase, class Allocator, class Exponent, Exponent MinE, Exponent MaxE, class I>
  1471. 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)
  1472. {
  1473. typedef typename make_signed<I>::type si_type;
  1474. if(e > static_cast<I>((std::numeric_limits<si_type>::max)()))
  1475. res = std::numeric_limits<number<cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE> > >::infinity().backend();
  1476. else
  1477. eval_ldexp(res, arg, static_cast<si_type>(e));
  1478. }
  1479. template <unsigned Digits, digit_base_type DigitBase, class Allocator, class Exponent, Exponent MinE, Exponent MaxE, class I>
  1480. 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)
  1481. {
  1482. if((e > (std::numeric_limits<Exponent>::max)()) || (e < (std::numeric_limits<Exponent>::min)()))
  1483. {
  1484. res = std::numeric_limits<number<cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE> > >::infinity().backend();
  1485. if(e < 0)
  1486. res.negate();
  1487. }
  1488. else
  1489. eval_ldexp(res, arg, static_cast<Exponent>(e));
  1490. }
  1491. /*
  1492. * Sign manipulation
  1493. */
  1494. template <unsigned Digits, digit_base_type DigitBase, class Allocator, class Exponent, Exponent MinE, Exponent MaxE>
  1495. 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)
  1496. {
  1497. res = arg;
  1498. res.sign() = false;
  1499. }
  1500. template <unsigned Digits, digit_base_type DigitBase, class Allocator, class Exponent, Exponent MinE, Exponent MaxE>
  1501. 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)
  1502. {
  1503. res = arg;
  1504. res.sign() = false;
  1505. }
  1506. template <unsigned Digits, digit_base_type DigitBase, class Allocator, class Exponent, Exponent MinE, Exponent MaxE>
  1507. inline int eval_fpclassify(const cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE> &arg)
  1508. {
  1509. switch(arg.exponent())
  1510. {
  1511. case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_zero:
  1512. return FP_ZERO;
  1513. case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_infinity:
  1514. return FP_INFINITE;
  1515. case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_nan:
  1516. return FP_NAN;
  1517. }
  1518. return FP_NORMAL;
  1519. }
  1520. template <unsigned Digits, digit_base_type DigitBase, class Allocator, class Exponent, Exponent MinE, Exponent MaxE>
  1521. 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)
  1522. {
  1523. using default_ops::eval_integer_sqrt;
  1524. using default_ops::eval_bit_test;
  1525. using default_ops::eval_increment;
  1526. switch(arg.exponent())
  1527. {
  1528. case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_nan:
  1529. errno = EDOM;
  1530. // fallthrough...
  1531. case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_zero:
  1532. res = arg;
  1533. return;
  1534. case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_infinity:
  1535. if(arg.sign())
  1536. {
  1537. res = std::numeric_limits<number<cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE> > >::quiet_NaN().backend();
  1538. errno = EDOM;
  1539. }
  1540. else
  1541. res = arg;
  1542. return;
  1543. }
  1544. if(arg.sign())
  1545. {
  1546. res = std::numeric_limits<number<cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE> > >::quiet_NaN().backend();
  1547. errno = EDOM;
  1548. return;
  1549. }
  1550. typename cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::double_rep_type t(arg.bits()), r, s;
  1551. 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);
  1552. eval_integer_sqrt(s, r, t);
  1553. if(!eval_bit_test(s, cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count))
  1554. {
  1555. // We have exactly the right number of cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count in the result, round as required:
  1556. if(s.compare(r) < 0)
  1557. {
  1558. eval_increment(s);
  1559. }
  1560. }
  1561. typename cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_type ae = arg.exponent();
  1562. res.exponent() = ae / 2;
  1563. if((ae & 1) && (ae < 0))
  1564. --res.exponent();
  1565. copy_and_round(res, s);
  1566. }
  1567. template <unsigned Digits, digit_base_type DigitBase, class Allocator, class Exponent, Exponent MinE, Exponent MaxE>
  1568. 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)
  1569. {
  1570. using default_ops::eval_increment;
  1571. switch(arg.exponent())
  1572. {
  1573. case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_nan:
  1574. errno = EDOM;
  1575. // fallthrough...
  1576. case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_zero:
  1577. case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_infinity:
  1578. res = arg;
  1579. return;
  1580. }
  1581. 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;
  1582. shift_type shift =
  1583. (shift_type)cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count - arg.exponent() - 1;
  1584. if((arg.exponent() > (shift_type)cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::max_exponent) || (shift <= 0))
  1585. {
  1586. // Either arg is already an integer, or a special value:
  1587. res = arg;
  1588. return;
  1589. }
  1590. if(shift >= (shift_type)cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count)
  1591. {
  1592. res = static_cast<signed_limb_type>(arg.sign() ? -1 : 0);
  1593. return;
  1594. }
  1595. bool fractional = (shift_type)eval_lsb(arg.bits()) < shift;
  1596. res = arg;
  1597. eval_right_shift(res.bits(), shift);
  1598. if(fractional && res.sign())
  1599. {
  1600. eval_increment(res.bits());
  1601. if(eval_msb(res.bits()) != cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count - 1 - shift)
  1602. {
  1603. // Must have extended result by one bit in the increment:
  1604. --shift;
  1605. ++res.exponent();
  1606. }
  1607. }
  1608. eval_left_shift(res.bits(), shift);
  1609. }
  1610. template <unsigned Digits, digit_base_type DigitBase, class Allocator, class Exponent, Exponent MinE, Exponent MaxE>
  1611. 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)
  1612. {
  1613. using default_ops::eval_increment;
  1614. switch(arg.exponent())
  1615. {
  1616. case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_infinity:
  1617. errno = EDOM;
  1618. // fallthrough...
  1619. case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_zero:
  1620. case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_nan:
  1621. res = arg;
  1622. return;
  1623. }
  1624. 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;
  1625. shift_type shift = (shift_type)cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count - arg.exponent() - 1;
  1626. if((arg.exponent() > (shift_type)cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::max_exponent) || (shift <= 0))
  1627. {
  1628. // Either arg is already an integer, or a special value:
  1629. res = arg;
  1630. return;
  1631. }
  1632. if(shift >= (shift_type)cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count)
  1633. {
  1634. bool s = arg.sign(); // takes care of signed zeros
  1635. res = static_cast<signed_limb_type>(arg.sign() ? 0 : 1);
  1636. res.sign() = s;
  1637. return;
  1638. }
  1639. bool fractional = (shift_type)eval_lsb(arg.bits()) < shift;
  1640. res = arg;
  1641. eval_right_shift(res.bits(), shift);
  1642. if(fractional && !res.sign())
  1643. {
  1644. eval_increment(res.bits());
  1645. if(eval_msb(res.bits()) != cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count - 1 - shift)
  1646. {
  1647. // Must have extended result by one bit in the increment:
  1648. --shift;
  1649. ++res.exponent();
  1650. }
  1651. }
  1652. eval_left_shift(res.bits(), shift);
  1653. }
  1654. template<unsigned D1, backends::digit_base_type B1, class A1, class E1, E1 M1, E1 M2>
  1655. int eval_signbit(const cpp_bin_float<D1, B1, A1, E1, M1, M2>& val)
  1656. {
  1657. return val.sign();
  1658. }
  1659. template<unsigned D1, backends::digit_base_type B1, class A1, class E1, E1 M1, E1 M2>
  1660. inline std::size_t hash_value(const cpp_bin_float<D1, B1, A1, E1, M1, M2>& val)
  1661. {
  1662. std::size_t result = hash_value(val.bits());
  1663. boost::hash_combine(result, val.exponent());
  1664. boost::hash_combine(result, val.sign());
  1665. return result;
  1666. }
  1667. } // namespace backends
  1668. #ifdef BOOST_NO_SFINAE_EXPR
  1669. namespace detail{
  1670. 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>
  1671. 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_ {};
  1672. template<class FloatT, unsigned D2, backends::digit_base_type B2, class A2, class E2, E2 M3, E2 M4>
  1673. struct is_explicitly_convertible<FloatT, backends::cpp_bin_float<D2, B2, A2, E2, M3, M4> > : public boost::is_floating_point<FloatT> {};
  1674. }
  1675. #endif
  1676. template<unsigned Digits, boost::multiprecision::backends::digit_base_type DigitBase, class Exponent, Exponent MinE, Exponent MaxE, class Allocator, boost::multiprecision::expression_template_option ExpressionTemplates>
  1677. inline boost::multiprecision::number<boost::multiprecision::backends::cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>, ExpressionTemplates>
  1678. copysign BOOST_PREVENT_MACRO_SUBSTITUTION(
  1679. const boost::multiprecision::number<boost::multiprecision::backends::cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>, ExpressionTemplates>& a,
  1680. const boost::multiprecision::number<boost::multiprecision::backends::cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>, ExpressionTemplates>& b)
  1681. {
  1682. boost::multiprecision::number<boost::multiprecision::backends::cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>, ExpressionTemplates> res(a);
  1683. res.backend().sign() = b.backend().sign();
  1684. return res;
  1685. }
  1686. using backends::cpp_bin_float;
  1687. using backends::digit_base_2;
  1688. using backends::digit_base_10;
  1689. template<unsigned Digits, backends::digit_base_type DigitBase, class Exponent, Exponent MinE, Exponent MaxE, class Allocator>
  1690. struct number_category<cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE> > : public boost::mpl::int_<boost::multiprecision::number_kind_floating_point>{};
  1691. template<unsigned Digits, backends::digit_base_type DigitBase, class Allocator, class Exponent, Exponent MinE, Exponent MaxE>
  1692. struct expression_template_default<cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE> >
  1693. {
  1694. static const expression_template_option value = is_void<Allocator>::value ? et_off : et_on;
  1695. };
  1696. typedef number<backends::cpp_bin_float<50> > cpp_bin_float_50;
  1697. typedef number<backends::cpp_bin_float<100> > cpp_bin_float_100;
  1698. typedef number<backends::cpp_bin_float<24, backends::digit_base_2, void, boost::int16_t, -126, 127>, et_off> cpp_bin_float_single;
  1699. typedef number<backends::cpp_bin_float<53, backends::digit_base_2, void, boost::int16_t, -1022, 1023>, et_off> cpp_bin_float_double;
  1700. typedef number<backends::cpp_bin_float<64, backends::digit_base_2, void, boost::int16_t, -16382, 16383>, et_off> cpp_bin_float_double_extended;
  1701. typedef number<backends::cpp_bin_float<113, backends::digit_base_2, void, boost::int16_t, -16382, 16383>, et_off> cpp_bin_float_quad;
  1702. typedef number<backends::cpp_bin_float<237, backends::digit_base_2, void, boost::int32_t, -262142, 262143>, et_off> cpp_bin_float_oct;
  1703. } // namespace multiprecision
  1704. namespace math {
  1705. using boost::multiprecision::signbit;
  1706. using boost::multiprecision::copysign;
  1707. } // namespace math
  1708. } // namespace boost
  1709. #include <boost/multiprecision/cpp_bin_float/io.hpp>
  1710. #include <boost/multiprecision/cpp_bin_float/transcendental.hpp>
  1711. namespace std{
  1712. //
  1713. // numeric_limits [partial] specializations for the types declared in this header:
  1714. //
  1715. template<unsigned Digits, boost::multiprecision::backends::digit_base_type DigitBase, class Allocator, class Exponent, Exponent MinE, Exponent MaxE, boost::multiprecision::expression_template_option ExpressionTemplates>
  1716. class numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>, ExpressionTemplates> >
  1717. {
  1718. typedef boost::multiprecision::number<boost::multiprecision::cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>, ExpressionTemplates> number_type;
  1719. public:
  1720. BOOST_STATIC_CONSTEXPR bool is_specialized = true;
  1721. static number_type (min)()
  1722. {
  1723. initializer.do_nothing();
  1724. static std::pair<bool, number_type> value;
  1725. if(!value.first)
  1726. {
  1727. value.first = true;
  1728. typedef typename boost::mpl::front<typename number_type::backend_type::unsigned_types>::type ui_type;
  1729. value.second.backend() = ui_type(1u);
  1730. value.second.backend().exponent() = boost::multiprecision::cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::min_exponent;
  1731. }
  1732. return value.second;
  1733. }
  1734. static number_type (max)()
  1735. {
  1736. initializer.do_nothing();
  1737. static std::pair<bool, number_type> value;
  1738. if(!value.first)
  1739. {
  1740. value.first = true;
  1741. if(boost::is_void<Allocator>::value)
  1742. eval_complement(value.second.backend().bits(), value.second.backend().bits());
  1743. else
  1744. {
  1745. // We jump through hoops here using the backend type directly just to keep VC12 happy
  1746. // (ie compiler workaround, for very strange compiler bug):
  1747. using boost::multiprecision::default_ops::eval_add;
  1748. using boost::multiprecision::default_ops::eval_decrement;
  1749. using boost::multiprecision::default_ops::eval_left_shift;
  1750. typedef typename number_type::backend_type::rep_type int_backend_type;
  1751. typedef typename boost::mpl::front<typename int_backend_type::unsigned_types>::type ui_type;
  1752. int_backend_type i;
  1753. i = ui_type(1u);
  1754. eval_left_shift(i, boost::multiprecision::cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count - 1);
  1755. int_backend_type j(i);
  1756. eval_decrement(i);
  1757. eval_add(j, i);
  1758. value.second.backend().bits() = j;
  1759. }
  1760. value.second.backend().exponent() = boost::multiprecision::cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::max_exponent;
  1761. }
  1762. return value.second;
  1763. }
  1764. BOOST_STATIC_CONSTEXPR number_type lowest()
  1765. {
  1766. return -(max)();
  1767. }
  1768. BOOST_STATIC_CONSTEXPR int digits = boost::multiprecision::cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count;
  1769. BOOST_STATIC_CONSTEXPR int digits10 = (digits - 1) * 301 / 1000;
  1770. // Is this really correct???
  1771. BOOST_STATIC_CONSTEXPR int max_digits10 = (digits * 301 / 1000) + 3;
  1772. BOOST_STATIC_CONSTEXPR bool is_signed = true;
  1773. BOOST_STATIC_CONSTEXPR bool is_integer = false;
  1774. BOOST_STATIC_CONSTEXPR bool is_exact = false;
  1775. BOOST_STATIC_CONSTEXPR int radix = 2;
  1776. static number_type epsilon()
  1777. {
  1778. initializer.do_nothing();
  1779. static std::pair<bool, number_type> value;
  1780. if(!value.first)
  1781. {
  1782. // We jump through hoops here just to keep VC12 happy (ie compiler workaround, for very strange compiler bug):
  1783. typedef typename boost::mpl::front<typename number_type::backend_type::unsigned_types>::type ui_type;
  1784. value.first = true;
  1785. value.second.backend() = ui_type(1u);
  1786. value.second = ldexp(value.second, 1 - (int)digits);
  1787. }
  1788. return value.second;
  1789. }
  1790. // What value should this be????
  1791. static number_type round_error()
  1792. {
  1793. // returns 0.5
  1794. initializer.do_nothing();
  1795. static std::pair<bool, number_type> value;
  1796. if(!value.first)
  1797. {
  1798. value.first = true;
  1799. // We jump through hoops here just to keep VC12 happy (ie compiler workaround, for very strange compiler bug):
  1800. typedef typename boost::mpl::front<typename number_type::backend_type::unsigned_types>::type ui_type;
  1801. value.second.backend() = ui_type(1u);
  1802. value.second = ldexp(value.second, -1);
  1803. }
  1804. return value.second;
  1805. }
  1806. 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;
  1807. BOOST_STATIC_CONSTEXPR typename boost::multiprecision::cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_type min_exponent10 = (min_exponent / 1000) * 301L;
  1808. 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;
  1809. BOOST_STATIC_CONSTEXPR typename boost::multiprecision::cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_type max_exponent10 = (max_exponent / 1000) * 301L;
  1810. BOOST_STATIC_CONSTEXPR bool has_infinity = true;
  1811. BOOST_STATIC_CONSTEXPR bool has_quiet_NaN = true;
  1812. BOOST_STATIC_CONSTEXPR bool has_signaling_NaN = false;
  1813. BOOST_STATIC_CONSTEXPR float_denorm_style has_denorm = denorm_absent;
  1814. BOOST_STATIC_CONSTEXPR bool has_denorm_loss = false;
  1815. static number_type infinity()
  1816. {
  1817. initializer.do_nothing();
  1818. static std::pair<bool, number_type> value;
  1819. if(!value.first)
  1820. {
  1821. value.first = true;
  1822. value.second.backend().exponent() = boost::multiprecision::cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_infinity;
  1823. }
  1824. return value.second;
  1825. }
  1826. static number_type quiet_NaN()
  1827. {
  1828. initializer.do_nothing();
  1829. static std::pair<bool, number_type> value;
  1830. if(!value.first)
  1831. {
  1832. value.first = true;
  1833. value.second.backend().exponent() = boost::multiprecision::cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_nan;
  1834. }
  1835. return value.second;
  1836. }
  1837. BOOST_STATIC_CONSTEXPR number_type signaling_NaN()
  1838. {
  1839. return number_type(0);
  1840. }
  1841. BOOST_STATIC_CONSTEXPR number_type denorm_min() { return number_type(0); }
  1842. BOOST_STATIC_CONSTEXPR bool is_iec559 = false;
  1843. BOOST_STATIC_CONSTEXPR bool is_bounded = true;
  1844. BOOST_STATIC_CONSTEXPR bool is_modulo = false;
  1845. BOOST_STATIC_CONSTEXPR bool traps = true;
  1846. BOOST_STATIC_CONSTEXPR bool tinyness_before = false;
  1847. BOOST_STATIC_CONSTEXPR float_round_style round_style = round_to_nearest;
  1848. private:
  1849. struct data_initializer
  1850. {
  1851. data_initializer()
  1852. {
  1853. std::numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE> > >::epsilon();
  1854. std::numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE> > >::round_error();
  1855. (std::numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE> > >::min)();
  1856. (std::numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE> > >::max)();
  1857. std::numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE> > >::infinity();
  1858. std::numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE> > >::quiet_NaN();
  1859. }
  1860. void do_nothing()const{}
  1861. };
  1862. static const data_initializer initializer;
  1863. };
  1864. template<unsigned Digits, boost::multiprecision::backends::digit_base_type DigitBase, class Allocator, class Exponent, Exponent MinE, Exponent MaxE, boost::multiprecision::expression_template_option ExpressionTemplates>
  1865. 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;
  1866. #ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
  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> >::digits;
  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> >::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 int numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>, ExpressionTemplates> >::max_digits10;
  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_signed;
  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_integer;
  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 bool numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>, ExpressionTemplates> >::is_exact;
  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 int numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>, ExpressionTemplates> >::radix;
  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_exponent;
  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> >::min_exponent10;
  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_exponent;
  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 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;
  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_infinity;
  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_quiet_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 bool numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>, ExpressionTemplates> >::has_signaling_NaN;
  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 float_denorm_style numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>, ExpressionTemplates> >::has_denorm;
  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> >::has_denorm_loss;
  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_iec559;
  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_bounded;
  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> >::is_modulo;
  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> >::traps;
  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 bool numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>, ExpressionTemplates> >::tinyness_before;
  1909. template <unsigned Digits, boost::multiprecision::backends::digit_base_type DigitBase, class Allocator, class Exponent, Exponent MinE, Exponent MaxE, boost::multiprecision::expression_template_option ExpressionTemplates>
  1910. 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;
  1911. #endif
  1912. } // namespace std
  1913. #endif