default_ops.hpp 144 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Copyright 2011 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_0.txt)
  5. #ifndef BOOST_MATH_BIG_NUM_DEF_OPS
  6. #define BOOST_MATH_BIG_NUM_DEF_OPS
  7. #include <boost/math/policies/error_handling.hpp>
  8. #include <boost/multiprecision/detail/number_base.hpp>
  9. #include <boost/math/special_functions/fpclassify.hpp>
  10. #include <boost/math/special_functions/next.hpp>
  11. #include <boost/math/special_functions/hypot.hpp>
  12. #include <boost/utility/enable_if.hpp>
  13. #include <boost/mpl/front.hpp>
  14. #include <boost/mpl/fold.hpp>
  15. #include <boost/cstdint.hpp>
  16. #include <boost/type_traits/make_unsigned.hpp>
  17. #ifndef BOOST_NO_CXX17_HDR_STRING_VIEW
  18. #include <string_view>
  19. #endif
  20. #ifndef INSTRUMENT_BACKEND
  21. #ifndef BOOST_MP_INSTRUMENT
  22. #define INSTRUMENT_BACKEND(x)
  23. #else
  24. #define INSTRUMENT_BACKEND(x)\
  25. std::cout << BOOST_STRINGIZE(x) << " = " << x.str(0, std::ios_base::scientific) << std::endl;
  26. #endif
  27. #endif
  28. namespace boost{ namespace multiprecision{
  29. namespace detail {
  30. template <class T>
  31. struct is_backend;
  32. template <class To, class From>
  33. void generic_interconvert(To& to, const From& from, const mpl::int_<number_kind_floating_point>& /*to_type*/, const mpl::int_<number_kind_integer>& /*from_type*/);
  34. template <class To, class From>
  35. void generic_interconvert(To& to, const From& from, const mpl::int_<number_kind_integer>& /*to_type*/, const mpl::int_<number_kind_integer>& /*from_type*/);
  36. template <class To, class From>
  37. void generic_interconvert(To& to, const From& from, const mpl::int_<number_kind_floating_point>& /*to_type*/, const mpl::int_<number_kind_floating_point>& /*from_type*/);
  38. template <class To, class From>
  39. void generic_interconvert(To& to, const From& from, const mpl::int_<number_kind_rational>& /*to_type*/, const mpl::int_<number_kind_rational>& /*from_type*/);
  40. template <class To, class From>
  41. void generic_interconvert(To& to, const From& from, const mpl::int_<number_kind_rational>& /*to_type*/, const mpl::int_<number_kind_integer>& /*from_type*/);
  42. }
  43. namespace default_ops{
  44. #ifdef BOOST_MSVC
  45. // warning C4127: conditional expression is constant
  46. // warning C4146: unary minus operator applied to unsigned type, result still unsigned
  47. #pragma warning(push)
  48. #pragma warning(disable:4127 4146)
  49. #endif
  50. //
  51. // Default versions of mixed arithmetic, these just construct a temporary
  52. // from the arithmetic value and then do the arithmetic on that, two versions
  53. // of each depending on whether the backend can be directly constructed from type V.
  54. //
  55. // Note that we have to provide *all* the template parameters to class number when used in
  56. // enable_if as MSVC-10 won't compile the code if we rely on a computed-default parameter.
  57. // Since the result of the test doesn't depend on whether expression templates are on or off
  58. // we just use et_on everywhere. We could use a BOOST_WORKAROUND but that just obfuscates the
  59. // code even more....
  60. //
  61. template <class T, class V>
  62. inline typename disable_if_c<is_convertible<V, T>::value >::type
  63. eval_add(T& result, V const& v)
  64. {
  65. T t;
  66. t = v;
  67. eval_add(result, t);
  68. }
  69. template <class T, class V>
  70. inline typename enable_if_c<is_convertible<V, T>::value >::type
  71. eval_add(T& result, V const& v)
  72. {
  73. T t(v);
  74. eval_add(result, t);
  75. }
  76. template <class T, class V>
  77. inline typename disable_if_c<is_convertible<V, T>::value>::type
  78. eval_subtract(T& result, V const& v)
  79. {
  80. T t;
  81. t = v;
  82. eval_subtract(result, t);
  83. }
  84. template <class T, class V>
  85. inline typename enable_if_c<is_convertible<V, T>::value>::type
  86. eval_subtract(T& result, V const& v)
  87. {
  88. T t(v);
  89. eval_subtract(result, t);
  90. }
  91. template <class T, class V>
  92. inline typename disable_if_c<is_convertible<V, T>::value>::type
  93. eval_multiply(T& result, V const& v)
  94. {
  95. T t;
  96. t = v;
  97. eval_multiply(result, t);
  98. }
  99. template <class T, class V>
  100. inline typename enable_if_c<is_convertible<V, T>::value>::type
  101. eval_multiply(T& result, V const& v)
  102. {
  103. T t(v);
  104. eval_multiply(result, t);
  105. }
  106. template <class T, class U, class V>
  107. void eval_multiply(T& t, const U& u, const V& v);
  108. template <class T, class U, class V>
  109. inline typename disable_if_c<!is_same<T, U>::value && is_same<T, V>::value>::type eval_multiply_add(T& t, const U& u, const V& v)
  110. {
  111. T z;
  112. eval_multiply(z, u, v);
  113. eval_add(t, z);
  114. }
  115. template <class T, class U, class V>
  116. inline typename enable_if_c<!is_same<T, U>::value && is_same<T, V>::value>::type eval_multiply_add(T& t, const U& u, const V& v)
  117. {
  118. eval_multiply_add(t, v, u);
  119. }
  120. template <class T, class U, class V>
  121. inline typename disable_if_c<!is_same<T, U>::value && is_same<T, V>::value>::type eval_multiply_subtract(T& t, const U& u, const V& v)
  122. {
  123. T z;
  124. eval_multiply(z, u, v);
  125. eval_subtract(t, z);
  126. }
  127. template <class T, class U, class V>
  128. inline typename enable_if_c<!is_same<T, U>::value && is_same<T, V>::value>::type eval_multiply_subtract(T& t, const U& u, const V& v)
  129. {
  130. eval_multiply_subtract(t, v, u);
  131. }
  132. template <class T, class V>
  133. inline typename enable_if_c<is_convertible<V, number<T, et_on> >::value && !is_convertible<V, T>::value>::type
  134. eval_divide(T& result, V const& v)
  135. {
  136. T t;
  137. t = v;
  138. eval_divide(result, t);
  139. }
  140. template <class T, class V>
  141. inline typename enable_if_c<is_convertible<V, number<T, et_on> >::value && is_convertible<V, T>::value>::type
  142. eval_divide(T& result, V const& v)
  143. {
  144. T t(v);
  145. eval_divide(result, t);
  146. }
  147. template <class T, class V>
  148. inline typename enable_if_c<is_convertible<V, number<T, et_on> >::value && !is_convertible<V, T>::value>::type
  149. eval_modulus(T& result, V const& v)
  150. {
  151. T t;
  152. t = v;
  153. eval_modulus(result, t);
  154. }
  155. template <class T, class V>
  156. inline typename enable_if_c<is_convertible<V, number<T, et_on> >::value&& is_convertible<V, T>::value>::type
  157. eval_modulus(T& result, V const& v)
  158. {
  159. T t(v);
  160. eval_modulus(result, t);
  161. }
  162. template <class T, class V>
  163. inline typename enable_if_c<is_convertible<V, number<T, et_on> >::value && !is_convertible<V, T>::value>::type
  164. eval_bitwise_and(T& result, V const& v)
  165. {
  166. T t;
  167. t = v;
  168. eval_bitwise_and(result, t);
  169. }
  170. template <class T, class V>
  171. inline typename enable_if_c<is_convertible<V, number<T, et_on> >::value && is_convertible<V, T>::value>::type
  172. eval_bitwise_and(T& result, V const& v)
  173. {
  174. T t(v);
  175. eval_bitwise_and(result, t);
  176. }
  177. template <class T, class V>
  178. inline typename enable_if_c<is_convertible<V, number<T, et_on> >::value && !is_convertible<V, T>::value>::type
  179. eval_bitwise_or(T& result, V const& v)
  180. {
  181. T t;
  182. t = v;
  183. eval_bitwise_or(result, t);
  184. }
  185. template <class T, class V>
  186. inline typename enable_if_c<is_convertible<V, number<T, et_on> >::value && is_convertible<V, T>::value>::type
  187. eval_bitwise_or(T& result, V const& v)
  188. {
  189. T t(v);
  190. eval_bitwise_or(result, t);
  191. }
  192. template <class T, class V>
  193. inline typename enable_if_c<is_convertible<V, number<T, et_on> >::value && !is_convertible<V, T>::value>::type
  194. eval_bitwise_xor(T& result, V const& v)
  195. {
  196. T t;
  197. t = v;
  198. eval_bitwise_xor(result, t);
  199. }
  200. template <class T, class V>
  201. inline typename enable_if_c<is_convertible<V, number<T, et_on> >::value && is_convertible<V, T>::value>::type
  202. eval_bitwise_xor(T& result, V const& v)
  203. {
  204. T t(v);
  205. eval_bitwise_xor(result, t);
  206. }
  207. template <class T, class V>
  208. inline typename enable_if_c<is_convertible<V, number<T, et_on> >::value && !is_convertible<V, T>::value>::type
  209. eval_complement(T& result, V const& v)
  210. {
  211. T t;
  212. t = v;
  213. eval_complement(result, t);
  214. }
  215. template <class T, class V>
  216. inline typename enable_if_c<is_convertible<V, number<T, et_on> >::value && is_convertible<V, T>::value>::type
  217. eval_complement(T& result, V const& v)
  218. {
  219. T t(v);
  220. eval_complement(result, t);
  221. }
  222. //
  223. // Default versions of 3-arg arithmetic functions, these mostly just forward to the 2 arg versions:
  224. //
  225. template <class T, class U, class V>
  226. void eval_add(T& t, const U& u, const V& v);
  227. template <class T>
  228. inline void eval_add_default(T& t, const T& u, const T& v)
  229. {
  230. if(&t == &v)
  231. {
  232. eval_add(t, u);
  233. }
  234. else if(&t == &u)
  235. {
  236. eval_add(t, v);
  237. }
  238. else
  239. {
  240. t = u;
  241. eval_add(t, v);
  242. }
  243. }
  244. template <class T, class U>
  245. inline typename enable_if_c<is_convertible<U, number<T, et_on> >::value && !is_convertible<U, T>::value>::type eval_add_default(T& t, const T& u, const U& v)
  246. {
  247. T vv;
  248. vv = v;
  249. eval_add(t, u, vv);
  250. }
  251. template <class T, class U>
  252. inline typename enable_if_c<is_convertible<U, number<T, et_on> >::value && is_convertible<U, T>::value>::type eval_add_default(T& t, const T& u, const U& v)
  253. {
  254. T vv(v);
  255. eval_add(t, u, vv);
  256. }
  257. template <class T, class U>
  258. inline typename enable_if_c<is_convertible<U, number<T, et_on> >::value>::type eval_add_default(T& t, const U& u, const T& v)
  259. {
  260. eval_add(t, v, u);
  261. }
  262. template <class T, class U, class V>
  263. inline void eval_add_default(T& t, const U& u, const V& v)
  264. {
  265. if(is_same<T, V>::value && ((void*)&t == (void*)&v))
  266. {
  267. eval_add(t, u);
  268. }
  269. else
  270. {
  271. t = u;
  272. eval_add(t, v);
  273. }
  274. }
  275. template <class T, class U, class V>
  276. inline void eval_add(T& t, const U& u, const V& v)
  277. {
  278. eval_add_default(t, u, v);
  279. }
  280. template <class T, class U, class V>
  281. void eval_subtract(T& t, const U& u, const V& v);
  282. template <class T>
  283. inline void eval_subtract_default(T& t, const T& u, const T& v)
  284. {
  285. if((&t == &v) && is_signed_number<T>::value)
  286. {
  287. eval_subtract(t, u);
  288. t.negate();
  289. }
  290. else if(&t == &u)
  291. {
  292. eval_subtract(t, v);
  293. }
  294. else
  295. {
  296. t = u;
  297. eval_subtract(t, v);
  298. }
  299. }
  300. template <class T, class U>
  301. inline typename enable_if_c<is_convertible<U, number<T, et_on> >::value && !is_convertible<U, T>::value>::type eval_subtract_default(T& t, const T& u, const U& v)
  302. {
  303. T vv;
  304. vv = v;
  305. eval_subtract(t, u, vv);
  306. }
  307. template <class T, class U>
  308. inline typename enable_if_c<is_convertible<U, number<T, et_on> >::value && is_convertible<U, T>::value>::type eval_subtract_default(T& t, const T& u, const U& v)
  309. {
  310. T vv(v);
  311. eval_subtract(t, u, vv);
  312. }
  313. template <class T, class U>
  314. inline typename enable_if_c<is_convertible<U, number<T, et_on> >::value && is_signed_number<T>::value>::type eval_subtract_default(T& t, const U& u, const T& v)
  315. {
  316. eval_subtract(t, v, u);
  317. t.negate();
  318. }
  319. template <class T, class U>
  320. inline typename enable_if_c<is_convertible<U, number<T, et_on> >::value && !is_convertible<U, T>::value && is_unsigned_number<T>::value>::type eval_subtract_default(T& t, const U& u, const T& v)
  321. {
  322. T temp;
  323. temp = u;
  324. eval_subtract(t, temp, v);
  325. }
  326. template <class T, class U>
  327. inline typename enable_if_c<is_convertible<U, number<T, et_on> >::value && is_convertible<U, T>::value && is_unsigned_number<T>::value>::type eval_subtract_default(T& t, const U& u, const T& v)
  328. {
  329. T temp(u);
  330. eval_subtract(t, temp, v);
  331. }
  332. template <class T, class U, class V>
  333. inline void eval_subtract_default(T& t, const U& u, const V& v)
  334. {
  335. if(is_same<T, V>::value && ((void*)&t == (void*)&v))
  336. {
  337. eval_subtract(t, u);
  338. t.negate();
  339. }
  340. else
  341. {
  342. t = u;
  343. eval_subtract(t, v);
  344. }
  345. }
  346. template <class T, class U, class V>
  347. inline void eval_subtract(T& t, const U& u, const V& v)
  348. {
  349. eval_subtract_default(t, u, v);
  350. }
  351. template <class T>
  352. inline void eval_multiply_default(T& t, const T& u, const T& v)
  353. {
  354. if(&t == &v)
  355. {
  356. eval_multiply(t, u);
  357. }
  358. else if(&t == &u)
  359. {
  360. eval_multiply(t, v);
  361. }
  362. else
  363. {
  364. t = u;
  365. eval_multiply(t, v);
  366. }
  367. }
  368. #if !BOOST_WORKAROUND(BOOST_MSVC, < 1900)
  369. template <class T, class U>
  370. inline typename enable_if_c<is_convertible<U, number<T, et_on> >::value && !is_convertible<U, T>::value>::type eval_multiply_default(T& t, const T& u, const U& v)
  371. {
  372. T vv;
  373. vv = v;
  374. eval_multiply(t, u, vv);
  375. }
  376. template <class T, class U>
  377. inline typename enable_if_c<is_convertible<U, number<T, et_on> >::value && is_convertible<U, T>::value>::type eval_multiply_default(T& t, const T& u, const U& v)
  378. {
  379. T vv(v);
  380. eval_multiply(t, u, vv);
  381. }
  382. template <class T, class U>
  383. inline typename enable_if_c<is_convertible<U, number<T, et_on> >::value>::type eval_multiply_default(T& t, const U& u, const T& v)
  384. {
  385. eval_multiply(t, v, u);
  386. }
  387. #endif
  388. template <class T, class U, class V>
  389. inline void eval_multiply_default(T& t, const U& u, const V& v)
  390. {
  391. if(is_same<T, V>::value && ((void*)&t == (void*)&v))
  392. {
  393. eval_multiply(t, u);
  394. }
  395. else
  396. {
  397. t = number<T>::canonical_value(u);
  398. eval_multiply(t, v);
  399. }
  400. }
  401. template <class T, class U, class V>
  402. inline void eval_multiply(T& t, const U& u, const V& v)
  403. {
  404. eval_multiply_default(t, u, v);
  405. }
  406. template <class T>
  407. inline void eval_multiply_add(T& t, const T& u, const T& v, const T& x)
  408. {
  409. if((void*)&x == (void*)&t)
  410. {
  411. T z;
  412. z = number<T>::canonical_value(x);
  413. eval_multiply_add(t, u, v, z);
  414. }
  415. else
  416. {
  417. eval_multiply(t, u, v);
  418. eval_add(t, x);
  419. }
  420. }
  421. template <class T, class U>
  422. inline typename boost::disable_if_c<boost::is_same<T, U>::value, T>::type make_T(const U& u)
  423. {
  424. T t;
  425. t = number<T>::canonical_value(u);
  426. return BOOST_MP_MOVE(t);
  427. }
  428. template <class T>
  429. inline const T& make_T(const T& t)
  430. {
  431. return t;
  432. }
  433. template <class T, class U, class V, class X>
  434. inline typename disable_if_c<!is_same<T, U>::value && is_same<T, V>::value>::type eval_multiply_add(T& t, const U& u, const V& v, const X& x)
  435. {
  436. eval_multiply_add(t, make_T<T>(u), make_T<T>(v), make_T<T>(x));
  437. }
  438. template <class T, class U, class V, class X>
  439. inline typename enable_if_c<!is_same<T, U>::value && is_same<T, V>::value>::type eval_multiply_add(T& t, const U& u, const V& v, const X& x)
  440. {
  441. eval_multiply_add(t, v, u, x);
  442. }
  443. template <class T, class U, class V, class X>
  444. inline typename disable_if_c<!is_same<T, U>::value && is_same<T, V>::value>::type eval_multiply_subtract(T& t, const U& u, const V& v, const X& x)
  445. {
  446. if((void*)&x == (void*)&t)
  447. {
  448. T z;
  449. z = x;
  450. eval_multiply_subtract(t, u, v, z);
  451. }
  452. else
  453. {
  454. eval_multiply(t, u, v);
  455. eval_subtract(t, x);
  456. }
  457. }
  458. template <class T, class U, class V, class X>
  459. inline typename enable_if_c<!is_same<T, U>::value && is_same<T, V>::value>::type eval_multiply_subtract(T& t, const U& u, const V& v, const X& x)
  460. {
  461. eval_multiply_subtract(t, v, u, x);
  462. }
  463. template <class T, class U, class V>
  464. void eval_divide(T& t, const U& u, const V& v);
  465. template <class T>
  466. inline void eval_divide_default(T& t, const T& u, const T& v)
  467. {
  468. if(&t == &u)
  469. eval_divide(t, v);
  470. else if(&t == &v)
  471. {
  472. T temp;
  473. eval_divide(temp, u, v);
  474. temp.swap(t);
  475. }
  476. else
  477. {
  478. t = u;
  479. eval_divide(t, v);
  480. }
  481. }
  482. #if !BOOST_WORKAROUND(BOOST_MSVC, < 1900)
  483. template <class T, class U>
  484. inline typename enable_if_c<is_convertible<U, number<T, et_on> >::value && !is_convertible<U, T>::value>::type eval_divide_default(T& t, const T& u, const U& v)
  485. {
  486. T vv;
  487. vv = v;
  488. eval_divide(t, u, vv);
  489. }
  490. template <class T, class U>
  491. inline typename enable_if_c<is_convertible<U, number<T, et_on> >::value && is_convertible<U, T>::value>::type eval_divide_default(T& t, const T& u, const U& v)
  492. {
  493. T vv(v);
  494. eval_divide(t, u, vv);
  495. }
  496. template <class T, class U>
  497. inline typename enable_if_c<is_convertible<U, number<T, et_on> >::value && !is_convertible<U, T>::value>::type eval_divide_default(T& t, const U& u, const T& v)
  498. {
  499. T uu;
  500. uu = u;
  501. eval_divide(t, uu, v);
  502. }
  503. template <class T, class U>
  504. inline typename enable_if_c<is_convertible<U, number<T, et_on> >::value && is_convertible<U, T>::value>::type eval_divide_default(T& t, const U& u, const T& v)
  505. {
  506. T uu(u);
  507. eval_divide(t, uu, v);
  508. }
  509. #endif
  510. template <class T, class U, class V>
  511. inline void eval_divide_default(T& t, const U& u, const V& v)
  512. {
  513. if(is_same<T, V>::value && ((void*)&t == (void*)&v))
  514. {
  515. T temp;
  516. temp = u;
  517. eval_divide(temp, v);
  518. t = temp;
  519. }
  520. else
  521. {
  522. t = u;
  523. eval_divide(t, v);
  524. }
  525. }
  526. template <class T, class U, class V>
  527. inline void eval_divide(T& t, const U& u, const V& v)
  528. {
  529. eval_divide_default(t, u, v);
  530. }
  531. template <class T, class U, class V>
  532. void eval_modulus(T& t, const U& u, const V& v);
  533. template <class T>
  534. inline void eval_modulus_default(T& t, const T& u, const T& v)
  535. {
  536. if(&t == &u)
  537. eval_modulus(t, v);
  538. else if(&t == &v)
  539. {
  540. T temp;
  541. eval_modulus(temp, u, v);
  542. temp.swap(t);
  543. }
  544. else
  545. {
  546. t = u;
  547. eval_modulus(t, v);
  548. }
  549. }
  550. template <class T, class U>
  551. inline typename enable_if_c<is_convertible<U, number<T, et_on> >::value && !is_convertible<U, T>::value>::type eval_modulus_default(T& t, const T& u, const U& v)
  552. {
  553. T vv;
  554. vv = v;
  555. eval_modulus(t, u, vv);
  556. }
  557. template <class T, class U>
  558. inline typename enable_if_c<is_convertible<U, number<T, et_on> >::value && is_convertible<U, T>::value>::type eval_modulus_default(T& t, const T& u, const U& v)
  559. {
  560. T vv(v);
  561. eval_modulus(t, u, vv);
  562. }
  563. template <class T, class U>
  564. inline typename enable_if_c<is_convertible<U, number<T, et_on> >::value && !is_convertible<U, T>::value>::type eval_modulus_default(T& t, const U& u, const T& v)
  565. {
  566. T uu;
  567. uu = u;
  568. eval_modulus(t, uu, v);
  569. }
  570. template <class T, class U>
  571. inline typename enable_if_c<is_convertible<U, number<T, et_on> >::value && is_convertible<U, T>::value>::type eval_modulus_default(T& t, const U& u, const T& v)
  572. {
  573. T uu(u);
  574. eval_modulus(t, uu, v);
  575. }
  576. template <class T, class U, class V>
  577. inline void eval_modulus_default(T& t, const U& u, const V& v)
  578. {
  579. if(is_same<T, V>::value && ((void*)&t == (void*)&v))
  580. {
  581. T temp(u);
  582. eval_modulus(temp, v);
  583. t = temp;
  584. }
  585. else
  586. {
  587. t = u;
  588. eval_modulus(t, v);
  589. }
  590. }
  591. template <class T, class U, class V>
  592. inline void eval_modulus(T& t, const U& u, const V& v)
  593. {
  594. eval_modulus_default(t, u, v);
  595. }
  596. template <class T, class U, class V>
  597. void eval_bitwise_and(T& t, const U& u, const V& v);
  598. template <class T>
  599. inline void eval_bitwise_and_default(T& t, const T& u, const T& v)
  600. {
  601. if(&t == &v)
  602. {
  603. eval_bitwise_and(t, u);
  604. }
  605. else if(&t == &u)
  606. {
  607. eval_bitwise_and(t, v);
  608. }
  609. else
  610. {
  611. t = u;
  612. eval_bitwise_and(t, v);
  613. }
  614. }
  615. template <class T, class U>
  616. inline typename disable_if_c<is_convertible<U, T>::value>::type eval_bitwise_and_default(T& t, const T& u, const U& v)
  617. {
  618. T vv;
  619. vv = v;
  620. eval_bitwise_and(t, u, vv);
  621. }
  622. template <class T, class U>
  623. inline typename enable_if_c<is_convertible<U, T>::value>::type eval_bitwise_and_default(T& t, const T& u, const U& v)
  624. {
  625. T vv(v);
  626. eval_bitwise_and(t, u, vv);
  627. }
  628. template <class T, class U>
  629. inline typename enable_if_c<is_convertible<U, number<T, et_on> >::value>::type eval_bitwise_and_default(T& t, const U& u, const T& v)
  630. {
  631. eval_bitwise_and(t, v, u);
  632. }
  633. template <class T, class U, class V>
  634. inline typename disable_if_c<is_same<T, U>::value || is_same<T, V>::value>::type eval_bitwise_and_default(T& t, const U& u, const V& v)
  635. {
  636. t = u;
  637. eval_bitwise_and(t, v);
  638. }
  639. template <class T, class U, class V>
  640. inline void eval_bitwise_and(T& t, const U& u, const V& v)
  641. {
  642. eval_bitwise_and_default(t, u, v);
  643. }
  644. template <class T, class U, class V>
  645. void eval_bitwise_or(T& t, const U& u, const V& v);
  646. template <class T>
  647. inline void eval_bitwise_or_default(T& t, const T& u, const T& v)
  648. {
  649. if(&t == &v)
  650. {
  651. eval_bitwise_or(t, u);
  652. }
  653. else if(&t == &u)
  654. {
  655. eval_bitwise_or(t, v);
  656. }
  657. else
  658. {
  659. t = u;
  660. eval_bitwise_or(t, v);
  661. }
  662. }
  663. template <class T, class U>
  664. inline typename enable_if_c<is_convertible<U, number<T, et_on> >::value && !is_convertible<U, T>::value>::type eval_bitwise_or_default(T& t, const T& u, const U& v)
  665. {
  666. T vv;
  667. vv = v;
  668. eval_bitwise_or(t, u, vv);
  669. }
  670. template <class T, class U>
  671. inline typename enable_if_c<is_convertible<U, number<T, et_on> >::value && is_convertible<U, T>::value>::type eval_bitwise_or_default(T& t, const T& u, const U& v)
  672. {
  673. T vv(v);
  674. eval_bitwise_or(t, u, vv);
  675. }
  676. template <class T, class U>
  677. inline typename enable_if_c<is_convertible<U, number<T, et_on> >::value>::type eval_bitwise_or_default(T& t, const U& u, const T& v)
  678. {
  679. eval_bitwise_or(t, v, u);
  680. }
  681. template <class T, class U, class V>
  682. inline void eval_bitwise_or_default(T& t, const U& u, const V& v)
  683. {
  684. if(is_same<T, V>::value && ((void*)&t == (void*)&v))
  685. {
  686. eval_bitwise_or(t, u);
  687. }
  688. else
  689. {
  690. t = u;
  691. eval_bitwise_or(t, v);
  692. }
  693. }
  694. template <class T, class U, class V>
  695. inline void eval_bitwise_or(T& t, const U& u, const V& v)
  696. {
  697. eval_bitwise_or_default(t, u, v);
  698. }
  699. template <class T, class U, class V>
  700. void eval_bitwise_xor(T& t, const U& u, const V& v);
  701. template <class T>
  702. inline void eval_bitwise_xor_default(T& t, const T& u, const T& v)
  703. {
  704. if(&t == &v)
  705. {
  706. eval_bitwise_xor(t, u);
  707. }
  708. else if(&t == &u)
  709. {
  710. eval_bitwise_xor(t, v);
  711. }
  712. else
  713. {
  714. t = u;
  715. eval_bitwise_xor(t, v);
  716. }
  717. }
  718. template <class T, class U>
  719. inline typename enable_if_c<is_convertible<U, number<T, et_on> >::value && !is_convertible<U, T>::value>::type eval_bitwise_xor_default(T& t, const T& u, const U& v)
  720. {
  721. T vv;
  722. vv = v;
  723. eval_bitwise_xor(t, u, vv);
  724. }
  725. template <class T, class U>
  726. inline typename enable_if_c<is_convertible<U, number<T, et_on> >::value && is_convertible<U, T>::value>::type eval_bitwise_xor_default(T& t, const T& u, const U& v)
  727. {
  728. T vv(v);
  729. eval_bitwise_xor(t, u, vv);
  730. }
  731. template <class T, class U>
  732. inline typename enable_if_c<is_convertible<U, number<T, et_on> >::value>::type eval_bitwise_xor_default(T& t, const U& u, const T& v)
  733. {
  734. eval_bitwise_xor(t, v, u);
  735. }
  736. template <class T, class U, class V>
  737. inline void eval_bitwise_xor_default(T& t, const U& u, const V& v)
  738. {
  739. if(is_same<T, V>::value && ((void*)&t == (void*)&v))
  740. {
  741. eval_bitwise_xor(t, u);
  742. }
  743. else
  744. {
  745. t = u;
  746. eval_bitwise_xor(t, v);
  747. }
  748. }
  749. template <class T, class U, class V>
  750. inline void eval_bitwise_xor(T& t, const U& u, const V& v)
  751. {
  752. eval_bitwise_xor_default(t, u, v);
  753. }
  754. template <class T>
  755. inline void eval_increment(T& val)
  756. {
  757. typedef typename mpl::front<typename T::unsigned_types>::type ui_type;
  758. eval_add(val, static_cast<ui_type>(1u));
  759. }
  760. template <class T>
  761. inline void eval_decrement(T& val)
  762. {
  763. typedef typename mpl::front<typename T::unsigned_types>::type ui_type;
  764. eval_subtract(val, static_cast<ui_type>(1u));
  765. }
  766. template <class T, class V>
  767. inline void eval_left_shift(T& result, const T& arg, const V val)
  768. {
  769. result = arg;
  770. eval_left_shift(result, val);
  771. }
  772. template <class T, class V>
  773. inline void eval_right_shift(T& result, const T& arg, const V val)
  774. {
  775. result = arg;
  776. eval_right_shift(result, val);
  777. }
  778. template <class T>
  779. inline bool eval_is_zero(const T& val)
  780. {
  781. typedef typename mpl::front<typename T::unsigned_types>::type ui_type;
  782. return val.compare(static_cast<ui_type>(0)) == 0;
  783. }
  784. template <class T>
  785. inline int eval_get_sign(const T& val)
  786. {
  787. typedef typename mpl::front<typename T::unsigned_types>::type ui_type;
  788. return val.compare(static_cast<ui_type>(0));
  789. }
  790. template <class T, class V, class U>
  791. inline void assign_components_imp(T& result, const V& v1, const U& v2, const mpl::int_<number_kind_rational>&)
  792. {
  793. result = v1;
  794. T t;
  795. t = v2;
  796. eval_divide(result, t);
  797. }
  798. template <class T, class V, class U, int N>
  799. inline void assign_components_imp(T& result, const V& v1, const U& v2, const mpl::int_<N>&)
  800. {
  801. typedef typename component_type<number<T> >::type component_number_type;
  802. component_number_type x(v1), y(v2);
  803. assign_components(result, x.backend(), y.backend());
  804. }
  805. template <class T, class V, class U>
  806. inline void assign_components(T& result, const V& v1, const U& v2)
  807. {
  808. return assign_components_imp(result, v1, v2, typename number_category<T>::type());
  809. }
  810. #ifndef BOOST_NO_CXX17_HDR_STRING_VIEW
  811. template <class Result, class Traits>
  812. inline void assign_from_string_view(Result& result, const std::basic_string_view<char, Traits>& view)
  813. {
  814. // since most (all?) backends require a const char* to construct from, we just
  815. // convert to that:
  816. std::string s(view);
  817. result = s.c_str();
  818. }
  819. template <class Result, class Traits>
  820. inline void assign_from_string_view(Result& result, const std::basic_string_view<char, Traits>& view_x, const std::basic_string_view<char, Traits>& view_y)
  821. {
  822. // since most (all?) backends require a const char* to construct from, we just
  823. // convert to that:
  824. std::string x(view_x), y(view_y);
  825. assign_components(result, x.c_str(), y.c_str());
  826. }
  827. #endif
  828. template <class R, int b>
  829. struct has_enough_bits
  830. {
  831. template <class T>
  832. struct type : public mpl::and_<mpl::not_<is_same<R, T> >, mpl::bool_<std::numeric_limits<T>::digits >= b> >{};
  833. };
  834. template <class R>
  835. struct terminal
  836. {
  837. terminal(const R& v) : value(v){}
  838. terminal(){}
  839. terminal& operator = (R val) { value = val; return *this; }
  840. R value;
  841. operator R()const { return value; }
  842. };
  843. template<class R, class B>
  844. struct calculate_next_larger_type
  845. {
  846. // Find which list we're looking through:
  847. typedef typename mpl::if_<
  848. is_signed<R>,
  849. typename B::signed_types,
  850. typename mpl::if_<
  851. is_unsigned<R>,
  852. typename B::unsigned_types,
  853. typename B::float_types
  854. >::type
  855. >::type list_type;
  856. // A predicate to find a type with enough bits:
  857. typedef typename has_enough_bits<R, std::numeric_limits<R>::digits>::template type<mpl::_> pred_type;
  858. // See if the last type is in the list, if so we have to start after this:
  859. typedef typename mpl::find_if<
  860. list_type,
  861. is_same<R, mpl::_>
  862. >::type start_last;
  863. // Where we're starting from, either the start of the sequence or the last type found:
  864. typedef typename mpl::if_<is_same<start_last, typename mpl::end<list_type>::type>, typename mpl::begin<list_type>::type, start_last>::type start_seq;
  865. // The range we're searching:
  866. typedef mpl::iterator_range<start_seq, typename mpl::end<list_type>::type> range;
  867. // Find the next type:
  868. typedef typename mpl::find_if<
  869. range,
  870. pred_type
  871. >::type iter_type;
  872. // Either the next type, or a "terminal" to indicate we've run out of types to search:
  873. typedef typename mpl::eval_if<
  874. is_same<typename mpl::end<list_type>::type, iter_type>,
  875. mpl::identity<terminal<R> >,
  876. mpl::deref<iter_type>
  877. >::type type;
  878. };
  879. template <class R, class T>
  880. inline typename boost::enable_if_c<boost::is_integral<R>::value, bool>::type check_in_range(const T& t)
  881. {
  882. // Can t fit in an R?
  883. if((t > 0) && std::numeric_limits<R>::is_specialized && std::numeric_limits<R>::is_bounded && (t > (std::numeric_limits<R>::max)()))
  884. return true;
  885. else
  886. return false;
  887. }
  888. template <class R, class B>
  889. inline typename boost::enable_if_c<boost::is_integral<R>::value>::type eval_convert_to(R* result, const B& backend)
  890. {
  891. typedef typename calculate_next_larger_type<R, B>::type next_type;
  892. next_type n;
  893. eval_convert_to(&n, backend);
  894. if(!boost::is_unsigned<R>::value && std::numeric_limits<R>::is_specialized && std::numeric_limits<R>::is_bounded && (n > (next_type)(std::numeric_limits<R>::max)()))
  895. {
  896. *result = (std::numeric_limits<R>::max)();
  897. }
  898. else if (std::numeric_limits<R>::is_specialized && std::numeric_limits<R>::is_bounded && (n < (next_type)(std::numeric_limits<R>::min)()))
  899. {
  900. *result = (std::numeric_limits<R>::min)();
  901. }
  902. else
  903. *result = static_cast<R>(n);
  904. }
  905. template <class R, class B>
  906. inline typename boost::disable_if_c<boost::is_integral<R>::value>::type eval_convert_to(R* result, const B& backend)
  907. {
  908. typedef typename calculate_next_larger_type<R, B>::type next_type;
  909. next_type n;
  910. eval_convert_to(&n, backend);
  911. if(std::numeric_limits<R>::is_specialized && std::numeric_limits<R>::is_bounded && ((n > (next_type)(std::numeric_limits<R>::max)() || (n < (next_type)-(std::numeric_limits<R>::max)()) )))
  912. {
  913. *result = n > 0 ? (std::numeric_limits<R>::max)() : -(std::numeric_limits<R>::max)();
  914. }
  915. else
  916. *result = static_cast<R>(n);
  917. }
  918. template <class R, class B>
  919. inline void last_chance_eval_convert_to(terminal<R>* result, const B& backend, const mpl::false_&)
  920. {
  921. //
  922. // We ran out of types to try for the conversion, try
  923. // a lexical_cast and hope for the best:
  924. //
  925. if (std::numeric_limits<R>::is_integer && !std::numeric_limits<R>::is_signed && (eval_get_sign(backend) < 0))
  926. BOOST_THROW_EXCEPTION(std::range_error("Attempt to convert negative value to an unsigned integer results in undefined behaviour"));
  927. try
  928. {
  929. result->value = boost::lexical_cast<R>(backend.str(0, std::ios_base::fmtflags(0)));
  930. }
  931. catch (const bad_lexical_cast&)
  932. {
  933. if (eval_get_sign(backend) < 0)
  934. {
  935. *result = std::numeric_limits<R>::is_integer && std::numeric_limits<R>::is_signed ? (std::numeric_limits<R>::min)() : -(std::numeric_limits<R>::max)();
  936. }
  937. else
  938. *result = (std::numeric_limits<R>::max)();
  939. }
  940. }
  941. template <class R, class B>
  942. inline void last_chance_eval_convert_to(terminal<R>* result, const B& backend, const mpl::true_&)
  943. {
  944. //
  945. // We ran out of types to try for the conversion, try
  946. // a lexical_cast and hope for the best:
  947. //
  948. if (std::numeric_limits<R>::is_integer && !std::numeric_limits<R>::is_signed && (eval_get_sign(backend) < 0))
  949. BOOST_THROW_EXCEPTION(std::range_error("Attempt to convert negative value to an unsigned integer results in undefined behaviour"));
  950. try
  951. {
  952. B t(backend);
  953. R mask = ~static_cast<R>(0u);
  954. eval_bitwise_and(t, mask);
  955. result->value = boost::lexical_cast<R>(t.str(0, std::ios_base::fmtflags(0)));
  956. }
  957. catch (const bad_lexical_cast&)
  958. {
  959. if (eval_get_sign(backend) < 0)
  960. {
  961. *result = std::numeric_limits<R>::is_integer && std::numeric_limits<R>::is_signed ? (std::numeric_limits<R>::min)() : -(std::numeric_limits<R>::max)();
  962. }
  963. else
  964. *result = (std::numeric_limits<R>::max)();
  965. }
  966. }
  967. template <class R, class B>
  968. inline void eval_convert_to(terminal<R>* result, const B& backend)
  969. {
  970. typedef mpl::bool_<boost::is_unsigned<R>::value && number_category<B>::value == number_kind_integer> tag_type;
  971. last_chance_eval_convert_to(result, backend, tag_type());
  972. }
  973. template <class B1, class B2, expression_template_option et>
  974. inline void eval_convert_to(terminal<number<B1, et> >* result, const B2& backend)
  975. {
  976. //
  977. // We ran out of types to try for the conversion, try
  978. // a generic conversion and hope for the best:
  979. //
  980. boost::multiprecision::detail::generic_interconvert(result->value.backend(), backend, number_category<B1>(), number_category<B2>());
  981. }
  982. template <class B>
  983. inline void eval_convert_to(std::string* result, const B& backend)
  984. {
  985. *result = backend.str(0, std::ios_base::fmtflags(0));
  986. }
  987. template <class B>
  988. inline void eval_convert_to(std::complex<float>* result, const B& backend)
  989. {
  990. typedef typename scalar_result_from_possible_complex<multiprecision::number<B> >::type scalar_type;
  991. scalar_type re, im;
  992. eval_real(re.backend(), backend);
  993. eval_imag(im.backend(), backend);
  994. *result = std::complex<float>(re.template convert_to<float>(), im.template convert_to<float>());
  995. }
  996. template <class B>
  997. inline void eval_convert_to(std::complex<double>* result, const B& backend)
  998. {
  999. typedef typename scalar_result_from_possible_complex<multiprecision::number<B> >::type scalar_type;
  1000. scalar_type re, im;
  1001. eval_real(re.backend(), backend);
  1002. eval_imag(im.backend(), backend);
  1003. *result = std::complex<double>(re.template convert_to<double>(), im.template convert_to<double>());
  1004. }
  1005. template <class B>
  1006. inline void eval_convert_to(std::complex<long double>* result, const B& backend)
  1007. {
  1008. typedef typename scalar_result_from_possible_complex<multiprecision::number<B> >::type scalar_type;
  1009. scalar_type re, im;
  1010. eval_real(re.backend(), backend);
  1011. eval_imag(im.backend(), backend);
  1012. *result = std::complex<long double>(re.template convert_to<long double>(), im.template convert_to<long double>());
  1013. }
  1014. //
  1015. // Functions:
  1016. //
  1017. template <class T>
  1018. void eval_abs(T& result, const T& arg)
  1019. {
  1020. typedef typename T::signed_types type_list;
  1021. typedef typename mpl::front<type_list>::type front;
  1022. result = arg;
  1023. if(arg.compare(front(0)) < 0)
  1024. result.negate();
  1025. }
  1026. template <class T>
  1027. void eval_fabs(T& result, const T& arg)
  1028. {
  1029. BOOST_STATIC_ASSERT_MSG(number_category<T>::value == number_kind_floating_point, "The fabs function is only valid for floating point types.");
  1030. typedef typename T::signed_types type_list;
  1031. typedef typename mpl::front<type_list>::type front;
  1032. result = arg;
  1033. if(arg.compare(front(0)) < 0)
  1034. result.negate();
  1035. }
  1036. template <class Backend>
  1037. inline int eval_fpclassify(const Backend& arg)
  1038. {
  1039. BOOST_STATIC_ASSERT_MSG(number_category<Backend>::value == number_kind_floating_point, "The fpclassify function is only valid for floating point types.");
  1040. return eval_is_zero(arg) ? FP_ZERO : FP_NORMAL;
  1041. }
  1042. template <class T>
  1043. inline void eval_fmod(T& result, const T& a, const T& b)
  1044. {
  1045. BOOST_STATIC_ASSERT_MSG(number_category<T>::value == number_kind_floating_point, "The fmod function is only valid for floating point types.");
  1046. if((&result == &a) || (&result == &b))
  1047. {
  1048. T temp;
  1049. eval_fmod(temp, a, b);
  1050. result = temp;
  1051. return;
  1052. }
  1053. switch(eval_fpclassify(a))
  1054. {
  1055. case FP_ZERO:
  1056. result = a;
  1057. return;
  1058. case FP_INFINITE:
  1059. case FP_NAN:
  1060. result = std::numeric_limits<number<T> >::quiet_NaN().backend();
  1061. errno = EDOM;
  1062. return;
  1063. }
  1064. switch(eval_fpclassify(b))
  1065. {
  1066. case FP_ZERO:
  1067. case FP_NAN:
  1068. result = std::numeric_limits<number<T> >::quiet_NaN().backend();
  1069. errno = EDOM;
  1070. return;
  1071. }
  1072. T n;
  1073. eval_divide(result, a, b);
  1074. if(eval_get_sign(result) < 0)
  1075. eval_ceil(n, result);
  1076. else
  1077. eval_floor(n, result);
  1078. eval_multiply(n, b);
  1079. eval_subtract(result, a, n);
  1080. }
  1081. template<class T, class A>
  1082. inline typename enable_if<is_arithmetic<A>, void>::type eval_fmod(T& result, const T& x, const A& a)
  1083. {
  1084. typedef typename boost::multiprecision::detail::canonical<A, T>::type canonical_type;
  1085. typedef typename mpl::if_<is_same<A, canonical_type>, T, canonical_type>::type cast_type;
  1086. cast_type c;
  1087. c = a;
  1088. eval_fmod(result, x, c);
  1089. }
  1090. template<class T, class A>
  1091. inline typename enable_if<is_arithmetic<A>, void>::type eval_fmod(T& result, const A& x, const T& a)
  1092. {
  1093. typedef typename boost::multiprecision::detail::canonical<A, T>::type canonical_type;
  1094. typedef typename mpl::if_<is_same<A, canonical_type>, T, canonical_type>::type cast_type;
  1095. cast_type c;
  1096. c = x;
  1097. eval_fmod(result, c, a);
  1098. }
  1099. template <class T>
  1100. void eval_round(T& result, const T& a);
  1101. template <class T>
  1102. inline void eval_remquo(T& result, const T& a, const T& b, int* pi)
  1103. {
  1104. BOOST_STATIC_ASSERT_MSG(number_category<T>::value == number_kind_floating_point, "The remquo function is only valid for floating point types.");
  1105. if((&result == &a) || (&result == &b))
  1106. {
  1107. T temp;
  1108. eval_remquo(temp, a, b, pi);
  1109. result = temp;
  1110. return;
  1111. }
  1112. T n;
  1113. eval_divide(result, a, b);
  1114. eval_round(n, result);
  1115. eval_convert_to(pi, n);
  1116. eval_multiply(n, b);
  1117. eval_subtract(result, a, n);
  1118. }
  1119. template<class T, class A>
  1120. inline typename enable_if<is_arithmetic<A>, void>::type eval_remquo(T& result, const T& x, const A& a, int* pi)
  1121. {
  1122. typedef typename boost::multiprecision::detail::canonical<A, T>::type canonical_type;
  1123. typedef typename mpl::if_<is_same<A, canonical_type>, T, canonical_type>::type cast_type;
  1124. cast_type c;
  1125. c = a;
  1126. eval_remquo(result, x, c, pi);
  1127. }
  1128. template<class T, class A>
  1129. inline typename enable_if<is_arithmetic<A>, void>::type eval_remquo(T& result, const A& x, const T& a, int* pi)
  1130. {
  1131. typedef typename boost::multiprecision::detail::canonical<A, T>::type canonical_type;
  1132. typedef typename mpl::if_<is_same<A, canonical_type>, T, canonical_type>::type cast_type;
  1133. cast_type c;
  1134. c = x;
  1135. eval_remquo(result, c, a, pi);
  1136. }
  1137. template <class T, class U, class V>
  1138. inline void eval_remainder(T& result, const U& a, const V& b)
  1139. {
  1140. int i;
  1141. eval_remquo(result, a, b, &i);
  1142. }
  1143. template <class B>
  1144. bool eval_gt(const B& a, const B& b);
  1145. template <class T, class U>
  1146. bool eval_gt(const T& a, const U& b);
  1147. template <class B>
  1148. bool eval_lt(const B& a, const B& b);
  1149. template <class T, class U>
  1150. bool eval_lt(const T& a, const U& b);
  1151. template<class T>
  1152. inline void eval_fdim(T& result, const T& a, const T& b)
  1153. {
  1154. typedef typename boost::multiprecision::detail::canonical<unsigned, T>::type ui_type;
  1155. static const ui_type zero = 0u;
  1156. switch(eval_fpclassify(b))
  1157. {
  1158. case FP_NAN:
  1159. case FP_INFINITE:
  1160. result = zero;
  1161. return;
  1162. }
  1163. switch(eval_fpclassify(a))
  1164. {
  1165. case FP_NAN:
  1166. result = zero;
  1167. return;
  1168. case FP_INFINITE:
  1169. result = a;
  1170. return;
  1171. }
  1172. if(eval_gt(a, b))
  1173. {
  1174. eval_subtract(result, a, b);
  1175. }
  1176. else
  1177. result = zero;
  1178. }
  1179. template<class T, class A>
  1180. inline typename boost::enable_if_c<boost::is_arithmetic<A>::value>::type eval_fdim(T& result, const T& a, const A& b)
  1181. {
  1182. typedef typename boost::multiprecision::detail::canonical<unsigned, T>::type ui_type;
  1183. typedef typename boost::multiprecision::detail::canonical<A, T>::type arithmetic_type;
  1184. static const ui_type zero = 0u;
  1185. arithmetic_type canonical_b = b;
  1186. switch((::boost::math::fpclassify)(b))
  1187. {
  1188. case FP_NAN:
  1189. case FP_INFINITE:
  1190. result = zero;
  1191. return;
  1192. }
  1193. switch(eval_fpclassify(a))
  1194. {
  1195. case FP_NAN:
  1196. result = zero;
  1197. return;
  1198. case FP_INFINITE:
  1199. result = a;
  1200. return;
  1201. }
  1202. if(eval_gt(a, canonical_b))
  1203. {
  1204. eval_subtract(result, a, canonical_b);
  1205. }
  1206. else
  1207. result = zero;
  1208. }
  1209. template<class T, class A>
  1210. inline typename boost::enable_if_c<boost::is_arithmetic<A>::value>::type eval_fdim(T& result, const A& a, const T& b)
  1211. {
  1212. typedef typename boost::multiprecision::detail::canonical<unsigned, T>::type ui_type;
  1213. typedef typename boost::multiprecision::detail::canonical<A, T>::type arithmetic_type;
  1214. static const ui_type zero = 0u;
  1215. arithmetic_type canonical_a = a;
  1216. switch(eval_fpclassify(b))
  1217. {
  1218. case FP_NAN:
  1219. case FP_INFINITE:
  1220. result = zero;
  1221. return;
  1222. }
  1223. switch((::boost::math::fpclassify)(a))
  1224. {
  1225. case FP_NAN:
  1226. result = zero;
  1227. return;
  1228. case FP_INFINITE:
  1229. result = std::numeric_limits<number<T> >::infinity().backend();
  1230. return;
  1231. }
  1232. if(eval_gt(canonical_a, b))
  1233. {
  1234. eval_subtract(result, canonical_a, b);
  1235. }
  1236. else
  1237. result = zero;
  1238. }
  1239. template <class T>
  1240. inline void eval_trunc(T& result, const T& a)
  1241. {
  1242. BOOST_STATIC_ASSERT_MSG(number_category<T>::value == number_kind_floating_point, "The trunc function is only valid for floating point types.");
  1243. switch(eval_fpclassify(a))
  1244. {
  1245. case FP_NAN:
  1246. errno = EDOM;
  1247. // fallthrough...
  1248. case FP_ZERO:
  1249. case FP_INFINITE:
  1250. result = a;
  1251. return;
  1252. }
  1253. if(eval_get_sign(a) < 0)
  1254. eval_ceil(result, a);
  1255. else
  1256. eval_floor(result, a);
  1257. }
  1258. template <class T>
  1259. inline void eval_modf(T& result, T const& arg, T* pipart)
  1260. {
  1261. typedef typename boost::multiprecision::detail::canonical<unsigned, T>::type ui_type;
  1262. int c = eval_fpclassify(arg);
  1263. if(c == (int)FP_NAN)
  1264. {
  1265. if(pipart)
  1266. *pipart = arg;
  1267. result = arg;
  1268. return;
  1269. }
  1270. else if(c == (int)FP_INFINITE)
  1271. {
  1272. if(pipart)
  1273. *pipart = arg;
  1274. result = ui_type(0u);
  1275. return;
  1276. }
  1277. if(pipart)
  1278. {
  1279. eval_trunc(*pipart, arg);
  1280. eval_subtract(result, arg, *pipart);
  1281. }
  1282. else
  1283. {
  1284. T ipart;
  1285. eval_trunc(ipart, arg);
  1286. eval_subtract(result, arg, ipart);
  1287. }
  1288. }
  1289. template <class T>
  1290. inline void eval_round(T& result, const T& a)
  1291. {
  1292. BOOST_STATIC_ASSERT_MSG(number_category<T>::value == number_kind_floating_point, "The round function is only valid for floating point types.");
  1293. typedef typename boost::multiprecision::detail::canonical<float, T>::type fp_type;
  1294. int c = eval_fpclassify(a);
  1295. if(c == (int)FP_NAN)
  1296. {
  1297. result = a;
  1298. errno = EDOM;
  1299. return;
  1300. }
  1301. if((c == FP_ZERO) || (c == (int)FP_INFINITE))
  1302. {
  1303. result = a;
  1304. }
  1305. else if(eval_get_sign(a) < 0)
  1306. {
  1307. eval_subtract(result, a, fp_type(0.5f));
  1308. eval_ceil(result, result);
  1309. }
  1310. else
  1311. {
  1312. eval_add(result, a, fp_type(0.5f));
  1313. eval_floor(result, result);
  1314. }
  1315. }
  1316. template <class B>
  1317. void eval_lcm(B& result, const B& a, const B& b);
  1318. template <class B>
  1319. void eval_gcd(B& result, const B& a, const B& b);
  1320. template <class T, class Arithmetic>
  1321. inline typename enable_if<is_integral<Arithmetic> >::type eval_gcd(T& result, const T& a, const Arithmetic& b)
  1322. {
  1323. typedef typename boost::multiprecision::detail::canonical<Arithmetic, T>::type si_type;
  1324. using default_ops::eval_gcd;
  1325. T t;
  1326. t = static_cast<si_type>(b);
  1327. eval_gcd(result, a, t);
  1328. }
  1329. template <class T, class Arithmetic>
  1330. inline typename enable_if<is_integral<Arithmetic> >::type eval_gcd(T& result, const Arithmetic& a, const T& b)
  1331. {
  1332. eval_gcd(result, b, a);
  1333. }
  1334. template <class T, class Arithmetic>
  1335. inline typename enable_if<is_integral<Arithmetic> >::type eval_lcm(T& result, const T& a, const Arithmetic& b)
  1336. {
  1337. typedef typename boost::multiprecision::detail::canonical<Arithmetic, T>::type si_type;
  1338. using default_ops::eval_lcm;
  1339. T t;
  1340. t = static_cast<si_type>(b);
  1341. eval_lcm(result, a, t);
  1342. }
  1343. template <class T, class Arithmetic>
  1344. inline typename enable_if<is_integral<Arithmetic> >::type eval_lcm(T& result, const Arithmetic& a, const T& b)
  1345. {
  1346. eval_lcm(result, b, a);
  1347. }
  1348. template <class T>
  1349. inline unsigned eval_lsb(const T& val)
  1350. {
  1351. typedef typename boost::multiprecision::detail::canonical<unsigned, T>::type ui_type;
  1352. int c = eval_get_sign(val);
  1353. if(c == 0)
  1354. {
  1355. BOOST_THROW_EXCEPTION(std::range_error("No bits were set in the operand."));
  1356. }
  1357. if(c < 0)
  1358. {
  1359. BOOST_THROW_EXCEPTION(std::range_error("Testing individual bits in negative values is not supported - results are undefined."));
  1360. }
  1361. unsigned result = 0;
  1362. T mask, t;
  1363. mask = ui_type(1);
  1364. do
  1365. {
  1366. eval_bitwise_and(t, mask, val);
  1367. ++result;
  1368. eval_left_shift(mask, 1);
  1369. }
  1370. while(eval_is_zero(t));
  1371. return --result;
  1372. }
  1373. template <class T>
  1374. inline int eval_msb(const T& val)
  1375. {
  1376. int c = eval_get_sign(val);
  1377. if(c == 0)
  1378. {
  1379. BOOST_THROW_EXCEPTION(std::range_error("No bits were set in the operand."));
  1380. }
  1381. if(c < 0)
  1382. {
  1383. BOOST_THROW_EXCEPTION(std::range_error("Testing individual bits in negative values is not supported - results are undefined."));
  1384. }
  1385. //
  1386. // This implementation is really really rubbish - it does
  1387. // a linear scan for the most-significant-bit. We should really
  1388. // do a binary search, but as none of our backends actually needs
  1389. // this implementation, we'll leave it for now. In fact for most
  1390. // backends it's likely that there will always be a more efficient
  1391. // native implementation possible.
  1392. //
  1393. unsigned result = 0;
  1394. T t(val);
  1395. while(!eval_is_zero(t))
  1396. {
  1397. eval_right_shift(t, 1);
  1398. ++result;
  1399. }
  1400. return --result;
  1401. }
  1402. template <class T>
  1403. inline bool eval_bit_test(const T& val, unsigned index)
  1404. {
  1405. typedef typename boost::multiprecision::detail::canonical<unsigned, T>::type ui_type;
  1406. T mask, t;
  1407. mask = ui_type(1);
  1408. eval_left_shift(mask, index);
  1409. eval_bitwise_and(t, mask, val);
  1410. return !eval_is_zero(t);
  1411. }
  1412. template <class T>
  1413. inline void eval_bit_set(T& val, unsigned index)
  1414. {
  1415. typedef typename boost::multiprecision::detail::canonical<unsigned, T>::type ui_type;
  1416. T mask;
  1417. mask = ui_type(1);
  1418. eval_left_shift(mask, index);
  1419. eval_bitwise_or(val, mask);
  1420. }
  1421. template <class T>
  1422. inline void eval_bit_flip(T& val, unsigned index)
  1423. {
  1424. typedef typename boost::multiprecision::detail::canonical<unsigned, T>::type ui_type;
  1425. T mask;
  1426. mask = ui_type(1);
  1427. eval_left_shift(mask, index);
  1428. eval_bitwise_xor(val, mask);
  1429. }
  1430. template <class T>
  1431. inline void eval_bit_unset(T& val, unsigned index)
  1432. {
  1433. typedef typename boost::multiprecision::detail::canonical<unsigned, T>::type ui_type;
  1434. T mask, t;
  1435. mask = ui_type(1);
  1436. eval_left_shift(mask, index);
  1437. eval_bitwise_and(t, mask, val);
  1438. if(!eval_is_zero(t))
  1439. eval_bitwise_xor(val, mask);
  1440. }
  1441. template <class B>
  1442. void eval_integer_sqrt(B& s, B& r, const B& x)
  1443. {
  1444. //
  1445. // This is slow bit-by-bit integer square root, see for example
  1446. // http://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Binary_numeral_system_.28base_2.29
  1447. // There are better methods such as http://hal.inria.fr/docs/00/07/28/54/PDF/RR-3805.pdf
  1448. // and http://hal.inria.fr/docs/00/07/21/13/PDF/RR-4475.pdf which should be implemented
  1449. // at some point.
  1450. //
  1451. typedef typename boost::multiprecision::detail::canonical<unsigned char, B>::type ui_type;
  1452. s = ui_type(0u);
  1453. if(eval_get_sign(x) == 0)
  1454. {
  1455. r = ui_type(0u);
  1456. return;
  1457. }
  1458. int g = eval_msb(x);
  1459. if(g <= 1)
  1460. {
  1461. s = ui_type(1);
  1462. eval_subtract(r, x, s);
  1463. return;
  1464. }
  1465. B t;
  1466. r = x;
  1467. g /= 2;
  1468. int org_g = g;
  1469. eval_bit_set(s, g);
  1470. eval_bit_set(t, 2 * g);
  1471. eval_subtract(r, x, t);
  1472. --g;
  1473. if(eval_get_sign(r) == 0)
  1474. return;
  1475. int msbr = eval_msb(r);
  1476. do
  1477. {
  1478. if(msbr >= org_g + g + 1)
  1479. {
  1480. t = s;
  1481. eval_left_shift(t, g + 1);
  1482. eval_bit_set(t, 2 * g);
  1483. if(t.compare(r) <= 0)
  1484. {
  1485. BOOST_ASSERT(g >= 0);
  1486. eval_bit_set(s, g);
  1487. eval_subtract(r, t);
  1488. if(eval_get_sign(r) == 0)
  1489. return;
  1490. msbr = eval_msb(r);
  1491. }
  1492. }
  1493. --g;
  1494. }
  1495. while(g >= 0);
  1496. }
  1497. template <class B>
  1498. inline void eval_conj(B& result, const B& val)
  1499. {
  1500. result = val; // assume non-complex result.
  1501. }
  1502. template <class B>
  1503. inline void eval_proj(B& result, const B& val)
  1504. {
  1505. result = val; // assume non-complex result.
  1506. }
  1507. //
  1508. // These have to implemented by the backend, declared here so that our macro generated code compiles OK.
  1509. //
  1510. template <class T>
  1511. typename enable_if_c<sizeof(T) == 0>::type eval_floor();
  1512. template <class T>
  1513. typename enable_if_c<sizeof(T) == 0>::type eval_ceil();
  1514. template <class T>
  1515. typename enable_if_c<sizeof(T) == 0>::type eval_trunc();
  1516. template <class T>
  1517. typename enable_if_c<sizeof(T) == 0>::type eval_sqrt();
  1518. template <class T>
  1519. typename enable_if_c<sizeof(T) == 0>::type eval_ldexp();
  1520. template <class T>
  1521. typename enable_if_c<sizeof(T) == 0>::type eval_frexp();
  1522. // TODO implement default versions of these:
  1523. template <class T>
  1524. typename enable_if_c<sizeof(T) == 0>::type eval_asinh();
  1525. template <class T>
  1526. typename enable_if_c<sizeof(T) == 0>::type eval_acosh();
  1527. template <class T>
  1528. typename enable_if_c<sizeof(T) == 0>::type eval_atanh();
  1529. //
  1530. // eval_logb and eval_scalbn simply assume base 2 and forward to
  1531. // eval_ldexp and eval_frexp:
  1532. //
  1533. template <class B>
  1534. inline typename B::exponent_type eval_ilogb(const B& val)
  1535. {
  1536. BOOST_STATIC_ASSERT_MSG(!std::numeric_limits<number<B> >::is_specialized || (std::numeric_limits<number<B> >::radix == 2), "The default implementation of ilogb requires a base 2 number type");
  1537. typename B::exponent_type e;
  1538. switch(eval_fpclassify(val))
  1539. {
  1540. case FP_NAN:
  1541. #ifdef FP_ILOGBNAN
  1542. return FP_ILOGBNAN > 0 ? (std::numeric_limits<typename B::exponent_type>::max)() : (std::numeric_limits<typename B::exponent_type>::min)();
  1543. #else
  1544. return (std::numeric_limits<typename B::exponent_type>::max)();
  1545. #endif
  1546. case FP_INFINITE:
  1547. return (std::numeric_limits<typename B::exponent_type>::max)();
  1548. case FP_ZERO:
  1549. return (std::numeric_limits<typename B::exponent_type>::min)();
  1550. }
  1551. B result;
  1552. eval_frexp(result, val, &e);
  1553. return e - 1;
  1554. }
  1555. template <class T>
  1556. int eval_signbit(const T& val);
  1557. template <class B>
  1558. inline void eval_logb(B& result, const B& val)
  1559. {
  1560. switch(eval_fpclassify(val))
  1561. {
  1562. case FP_NAN:
  1563. result = val;
  1564. errno = EDOM;
  1565. return;
  1566. case FP_ZERO:
  1567. result = std::numeric_limits<number<B> >::infinity().backend();
  1568. result.negate();
  1569. errno = ERANGE;
  1570. return;
  1571. case FP_INFINITE:
  1572. result = val;
  1573. if(eval_signbit(val))
  1574. result.negate();
  1575. return;
  1576. }
  1577. typedef typename boost::mpl::if_c<boost::is_same<boost::intmax_t, long>::value, boost::long_long_type, boost::intmax_t>::type max_t;
  1578. result = static_cast<max_t>(eval_ilogb(val));
  1579. }
  1580. template <class B, class A>
  1581. inline void eval_scalbn(B& result, const B& val, A e)
  1582. {
  1583. BOOST_STATIC_ASSERT_MSG(!std::numeric_limits<number<B> >::is_specialized || (std::numeric_limits<number<B> >::radix == 2), "The default implementation of scalbn requires a base 2 number type");
  1584. eval_ldexp(result, val, static_cast<typename B::exponent_type>(e));
  1585. }
  1586. template <class B, class A>
  1587. inline void eval_scalbln(B& result, const B& val, A e)
  1588. {
  1589. eval_scalbn(result, val, e);
  1590. }
  1591. template <class T>
  1592. inline bool is_arg_nan(const T& val, mpl::true_ const&, const mpl::false_&)
  1593. {
  1594. return eval_fpclassify(val) == FP_NAN;
  1595. }
  1596. template <class T>
  1597. inline bool is_arg_nan(const T& val, mpl::false_ const&, const mpl::true_&)
  1598. {
  1599. return (boost::math::isnan)(val);
  1600. }
  1601. template <class T>
  1602. inline bool is_arg_nan(const T&, mpl::false_ const&, const mpl::false_&)
  1603. {
  1604. return false;
  1605. }
  1606. template <class T>
  1607. inline bool is_arg_nan(const T& val)
  1608. {
  1609. return is_arg_nan(val, mpl::bool_<boost::multiprecision::detail::is_backend<T>::value>(), is_floating_point<T>());
  1610. }
  1611. template <class T, class U, class V>
  1612. inline void eval_fmax(T& result, const U& a, const V& b)
  1613. {
  1614. if(is_arg_nan(a))
  1615. result = number<T>::canonical_value(b);
  1616. else if(is_arg_nan(b))
  1617. result = number<T>::canonical_value(a);
  1618. else if(eval_lt(number<T>::canonical_value(a), number<T>::canonical_value(b)))
  1619. result = number<T>::canonical_value(b);
  1620. else
  1621. result = number<T>::canonical_value(a);
  1622. }
  1623. template <class T, class U, class V>
  1624. inline void eval_fmin(T& result, const U& a, const V& b)
  1625. {
  1626. if(is_arg_nan(a))
  1627. result = number<T>::canonical_value(b);
  1628. else if(is_arg_nan(b))
  1629. result = number<T>::canonical_value(a);
  1630. else if(eval_lt(number<T>::canonical_value(a), number<T>::canonical_value(b)))
  1631. result = number<T>::canonical_value(a);
  1632. else
  1633. result = number<T>::canonical_value(b);
  1634. }
  1635. template <class R, class T, class U>
  1636. inline void eval_hypot(R& result, const T& a, const U& b)
  1637. {
  1638. //
  1639. // Normalize x and y, so that both are positive and x >= y:
  1640. //
  1641. R x, y;
  1642. x = number<R>::canonical_value(a);
  1643. y = number<R>::canonical_value(b);
  1644. if(eval_get_sign(x) < 0)
  1645. x.negate();
  1646. if(eval_get_sign(y) < 0)
  1647. y.negate();
  1648. // Special case, see C99 Annex F.
  1649. // The order of the if's is important: do not change!
  1650. int c1 = eval_fpclassify(x);
  1651. int c2 = eval_fpclassify(y);
  1652. if(c1 == FP_ZERO)
  1653. {
  1654. result = y;
  1655. return;
  1656. }
  1657. if(c2 == FP_ZERO)
  1658. {
  1659. result = x;
  1660. return;
  1661. }
  1662. if(c1 == FP_INFINITE)
  1663. {
  1664. result = x;
  1665. return;
  1666. }
  1667. if((c2 == FP_INFINITE) || (c2 == FP_NAN))
  1668. {
  1669. result = y;
  1670. return;
  1671. }
  1672. if(c1 == FP_NAN)
  1673. {
  1674. result = x;
  1675. return;
  1676. }
  1677. if(eval_gt(y, x))
  1678. x.swap(y);
  1679. eval_multiply(result, x, std::numeric_limits<number<R> >::epsilon().backend());
  1680. if(eval_gt(result, y))
  1681. {
  1682. result = x;
  1683. return;
  1684. }
  1685. R rat;
  1686. eval_divide(rat, y, x);
  1687. eval_multiply(result, rat, rat);
  1688. eval_increment(result);
  1689. eval_sqrt(rat, result);
  1690. eval_multiply(result, rat, x);
  1691. }
  1692. template <class R, class T>
  1693. inline void eval_nearbyint(R& result, const T& a)
  1694. {
  1695. eval_round(result, a);
  1696. }
  1697. template <class R, class T>
  1698. inline void eval_rint(R& result, const T& a)
  1699. {
  1700. eval_nearbyint(result, a);
  1701. }
  1702. template <class T>
  1703. inline int eval_signbit(const T& val)
  1704. {
  1705. return eval_get_sign(val) < 0 ? 1 : 0;
  1706. }
  1707. //
  1708. // Real and imaginary parts:
  1709. //
  1710. template <class To, class From>
  1711. inline void eval_real(To& to, const From& from)
  1712. {
  1713. to = from;
  1714. }
  1715. template <class To, class From>
  1716. inline void eval_imag(To& to, const From& )
  1717. {
  1718. typedef typename mpl::front<typename To::unsigned_types>::type ui_type;
  1719. to = ui_type(0);
  1720. }
  1721. } namespace default_ops_adl {
  1722. template <class To, class From>
  1723. inline void eval_set_real_imp(To& to, const From& from)
  1724. {
  1725. typedef typename component_type<number<To> >::type to_component_type;
  1726. typename to_component_type::backend_type to_component;
  1727. to_component = from;
  1728. eval_set_real(to, to_component);
  1729. }
  1730. template <class To, class From>
  1731. inline void eval_set_imag_imp(To& to, const From& from)
  1732. {
  1733. typedef typename component_type<number<To> >::type to_component_type;
  1734. typename to_component_type::backend_type to_component;
  1735. to_component = from;
  1736. eval_set_imag(to, to_component);
  1737. }
  1738. } namespace default_ops{
  1739. template <class To, class From>
  1740. inline typename enable_if_c<number_category<To>::value == number_kind_complex>::type eval_set_real(To& to, const From& from)
  1741. {
  1742. default_ops_adl::eval_set_real_imp(to, from);
  1743. }
  1744. template <class To, class From>
  1745. inline typename disable_if_c<number_category<To>::value == number_kind_complex>::type eval_set_real(To& to, const From& from)
  1746. {
  1747. to = from;
  1748. }
  1749. template <class To, class From>
  1750. inline void eval_set_imag(To& to, const From& from)
  1751. {
  1752. default_ops_adl::eval_set_imag_imp(to, from);
  1753. }
  1754. template <class T>
  1755. inline void eval_set_real(T& to, const T& from)
  1756. {
  1757. to = from;
  1758. }
  1759. template <class T>
  1760. void eval_set_imag(T&, const T&)
  1761. {
  1762. BOOST_STATIC_ASSERT_MSG(sizeof(T) == INT_MAX, "eval_set_imag needs to be specialised for each specific backend");
  1763. }
  1764. //
  1765. // These functions are implemented in separate files, but expanded inline here,
  1766. // DO NOT CHANGE THE ORDER OF THESE INCLUDES:
  1767. //
  1768. #include <boost/multiprecision/detail/functions/constants.hpp>
  1769. #include <boost/multiprecision/detail/functions/pow.hpp>
  1770. #include <boost/multiprecision/detail/functions/trig.hpp>
  1771. }
  1772. //
  1773. // Default versions of floating point classification routines:
  1774. //
  1775. template <class Backend, multiprecision::expression_template_option ExpressionTemplates>
  1776. inline int fpclassify BOOST_PREVENT_MACRO_SUBSTITUTION(const multiprecision::number<Backend, ExpressionTemplates>& arg)
  1777. {
  1778. using multiprecision::default_ops::eval_fpclassify;
  1779. return eval_fpclassify(arg.backend());
  1780. }
  1781. template <class tag, class A1, class A2, class A3, class A4>
  1782. inline int fpclassify BOOST_PREVENT_MACRO_SUBSTITUTION(const multiprecision::detail::expression<tag, A1, A2, A3, A4>& arg)
  1783. {
  1784. typedef typename multiprecision::detail::expression<tag, A1, A2, A3, A4>::result_type value_type;
  1785. return fpclassify BOOST_PREVENT_MACRO_SUBSTITUTION(value_type(arg));
  1786. }
  1787. template <class Backend, multiprecision::expression_template_option ExpressionTemplates>
  1788. inline bool isfinite BOOST_PREVENT_MACRO_SUBSTITUTION(const multiprecision::number<Backend, ExpressionTemplates>& arg)
  1789. {
  1790. int v = fpclassify BOOST_PREVENT_MACRO_SUBSTITUTION(arg);
  1791. return (v != (int)FP_INFINITE) && (v != (int)FP_NAN);
  1792. }
  1793. template <class tag, class A1, class A2, class A3, class A4>
  1794. inline bool isfinite BOOST_PREVENT_MACRO_SUBSTITUTION(const multiprecision::detail::expression<tag, A1, A2, A3, A4>& arg)
  1795. {
  1796. typedef typename multiprecision::detail::expression<tag, A1, A2, A3, A4>::result_type value_type;
  1797. return isfinite BOOST_PREVENT_MACRO_SUBSTITUTION(value_type(arg));
  1798. }
  1799. template <class Backend, multiprecision::expression_template_option ExpressionTemplates>
  1800. inline bool isnan BOOST_PREVENT_MACRO_SUBSTITUTION(const multiprecision::number<Backend, ExpressionTemplates>& arg)
  1801. {
  1802. return fpclassify BOOST_PREVENT_MACRO_SUBSTITUTION(arg) == (int)FP_NAN;
  1803. }
  1804. template <class tag, class A1, class A2, class A3, class A4>
  1805. inline bool isnan BOOST_PREVENT_MACRO_SUBSTITUTION(const multiprecision::detail::expression<tag, A1, A2, A3, A4>& arg)
  1806. {
  1807. typedef typename multiprecision::detail::expression<tag, A1, A2, A3, A4>::result_type value_type;
  1808. return isnan BOOST_PREVENT_MACRO_SUBSTITUTION(value_type(arg));
  1809. }
  1810. template <class Backend, multiprecision::expression_template_option ExpressionTemplates>
  1811. inline bool isinf BOOST_PREVENT_MACRO_SUBSTITUTION(const multiprecision::number<Backend, ExpressionTemplates>& arg)
  1812. {
  1813. return fpclassify BOOST_PREVENT_MACRO_SUBSTITUTION(arg) == (int)FP_INFINITE;
  1814. }
  1815. template <class tag, class A1, class A2, class A3, class A4>
  1816. inline bool isinf BOOST_PREVENT_MACRO_SUBSTITUTION(const multiprecision::detail::expression<tag, A1, A2, A3, A4>& arg)
  1817. {
  1818. typedef typename multiprecision::detail::expression<tag, A1, A2, A3, A4>::result_type value_type;
  1819. return isinf BOOST_PREVENT_MACRO_SUBSTITUTION(value_type(arg));
  1820. }
  1821. template <class Backend, multiprecision::expression_template_option ExpressionTemplates>
  1822. inline bool isnormal BOOST_PREVENT_MACRO_SUBSTITUTION(const multiprecision::number<Backend, ExpressionTemplates>& arg)
  1823. {
  1824. return fpclassify BOOST_PREVENT_MACRO_SUBSTITUTION(arg) == (int)FP_NORMAL;
  1825. }
  1826. template <class tag, class A1, class A2, class A3, class A4>
  1827. inline bool isnormal BOOST_PREVENT_MACRO_SUBSTITUTION(const multiprecision::detail::expression<tag, A1, A2, A3, A4>& arg)
  1828. {
  1829. typedef typename multiprecision::detail::expression<tag, A1, A2, A3, A4>::result_type value_type;
  1830. return isnormal BOOST_PREVENT_MACRO_SUBSTITUTION(value_type(arg));
  1831. }
  1832. // Default versions of sign manipulation functions, if individual backends can do better than this
  1833. // (for example with signed zero), then they should overload these functions further:
  1834. template <class Backend, multiprecision::expression_template_option ExpressionTemplates>
  1835. inline int sign BOOST_PREVENT_MACRO_SUBSTITUTION(const multiprecision::number<Backend, ExpressionTemplates>& arg)
  1836. {
  1837. return arg.sign();
  1838. }
  1839. template <class tag, class A1, class A2, class A3, class A4>
  1840. inline int sign BOOST_PREVENT_MACRO_SUBSTITUTION(const multiprecision::detail::expression<tag, A1, A2, A3, A4>& arg)
  1841. {
  1842. typedef typename multiprecision::detail::expression<tag, A1, A2, A3, A4>::result_type value_type;
  1843. return sign BOOST_PREVENT_MACRO_SUBSTITUTION(value_type(arg));
  1844. }
  1845. template <class Backend, multiprecision::expression_template_option ExpressionTemplates>
  1846. inline int signbit BOOST_PREVENT_MACRO_SUBSTITUTION(const multiprecision::number<Backend, ExpressionTemplates>& arg)
  1847. {
  1848. using default_ops::eval_signbit;
  1849. return eval_signbit(arg.backend());
  1850. }
  1851. template <class tag, class A1, class A2, class A3, class A4>
  1852. inline int signbit BOOST_PREVENT_MACRO_SUBSTITUTION(const multiprecision::detail::expression<tag, A1, A2, A3, A4>& arg)
  1853. {
  1854. typedef typename multiprecision::detail::expression<tag, A1, A2, A3, A4>::result_type value_type;
  1855. return signbit BOOST_PREVENT_MACRO_SUBSTITUTION(value_type(arg));
  1856. }
  1857. template <class Backend, multiprecision::expression_template_option ExpressionTemplates>
  1858. inline multiprecision::number<Backend, ExpressionTemplates> changesign BOOST_PREVENT_MACRO_SUBSTITUTION(const multiprecision::number<Backend, ExpressionTemplates>& arg)
  1859. {
  1860. return -arg;
  1861. }
  1862. template <class tag, class A1, class A2, class A3, class A4>
  1863. inline typename multiprecision::detail::expression<tag, A1, A2, A3, A4>::result_type changesign BOOST_PREVENT_MACRO_SUBSTITUTION(const multiprecision::detail::expression<tag, A1, A2, A3, A4>& arg)
  1864. {
  1865. typedef typename multiprecision::detail::expression<tag, A1, A2, A3, A4>::result_type value_type;
  1866. return changesign BOOST_PREVENT_MACRO_SUBSTITUTION(value_type(arg));
  1867. }
  1868. template <class Backend, multiprecision::expression_template_option ExpressionTemplates>
  1869. inline multiprecision::number<Backend, ExpressionTemplates> copysign BOOST_PREVENT_MACRO_SUBSTITUTION(const multiprecision::number<Backend, ExpressionTemplates>& a, const multiprecision::number<Backend, ExpressionTemplates>& b)
  1870. {
  1871. return (boost::multiprecision::signbit)(a) != (boost::multiprecision::signbit)(b) ? (boost::multiprecision::changesign)(a) : a;
  1872. }
  1873. template <class Backend, multiprecision::expression_template_option ExpressionTemplates, class tag, class A1, class A2, class A3, class A4>
  1874. inline multiprecision::number<Backend, ExpressionTemplates> copysign BOOST_PREVENT_MACRO_SUBSTITUTION(const multiprecision::number<Backend, ExpressionTemplates>& a, const multiprecision::detail::expression<tag, A1, A2, A3, A4>& b)
  1875. {
  1876. return copysign BOOST_PREVENT_MACRO_SUBSTITUTION(a, multiprecision::number<Backend, ExpressionTemplates>(b));
  1877. }
  1878. template <class tag, class A1, class A2, class A3, class A4, class Backend, multiprecision::expression_template_option ExpressionTemplates>
  1879. inline multiprecision::number<Backend, ExpressionTemplates> copysign BOOST_PREVENT_MACRO_SUBSTITUTION(const multiprecision::detail::expression<tag, A1, A2, A3, A4>& a, const multiprecision::number<Backend, ExpressionTemplates>& b)
  1880. {
  1881. return copysign BOOST_PREVENT_MACRO_SUBSTITUTION(multiprecision::number<Backend, ExpressionTemplates>(a), b);
  1882. }
  1883. template <class tag, class A1, class A2, class A3, class A4, class tagb, class A1b, class A2b, class A3b, class A4b>
  1884. inline typename multiprecision::detail::expression<tag, A1, A2, A3, A4>::result_type copysign BOOST_PREVENT_MACRO_SUBSTITUTION(const multiprecision::detail::expression<tag, A1, A2, A3, A4>& a, const multiprecision::detail::expression<tagb, A1b, A2b, A3b, A4b>& b)
  1885. {
  1886. typedef typename multiprecision::detail::expression<tag, A1, A2, A3, A4>::result_type value_type;
  1887. return copysign BOOST_PREVENT_MACRO_SUBSTITUTION(value_type(a), value_type(b));
  1888. }
  1889. //
  1890. // real and imag:
  1891. //
  1892. template <class Backend, multiprecision::expression_template_option ExpressionTemplates>
  1893. inline typename scalar_result_from_possible_complex<multiprecision::number<Backend, ExpressionTemplates> >::type
  1894. real(const multiprecision::number<Backend, ExpressionTemplates>& a)
  1895. {
  1896. using default_ops::eval_real;
  1897. typedef typename scalar_result_from_possible_complex<multiprecision::number<Backend, ExpressionTemplates> >::type result_type;
  1898. boost::multiprecision::detail::scoped_default_precision<result_type> precision_guard(a);
  1899. result_type result;
  1900. eval_real(result.backend(), a.backend());
  1901. return result;
  1902. }
  1903. template <class Backend, multiprecision::expression_template_option ExpressionTemplates>
  1904. inline typename scalar_result_from_possible_complex<multiprecision::number<Backend, ExpressionTemplates> >::type
  1905. imag(const multiprecision::number<Backend, ExpressionTemplates>& a)
  1906. {
  1907. using default_ops::eval_imag;
  1908. typedef typename scalar_result_from_possible_complex<multiprecision::number<Backend, ExpressionTemplates> >::type result_type;
  1909. boost::multiprecision::detail::scoped_default_precision<result_type> precision_guard(a);
  1910. result_type result;
  1911. eval_imag(result.backend(), a.backend());
  1912. return result;
  1913. }
  1914. template <class tag, class A1, class A2, class A3, class A4>
  1915. inline typename scalar_result_from_possible_complex<typename multiprecision::detail::expression<tag, A1, A2, A3, A4>::result_type>::type
  1916. real(const multiprecision::detail::expression<tag, A1, A2, A3, A4>& arg)
  1917. {
  1918. typedef typename multiprecision::detail::expression<tag, A1, A2, A3, A4>::result_type value_type;
  1919. detail::scoped_default_precision<value_type> precision_guard(arg);
  1920. return real(value_type(arg));
  1921. }
  1922. template <class tag, class A1, class A2, class A3, class A4>
  1923. inline typename scalar_result_from_possible_complex<typename multiprecision::detail::expression<tag, A1, A2, A3, A4>::result_type>::type
  1924. imag(const multiprecision::detail::expression<tag, A1, A2, A3, A4>& arg)
  1925. {
  1926. typedef typename multiprecision::detail::expression<tag, A1, A2, A3, A4>::result_type value_type;
  1927. detail::scoped_default_precision<value_type> precision_guard(arg);
  1928. return imag(value_type(arg));
  1929. }
  1930. //
  1931. // Complex number functions, these are overloaded at the Backend level, we just provide the
  1932. // expression template versions here, plus overloads for non-complex types:
  1933. //
  1934. template <class T, expression_template_option ExpressionTemplates>
  1935. inline typename boost::lazy_enable_if_c<number_category<T>::value == number_kind_complex, component_type<number<T, ExpressionTemplates> > >::type
  1936. abs(const number<T, ExpressionTemplates>& v)
  1937. {
  1938. return BOOST_MP_MOVE(boost::math::hypot(real(v), imag(v)));
  1939. }
  1940. template <class tag, class A1, class A2, class A3, class A4>
  1941. inline typename boost::lazy_enable_if_c<number_category<typename detail::expression<tag, A1, A2, A3, A4>::result_type>::value == number_kind_complex, component_type<typename detail::expression<tag, A1, A2, A3, A4>::result_type> >::type
  1942. abs(const detail::expression<tag, A1, A2, A3, A4>& v)
  1943. {
  1944. typedef typename detail::expression<tag, A1, A2, A3, A4>::result_type number_type;
  1945. return BOOST_MP_MOVE(abs(static_cast<number_type>(v)));
  1946. }
  1947. template <class T, expression_template_option ExpressionTemplates>
  1948. inline typename enable_if_c<number_category<T>::value == number_kind_complex, typename scalar_result_from_possible_complex<number<T, ExpressionTemplates> >::type>::type
  1949. arg(const number<T, ExpressionTemplates>& v)
  1950. {
  1951. return BOOST_MP_MOVE(atan2(imag(v), real(v)));
  1952. }
  1953. template <class T, expression_template_option ExpressionTemplates>
  1954. inline typename enable_if_c<number_category<T>::value == number_kind_floating_point, typename scalar_result_from_possible_complex<number<T, ExpressionTemplates> >::type>::type
  1955. arg(const number<T, ExpressionTemplates>&)
  1956. {
  1957. return 0;
  1958. }
  1959. template <class tag, class A1, class A2, class A3, class A4>
  1960. inline typename enable_if_c<number_category<typename detail::expression<tag, A1, A2, A3, A4>::result_type>::value == number_kind_complex || number_category<typename detail::expression<tag, A1, A2, A3, A4>::result_type>::value == number_kind_floating_point, typename scalar_result_from_possible_complex<typename detail::expression<tag, A1, A2, A3, A4>::result_type>::type>::type
  1961. arg(const detail::expression<tag, A1, A2, A3, A4>& v)
  1962. {
  1963. typedef typename detail::expression<tag, A1, A2, A3, A4>::result_type number_type;
  1964. return BOOST_MP_MOVE(arg(static_cast<number_type>(v)));
  1965. }
  1966. template <class T, expression_template_option ExpressionTemplates>
  1967. inline typename boost::lazy_enable_if_c<number_category<T>::value == number_kind_complex, component_type<number<T, ExpressionTemplates> > >::type
  1968. norm(const number<T, ExpressionTemplates>& v)
  1969. {
  1970. typename component_type<number<T, ExpressionTemplates> >::type a(real(v)), b(imag(v));
  1971. return BOOST_MP_MOVE(a * a + b * b);
  1972. }
  1973. template <class T, expression_template_option ExpressionTemplates>
  1974. inline typename boost::enable_if_c<number_category<T>::value != number_kind_complex, typename scalar_result_from_possible_complex<number<T, ExpressionTemplates> >::type >::type
  1975. norm(const number<T, ExpressionTemplates>& v)
  1976. {
  1977. return v * v;
  1978. }
  1979. template <class tag, class A1, class A2, class A3, class A4>
  1980. inline typename scalar_result_from_possible_complex<typename detail::expression<tag, A1, A2, A3, A4>::result_type>::type
  1981. norm(const detail::expression<tag, A1, A2, A3, A4>& v)
  1982. {
  1983. typedef typename detail::expression<tag, A1, A2, A3, A4>::result_type number_type;
  1984. return BOOST_MP_MOVE(norm(static_cast<number_type>(v)));
  1985. }
  1986. template <class Backend, expression_template_option ExpressionTemplates>
  1987. typename complex_result_from_scalar<number<Backend, ExpressionTemplates> >::type polar(number<Backend, ExpressionTemplates> const& r, number<Backend, ExpressionTemplates> const& theta)
  1988. {
  1989. return typename complex_result_from_scalar<number<Backend, ExpressionTemplates> >::type(number<Backend, ExpressionTemplates>(r * cos(theta)), number<Backend, ExpressionTemplates>(r * sin(theta)));
  1990. }
  1991. template <class tag, class A1, class A2, class A3, class A4, class Backend, expression_template_option ExpressionTemplates>
  1992. typename enable_if_c<boost::is_same<typename detail::expression<tag, A1, A2, A3, A4>::result_type, number<Backend, ExpressionTemplates> >::value,
  1993. typename complex_result_from_scalar<number<Backend, ExpressionTemplates> >::type>::type
  1994. polar(detail::expression<tag, A1, A2, A3, A4> const& r, number<Backend, ExpressionTemplates> const& theta)
  1995. {
  1996. return typename complex_result_from_scalar<number<Backend, ExpressionTemplates> >::type(number<Backend, ExpressionTemplates>(r * cos(theta)), number<Backend, ExpressionTemplates>(r * sin(theta)));
  1997. }
  1998. template <class Backend, expression_template_option ExpressionTemplates, class tag, class A1, class A2, class A3, class A4>
  1999. typename enable_if_c<boost::is_same<typename detail::expression<tag, A1, A2, A3, A4>::result_type, number<Backend, ExpressionTemplates> >::value,
  2000. typename complex_result_from_scalar<number<Backend, ExpressionTemplates> >::type>::type
  2001. polar(number<Backend, ExpressionTemplates> const& r, detail::expression<tag, A1, A2, A3, A4> const& theta)
  2002. {
  2003. return typename complex_result_from_scalar<number<Backend, ExpressionTemplates> >::type(number<Backend, ExpressionTemplates>(r * cos(theta)), number<Backend, ExpressionTemplates>(r * sin(theta)));
  2004. }
  2005. template <class tag, class A1, class A2, class A3, class A4, class tagb, class A1b, class A2b, class A3b, class A4b>
  2006. typename enable_if_c<boost::is_same<typename detail::expression<tag, A1, A2, A3, A4>::result_type, typename detail::expression<tagb, A1b, A2b, A3b, A4b>::result_type >::value,
  2007. typename complex_result_from_scalar<typename detail::expression<tag, A1, A2, A3, A4>::result_type >::type>::type
  2008. polar(detail::expression<tag, A1, A2, A3, A4> const& r, detail::expression<tagb, A1b, A2b, A3b, A4b> const& theta)
  2009. {
  2010. typedef typename detail::expression<tag, A1, A2, A3, A4>::result_type scalar_type;
  2011. return typename complex_result_from_scalar<scalar_type>::type(scalar_type(r * cos(theta)), scalar_type(r * sin(theta)));
  2012. }
  2013. //
  2014. // We also allow the first argument to polar to be an arithmetic type (probably a literal):
  2015. //
  2016. template <class Scalar, class Backend, expression_template_option ExpressionTemplates>
  2017. typename boost::enable_if_c<boost::is_arithmetic<Scalar>::value, typename complex_result_from_scalar<number<Backend, ExpressionTemplates> >::type>::type
  2018. polar(Scalar const& r, number<Backend, ExpressionTemplates> const& theta)
  2019. {
  2020. return typename complex_result_from_scalar<number<Backend, ExpressionTemplates> >::type(number<Backend, ExpressionTemplates>(r * cos(theta)), number<Backend, ExpressionTemplates>(r * sin(theta)));
  2021. }
  2022. template <class tag, class A1, class A2, class A3, class A4, class Scalar>
  2023. typename enable_if_c<boost::is_arithmetic<Scalar>::value,
  2024. typename complex_result_from_scalar<typename detail::expression<tag, A1, A2, A3, A4>::result_type>::type>::type
  2025. polar(Scalar const& r, detail::expression<tag, A1, A2, A3, A4> const& theta)
  2026. {
  2027. typedef typename detail::expression<tag, A1, A2, A3, A4>::result_type scalar_type;
  2028. return typename complex_result_from_scalar<scalar_type>::type(scalar_type(r * cos(theta)), scalar_type(r * sin(theta)));
  2029. }
  2030. //
  2031. // Single argument overloads:
  2032. //
  2033. template <class Backend, expression_template_option ExpressionTemplates>
  2034. typename complex_result_from_scalar<number<Backend, ExpressionTemplates> >::type polar(number<Backend, ExpressionTemplates> const& r)
  2035. {
  2036. return typename complex_result_from_scalar<number<Backend, ExpressionTemplates> >::type(r);
  2037. }
  2038. template <class tag, class A1, class A2, class A3, class A4>
  2039. typename complex_result_from_scalar<typename detail::expression<tag, A1, A2, A3, A4>::result_type>::type
  2040. polar(detail::expression<tag, A1, A2, A3, A4> const& r)
  2041. {
  2042. return typename complex_result_from_scalar<typename detail::expression<tag, A1, A2, A3, A4>::result_type>::type(r);
  2043. }
  2044. } // namespace multiprecision
  2045. namespace math {
  2046. //
  2047. // Import Math functions here, so they can be found by Boost.Math:
  2048. //
  2049. using boost::multiprecision::signbit;
  2050. using boost::multiprecision::sign;
  2051. using boost::multiprecision::copysign;
  2052. using boost::multiprecision::changesign;
  2053. using boost::multiprecision::fpclassify;
  2054. using boost::multiprecision::isinf;
  2055. using boost::multiprecision::isnan;
  2056. using boost::multiprecision::isnormal;
  2057. using boost::multiprecision::isfinite;
  2058. }
  2059. namespace multiprecision{
  2060. typedef ::boost::math::policies::policy<
  2061. ::boost::math::policies::domain_error< ::boost::math::policies::errno_on_error>,
  2062. ::boost::math::policies::pole_error< ::boost::math::policies::errno_on_error>,
  2063. ::boost::math::policies::overflow_error< ::boost::math::policies::errno_on_error>,
  2064. ::boost::math::policies::evaluation_error< ::boost::math::policies::errno_on_error>,
  2065. ::boost::math::policies::rounding_error< ::boost::math::policies::errno_on_error>
  2066. > c99_error_policy;
  2067. template <class Backend, multiprecision::expression_template_option ExpressionTemplates>
  2068. inline typename boost::enable_if_c<number_category<Backend>::value != number_kind_complex, multiprecision::number<Backend, ExpressionTemplates> >::type
  2069. asinh BOOST_PREVENT_MACRO_SUBSTITUTION(const multiprecision::number<Backend, ExpressionTemplates>& arg)
  2070. {
  2071. detail::scoped_default_precision<multiprecision::number<Backend, ExpressionTemplates> > precision_guard(arg);
  2072. return boost::math::asinh(arg, c99_error_policy());
  2073. }
  2074. template <class tag, class A1, class A2, class A3, class A4>
  2075. inline typename boost::enable_if_c<number_category<typename multiprecision::detail::expression<tag, A1, A2, A3, A4>::result_type>::value != number_kind_complex, typename multiprecision::detail::expression<tag, A1, A2, A3, A4>::result_type>::type
  2076. asinh BOOST_PREVENT_MACRO_SUBSTITUTION(const multiprecision::detail::expression<tag, A1, A2, A3, A4>& arg)
  2077. {
  2078. typedef typename multiprecision::detail::expression<tag, A1, A2, A3, A4>::result_type value_type;
  2079. detail::scoped_default_precision<value_type > precision_guard(arg);
  2080. return asinh(value_type(arg));
  2081. }
  2082. template <class Backend, multiprecision::expression_template_option ExpressionTemplates>
  2083. inline typename boost::enable_if_c<number_category<Backend>::value != number_kind_complex, multiprecision::number<Backend, ExpressionTemplates> >::type
  2084. acosh BOOST_PREVENT_MACRO_SUBSTITUTION(const multiprecision::number<Backend, ExpressionTemplates>& arg)
  2085. {
  2086. detail::scoped_default_precision<multiprecision::number<Backend, ExpressionTemplates> > precision_guard(arg);
  2087. return boost::math::acosh(arg, c99_error_policy());
  2088. }
  2089. template <class tag, class A1, class A2, class A3, class A4>
  2090. inline typename boost::enable_if_c<number_category<typename multiprecision::detail::expression<tag, A1, A2, A3, A4>::result_type>::value != number_kind_complex, typename multiprecision::detail::expression<tag, A1, A2, A3, A4>::result_type>::type
  2091. acosh BOOST_PREVENT_MACRO_SUBSTITUTION(const multiprecision::detail::expression<tag, A1, A2, A3, A4>& arg)
  2092. {
  2093. typedef typename multiprecision::detail::expression<tag, A1, A2, A3, A4>::result_type value_type;
  2094. detail::scoped_default_precision<value_type > precision_guard(arg);
  2095. return acosh(value_type(arg));
  2096. }
  2097. template <class Backend, multiprecision::expression_template_option ExpressionTemplates>
  2098. inline typename boost::enable_if_c<number_category<Backend>::value != number_kind_complex, multiprecision::number<Backend, ExpressionTemplates> >::type
  2099. atanh BOOST_PREVENT_MACRO_SUBSTITUTION(const multiprecision::number<Backend, ExpressionTemplates>& arg)
  2100. {
  2101. detail::scoped_default_precision<multiprecision::number<Backend, ExpressionTemplates> > precision_guard(arg);
  2102. return boost::math::atanh(arg, c99_error_policy());
  2103. }
  2104. template <class tag, class A1, class A2, class A3, class A4>
  2105. inline typename boost::enable_if_c<number_category<typename multiprecision::detail::expression<tag, A1, A2, A3, A4>::result_type>::value != number_kind_complex, typename multiprecision::detail::expression<tag, A1, A2, A3, A4>::result_type>::type
  2106. atanh BOOST_PREVENT_MACRO_SUBSTITUTION(const multiprecision::detail::expression<tag, A1, A2, A3, A4>& arg)
  2107. {
  2108. typedef typename multiprecision::detail::expression<tag, A1, A2, A3, A4>::result_type value_type;
  2109. detail::scoped_default_precision<value_type > precision_guard(arg);
  2110. return atanh(value_type(arg));
  2111. }
  2112. template <class Backend, multiprecision::expression_template_option ExpressionTemplates>
  2113. inline multiprecision::number<Backend, ExpressionTemplates> cbrt BOOST_PREVENT_MACRO_SUBSTITUTION(const multiprecision::number<Backend, ExpressionTemplates>& arg)
  2114. {
  2115. detail::scoped_default_precision<multiprecision::number<Backend, ExpressionTemplates> > precision_guard(arg);
  2116. return boost::math::cbrt(arg, c99_error_policy());
  2117. }
  2118. template <class tag, class A1, class A2, class A3, class A4>
  2119. inline typename multiprecision::detail::expression<tag, A1, A2, A3, A4>::result_type cbrt BOOST_PREVENT_MACRO_SUBSTITUTION(const multiprecision::detail::expression<tag, A1, A2, A3, A4>& arg)
  2120. {
  2121. typedef typename multiprecision::detail::expression<tag, A1, A2, A3, A4>::result_type value_type;
  2122. detail::scoped_default_precision<value_type> precision_guard(arg);
  2123. return cbrt(value_type(arg));
  2124. }
  2125. template <class Backend, multiprecision::expression_template_option ExpressionTemplates>
  2126. inline multiprecision::number<Backend, ExpressionTemplates> erf BOOST_PREVENT_MACRO_SUBSTITUTION(const multiprecision::number<Backend, ExpressionTemplates>& arg)
  2127. {
  2128. detail::scoped_default_precision<multiprecision::number<Backend, ExpressionTemplates> > precision_guard(arg);
  2129. return boost::math::erf(arg, c99_error_policy());
  2130. }
  2131. template <class tag, class A1, class A2, class A3, class A4>
  2132. inline typename multiprecision::detail::expression<tag, A1, A2, A3, A4>::result_type erf BOOST_PREVENT_MACRO_SUBSTITUTION(const multiprecision::detail::expression<tag, A1, A2, A3, A4>& arg)
  2133. {
  2134. typedef typename multiprecision::detail::expression<tag, A1, A2, A3, A4>::result_type value_type;
  2135. detail::scoped_default_precision<value_type> precision_guard(arg);
  2136. return erf(value_type(arg));
  2137. }
  2138. template <class Backend, multiprecision::expression_template_option ExpressionTemplates>
  2139. inline multiprecision::number<Backend, ExpressionTemplates> erfc BOOST_PREVENT_MACRO_SUBSTITUTION(const multiprecision::number<Backend, ExpressionTemplates>& arg)
  2140. {
  2141. detail::scoped_default_precision<multiprecision::number<Backend, ExpressionTemplates> > precision_guard(arg);
  2142. return boost::math::erfc(arg, c99_error_policy());
  2143. }
  2144. template <class tag, class A1, class A2, class A3, class A4>
  2145. inline typename multiprecision::detail::expression<tag, A1, A2, A3, A4>::result_type erfc BOOST_PREVENT_MACRO_SUBSTITUTION(const multiprecision::detail::expression<tag, A1, A2, A3, A4>& arg)
  2146. {
  2147. typedef typename multiprecision::detail::expression<tag, A1, A2, A3, A4>::result_type value_type;
  2148. detail::scoped_default_precision<value_type> precision_guard(arg);
  2149. return erfc(value_type(arg));
  2150. }
  2151. template <class Backend, multiprecision::expression_template_option ExpressionTemplates>
  2152. inline multiprecision::number<Backend, ExpressionTemplates> expm1 BOOST_PREVENT_MACRO_SUBSTITUTION(const multiprecision::number<Backend, ExpressionTemplates>& arg)
  2153. {
  2154. detail::scoped_default_precision<multiprecision::number<Backend, ExpressionTemplates> > precision_guard(arg);
  2155. return boost::math::expm1(arg, c99_error_policy());
  2156. }
  2157. template <class tag, class A1, class A2, class A3, class A4>
  2158. inline typename multiprecision::detail::expression<tag, A1, A2, A3, A4>::result_type expm1 BOOST_PREVENT_MACRO_SUBSTITUTION(const multiprecision::detail::expression<tag, A1, A2, A3, A4>& arg)
  2159. {
  2160. typedef typename multiprecision::detail::expression<tag, A1, A2, A3, A4>::result_type value_type;
  2161. detail::scoped_default_precision<value_type> precision_guard(arg);
  2162. return expm1(value_type(arg));
  2163. }
  2164. template <class Backend, multiprecision::expression_template_option ExpressionTemplates>
  2165. inline multiprecision::number<Backend, ExpressionTemplates> lgamma BOOST_PREVENT_MACRO_SUBSTITUTION(const multiprecision::number<Backend, ExpressionTemplates>& arg)
  2166. {
  2167. detail::scoped_default_precision<multiprecision::number<Backend, ExpressionTemplates> > precision_guard(arg);
  2168. multiprecision::number<Backend, ExpressionTemplates> result;
  2169. result = boost::math::lgamma(arg, c99_error_policy());
  2170. if((boost::multiprecision::isnan)(result) && !(boost::multiprecision::isnan)(arg))
  2171. {
  2172. result = std::numeric_limits<multiprecision::number<Backend, ExpressionTemplates> >::infinity();
  2173. errno = ERANGE;
  2174. }
  2175. return result;
  2176. }
  2177. template <class tag, class A1, class A2, class A3, class A4>
  2178. inline typename multiprecision::detail::expression<tag, A1, A2, A3, A4>::result_type lgamma BOOST_PREVENT_MACRO_SUBSTITUTION(const multiprecision::detail::expression<tag, A1, A2, A3, A4>& arg)
  2179. {
  2180. typedef typename multiprecision::detail::expression<tag, A1, A2, A3, A4>::result_type value_type;
  2181. detail::scoped_default_precision<value_type> precision_guard(arg);
  2182. return lgamma(value_type(arg));
  2183. }
  2184. template <class Backend, multiprecision::expression_template_option ExpressionTemplates>
  2185. inline multiprecision::number<Backend, ExpressionTemplates> tgamma BOOST_PREVENT_MACRO_SUBSTITUTION(const multiprecision::number<Backend, ExpressionTemplates>& arg)
  2186. {
  2187. detail::scoped_default_precision<multiprecision::number<Backend, ExpressionTemplates> > precision_guard(arg);
  2188. if((arg == 0) && std::numeric_limits<multiprecision::number<Backend, ExpressionTemplates> >::has_infinity)
  2189. {
  2190. errno = ERANGE;
  2191. return 1 / arg;
  2192. }
  2193. return boost::math::tgamma(arg, c99_error_policy());
  2194. }
  2195. template <class tag, class A1, class A2, class A3, class A4>
  2196. inline typename multiprecision::detail::expression<tag, A1, A2, A3, A4>::result_type tgamma BOOST_PREVENT_MACRO_SUBSTITUTION(const multiprecision::detail::expression<tag, A1, A2, A3, A4>& arg)
  2197. {
  2198. typedef typename multiprecision::detail::expression<tag, A1, A2, A3, A4>::result_type value_type;
  2199. detail::scoped_default_precision<value_type> precision_guard(arg);
  2200. return tgamma(value_type(arg));
  2201. }
  2202. template <class Backend, multiprecision::expression_template_option ExpressionTemplates>
  2203. inline long lrint BOOST_PREVENT_MACRO_SUBSTITUTION(const multiprecision::number<Backend, ExpressionTemplates>& arg)
  2204. {
  2205. return lround(arg);
  2206. }
  2207. template <class tag, class A1, class A2, class A3, class A4>
  2208. inline long lrint BOOST_PREVENT_MACRO_SUBSTITUTION(const multiprecision::detail::expression<tag, A1, A2, A3, A4>& arg)
  2209. {
  2210. return lround(arg);
  2211. }
  2212. #ifndef BOOST_NO_LONG_LONG
  2213. template <class Backend, multiprecision::expression_template_option ExpressionTemplates>
  2214. inline boost::long_long_type llrint BOOST_PREVENT_MACRO_SUBSTITUTION(const multiprecision::number<Backend, ExpressionTemplates>& arg)
  2215. {
  2216. return llround(arg);
  2217. }
  2218. template <class tag, class A1, class A2, class A3, class A4>
  2219. inline boost::long_long_type llrint BOOST_PREVENT_MACRO_SUBSTITUTION(const multiprecision::detail::expression<tag, A1, A2, A3, A4>& arg)
  2220. {
  2221. return llround(arg);
  2222. }
  2223. #endif
  2224. template <class Backend, multiprecision::expression_template_option ExpressionTemplates>
  2225. inline multiprecision::number<Backend, ExpressionTemplates> log1p BOOST_PREVENT_MACRO_SUBSTITUTION(const multiprecision::number<Backend, ExpressionTemplates>& arg)
  2226. {
  2227. detail::scoped_default_precision<multiprecision::number<Backend, ExpressionTemplates> > precision_guard(arg);
  2228. return boost::math::log1p(arg, c99_error_policy());
  2229. }
  2230. template <class tag, class A1, class A2, class A3, class A4>
  2231. inline typename multiprecision::detail::expression<tag, A1, A2, A3, A4>::result_type log1p BOOST_PREVENT_MACRO_SUBSTITUTION(const multiprecision::detail::expression<tag, A1, A2, A3, A4>& arg)
  2232. {
  2233. typedef typename multiprecision::detail::expression<tag, A1, A2, A3, A4>::result_type value_type;
  2234. detail::scoped_default_precision<value_type> precision_guard(arg);
  2235. return log1p(value_type(arg));
  2236. }
  2237. template <class Backend, multiprecision::expression_template_option ExpressionTemplates>
  2238. inline multiprecision::number<Backend, ExpressionTemplates> nextafter BOOST_PREVENT_MACRO_SUBSTITUTION(const multiprecision::number<Backend, ExpressionTemplates>& a, const multiprecision::number<Backend, ExpressionTemplates>& b)
  2239. {
  2240. detail::scoped_default_precision<multiprecision::number<Backend, ExpressionTemplates> > precision_guard(a, b);
  2241. return boost::math::nextafter(a, b, c99_error_policy());
  2242. }
  2243. template <class Backend, multiprecision::expression_template_option ExpressionTemplates, class tag, class A1, class A2, class A3, class A4>
  2244. inline multiprecision::number<Backend, ExpressionTemplates> nextafter BOOST_PREVENT_MACRO_SUBSTITUTION(const multiprecision::number<Backend, ExpressionTemplates>& a, const multiprecision::detail::expression<tag, A1, A2, A3, A4>& b)
  2245. {
  2246. detail::scoped_default_precision<multiprecision::number<Backend, ExpressionTemplates> > precision_guard(a, b);
  2247. return nextafter BOOST_PREVENT_MACRO_SUBSTITUTION(a, multiprecision::number<Backend, ExpressionTemplates>(b));
  2248. }
  2249. template <class tag, class A1, class A2, class A3, class A4, class Backend, multiprecision::expression_template_option ExpressionTemplates>
  2250. inline multiprecision::number<Backend, ExpressionTemplates> nextafter BOOST_PREVENT_MACRO_SUBSTITUTION(const multiprecision::detail::expression<tag, A1, A2, A3, A4>& a, const multiprecision::number<Backend, ExpressionTemplates>& b)
  2251. {
  2252. detail::scoped_default_precision<multiprecision::number<Backend, ExpressionTemplates> > precision_guard(a, b);
  2253. return nextafter BOOST_PREVENT_MACRO_SUBSTITUTION(multiprecision::number<Backend, ExpressionTemplates>(a), b);
  2254. }
  2255. template <class tag, class A1, class A2, class A3, class A4, class tagb, class A1b, class A2b, class A3b, class A4b>
  2256. inline typename multiprecision::detail::expression<tag, A1, A2, A3, A4>::result_type nextafter BOOST_PREVENT_MACRO_SUBSTITUTION(const multiprecision::detail::expression<tag, A1, A2, A3, A4>& a, const multiprecision::detail::expression<tagb, A1b, A2b, A3b, A4b>& b)
  2257. {
  2258. typedef typename multiprecision::detail::expression<tag, A1, A2, A3, A4>::result_type value_type;
  2259. detail::scoped_default_precision<value_type> precision_guard(a, b);
  2260. return nextafter BOOST_PREVENT_MACRO_SUBSTITUTION(value_type(a), value_type(b));
  2261. }
  2262. template <class Backend, multiprecision::expression_template_option ExpressionTemplates>
  2263. inline multiprecision::number<Backend, ExpressionTemplates> nexttoward BOOST_PREVENT_MACRO_SUBSTITUTION(const multiprecision::number<Backend, ExpressionTemplates>& a, const multiprecision::number<Backend, ExpressionTemplates>& b)
  2264. {
  2265. detail::scoped_default_precision<multiprecision::number<Backend, ExpressionTemplates> > precision_guard(a, b);
  2266. return boost::math::nextafter(a, b, c99_error_policy());
  2267. }
  2268. template <class Backend, multiprecision::expression_template_option ExpressionTemplates, class tag, class A1, class A2, class A3, class A4>
  2269. inline multiprecision::number<Backend, ExpressionTemplates> nexttoward BOOST_PREVENT_MACRO_SUBSTITUTION(const multiprecision::number<Backend, ExpressionTemplates>& a, const multiprecision::detail::expression<tag, A1, A2, A3, A4>& b)
  2270. {
  2271. detail::scoped_default_precision<multiprecision::number<Backend, ExpressionTemplates> > precision_guard(a, b);
  2272. return nexttoward BOOST_PREVENT_MACRO_SUBSTITUTION(a, multiprecision::number<Backend, ExpressionTemplates>(b));
  2273. }
  2274. template <class tag, class A1, class A2, class A3, class A4, class Backend, multiprecision::expression_template_option ExpressionTemplates>
  2275. inline multiprecision::number<Backend, ExpressionTemplates> nexttoward BOOST_PREVENT_MACRO_SUBSTITUTION(const multiprecision::detail::expression<tag, A1, A2, A3, A4>& a, const multiprecision::number<Backend, ExpressionTemplates>& b)
  2276. {
  2277. detail::scoped_default_precision<multiprecision::number<Backend, ExpressionTemplates> > precision_guard(a, b);
  2278. return nexttoward BOOST_PREVENT_MACRO_SUBSTITUTION(multiprecision::number<Backend, ExpressionTemplates>(a), b);
  2279. }
  2280. template <class tag, class A1, class A2, class A3, class A4, class tagb, class A1b, class A2b, class A3b, class A4b>
  2281. inline typename multiprecision::detail::expression<tag, A1, A2, A3, A4>::result_type nexttoward BOOST_PREVENT_MACRO_SUBSTITUTION(const multiprecision::detail::expression<tag, A1, A2, A3, A4>& a, const multiprecision::detail::expression<tagb, A1b, A2b, A3b, A4b>& b)
  2282. {
  2283. typedef typename multiprecision::detail::expression<tag, A1, A2, A3, A4>::result_type value_type;
  2284. detail::scoped_default_precision<value_type> precision_guard(a, b);
  2285. return nexttoward BOOST_PREVENT_MACRO_SUBSTITUTION(value_type(a), value_type(b));
  2286. }
  2287. template <class B1, class B2, class B3, expression_template_option ET1, expression_template_option ET2, expression_template_option ET3>
  2288. inline number<B1, ET1>& add(number<B1, ET1>& result, const number<B2, ET2>& a, const number<B3, ET3>& b)
  2289. {
  2290. BOOST_STATIC_ASSERT_MSG((is_convertible<B2, B1>::value), "No conversion to the target of a mixed precision addition exists");
  2291. BOOST_STATIC_ASSERT_MSG((is_convertible<B3, B1>::value), "No conversion to the target of a mixed precision addition exists");
  2292. using default_ops::eval_add;
  2293. eval_add(result.backend(), a.backend(), b.backend());
  2294. return result;
  2295. }
  2296. template <class B1, class B2, class B3, expression_template_option ET1, expression_template_option ET2, expression_template_option ET3>
  2297. inline number<B1, ET1>& subtract(number<B1, ET1>& result, const number<B2, ET2>& a, const number<B3, ET3>& b)
  2298. {
  2299. BOOST_STATIC_ASSERT_MSG((is_convertible<B2, B1>::value), "No conversion to the target of a mixed precision addition exists");
  2300. BOOST_STATIC_ASSERT_MSG((is_convertible<B3, B1>::value), "No conversion to the target of a mixed precision addition exists");
  2301. using default_ops::eval_subtract;
  2302. eval_subtract(result.backend(), a.backend(), b.backend());
  2303. return result;
  2304. }
  2305. template <class B1, class B2, class B3, expression_template_option ET1, expression_template_option ET2, expression_template_option ET3>
  2306. inline number<B1, ET1>& multiply(number<B1, ET1>& result, const number<B2, ET2>& a, const number<B3, ET3>& b)
  2307. {
  2308. BOOST_STATIC_ASSERT_MSG((is_convertible<B2, B1>::value), "No conversion to the target of a mixed precision addition exists");
  2309. BOOST_STATIC_ASSERT_MSG((is_convertible<B3, B1>::value), "No conversion to the target of a mixed precision addition exists");
  2310. using default_ops::eval_multiply;
  2311. eval_multiply(result.backend(), a.backend(), b.backend());
  2312. return result;
  2313. }
  2314. template <class B, expression_template_option ET, class I>
  2315. inline typename enable_if_c<is_integral<I>::value, number<B, ET>&>::type
  2316. add(number<B, ET>& result, const I& a, const I& b)
  2317. {
  2318. using default_ops::eval_add;
  2319. typedef typename detail::canonical<I, B>::type canonical_type;
  2320. eval_add(result.backend(), static_cast<canonical_type>(a), static_cast<canonical_type>(b));
  2321. return result;
  2322. }
  2323. template <class B, expression_template_option ET, class I>
  2324. inline typename enable_if_c<is_integral<I>::value, number<B, ET>&>::type
  2325. subtract(number<B, ET>& result, const I& a, const I& b)
  2326. {
  2327. using default_ops::eval_subtract;
  2328. typedef typename detail::canonical<I, B>::type canonical_type;
  2329. eval_subtract(result.backend(), static_cast<canonical_type>(a), static_cast<canonical_type>(b));
  2330. return result;
  2331. }
  2332. template <class B, expression_template_option ET, class I>
  2333. inline typename enable_if_c<is_integral<I>::value, number<B, ET>&>::type
  2334. multiply(number<B, ET>& result, const I& a, const I& b)
  2335. {
  2336. using default_ops::eval_multiply;
  2337. typedef typename detail::canonical<I, B>::type canonical_type;
  2338. eval_multiply(result.backend(), static_cast<canonical_type>(a), static_cast<canonical_type>(b));
  2339. return result;
  2340. }
  2341. template <class tag, class A1, class A2, class A3, class A4, class Policy>
  2342. inline typename detail::expression<tag, A1, A2, A3, A4>::result_type trunc(const detail::expression<tag, A1, A2, A3, A4>& v, const Policy& pol)
  2343. {
  2344. typedef typename detail::expression<tag, A1, A2, A3, A4>::result_type number_type;
  2345. return BOOST_MP_MOVE(trunc(number_type(v), pol));
  2346. }
  2347. template <class Backend, expression_template_option ExpressionTemplates, class Policy>
  2348. inline number<Backend, ExpressionTemplates> trunc(const number<Backend, ExpressionTemplates>& v, const Policy&)
  2349. {
  2350. using default_ops::eval_trunc;
  2351. detail::scoped_default_precision<multiprecision::number<Backend, ExpressionTemplates> > precision_guard(v);
  2352. number<Backend, ExpressionTemplates> result;
  2353. eval_trunc(result.backend(), v.backend());
  2354. return BOOST_MP_MOVE(result);
  2355. }
  2356. template <class tag, class A1, class A2, class A3, class A4, class Policy>
  2357. inline int itrunc(const detail::expression<tag, A1, A2, A3, A4>& v, const Policy& pol)
  2358. {
  2359. typedef typename detail::expression<tag, A1, A2, A3, A4>::result_type number_type;
  2360. number_type r(trunc(v, pol));
  2361. if((r > (std::numeric_limits<int>::max)()) || r < (std::numeric_limits<int>::min)() || !(boost::math::isfinite)(v))
  2362. return boost::math::policies::raise_rounding_error("boost::multiprecision::itrunc<%1%>(%1%)", 0, number_type(v), 0, pol);
  2363. return r.template convert_to<int>();
  2364. }
  2365. template <class tag, class A1, class A2, class A3, class A4>
  2366. inline int itrunc(const detail::expression<tag, A1, A2, A3, A4>& v)
  2367. {
  2368. return itrunc(v, boost::math::policies::policy<>());
  2369. }
  2370. template <class Backend, expression_template_option ExpressionTemplates, class Policy>
  2371. inline int itrunc(const number<Backend, ExpressionTemplates>& v, const Policy& pol)
  2372. {
  2373. number<Backend, ExpressionTemplates> r(trunc(v, pol));
  2374. if((r > (std::numeric_limits<int>::max)()) || r < (std::numeric_limits<int>::min)() || !(boost::math::isfinite)(v))
  2375. return boost::math::policies::raise_rounding_error("boost::multiprecision::itrunc<%1%>(%1%)", 0, v, 0, pol);
  2376. return r.template convert_to<int>();
  2377. }
  2378. template <class Backend, expression_template_option ExpressionTemplates>
  2379. inline int itrunc(const number<Backend, ExpressionTemplates>& v)
  2380. {
  2381. return itrunc(v, boost::math::policies::policy<>());
  2382. }
  2383. template <class tag, class A1, class A2, class A3, class A4, class Policy>
  2384. inline long ltrunc(const detail::expression<tag, A1, A2, A3, A4>& v, const Policy& pol)
  2385. {
  2386. typedef typename detail::expression<tag, A1, A2, A3, A4>::result_type number_type;
  2387. number_type r(trunc(v, pol));
  2388. if((r > (std::numeric_limits<long>::max)()) || r < (std::numeric_limits<long>::min)() || !(boost::math::isfinite)(v))
  2389. return boost::math::policies::raise_rounding_error("boost::multiprecision::ltrunc<%1%>(%1%)", 0, number_type(v), 0L, pol);
  2390. return r.template convert_to<long>();
  2391. }
  2392. template <class tag, class A1, class A2, class A3, class A4>
  2393. inline long ltrunc(const detail::expression<tag, A1, A2, A3, A4>& v)
  2394. {
  2395. return ltrunc(v, boost::math::policies::policy<>());
  2396. }
  2397. template <class T, expression_template_option ExpressionTemplates, class Policy>
  2398. inline long ltrunc(const number<T, ExpressionTemplates>& v, const Policy& pol)
  2399. {
  2400. number<T, ExpressionTemplates> r(trunc(v, pol));
  2401. if((r > (std::numeric_limits<long>::max)()) || r < (std::numeric_limits<long>::min)() || !(boost::math::isfinite)(v))
  2402. return boost::math::policies::raise_rounding_error("boost::multiprecision::ltrunc<%1%>(%1%)", 0, v, 0L, pol);
  2403. return r.template convert_to<long>();
  2404. }
  2405. template <class T, expression_template_option ExpressionTemplates>
  2406. inline long ltrunc(const number<T, ExpressionTemplates>& v)
  2407. {
  2408. return ltrunc(v, boost::math::policies::policy<>());
  2409. }
  2410. #ifndef BOOST_NO_LONG_LONG
  2411. template <class tag, class A1, class A2, class A3, class A4, class Policy>
  2412. inline boost::long_long_type lltrunc(const detail::expression<tag, A1, A2, A3, A4>& v, const Policy& pol)
  2413. {
  2414. typedef typename detail::expression<tag, A1, A2, A3, A4>::result_type number_type;
  2415. number_type r(trunc(v, pol));
  2416. if((r > (std::numeric_limits<boost::long_long_type>::max)()) || r < (std::numeric_limits<boost::long_long_type>::min)() || !(boost::math::isfinite)(v))
  2417. return boost::math::policies::raise_rounding_error("boost::multiprecision::lltrunc<%1%>(%1%)", 0, number_type(v), 0LL, pol);
  2418. return r.template convert_to<boost::long_long_type>();
  2419. }
  2420. template <class tag, class A1, class A2, class A3, class A4>
  2421. inline boost::long_long_type lltrunc(const detail::expression<tag, A1, A2, A3, A4>& v)
  2422. {
  2423. return lltrunc(v, boost::math::policies::policy<>());
  2424. }
  2425. template <class T, expression_template_option ExpressionTemplates, class Policy>
  2426. inline boost::long_long_type lltrunc(const number<T, ExpressionTemplates>& v, const Policy& pol)
  2427. {
  2428. number<T, ExpressionTemplates> r(trunc(v, pol));
  2429. if((r > (std::numeric_limits<boost::long_long_type>::max)()) || r < (std::numeric_limits<boost::long_long_type>::min)() || !(boost::math::isfinite)(v))
  2430. return boost::math::policies::raise_rounding_error("boost::multiprecision::lltrunc<%1%>(%1%)", 0, v, 0LL, pol);
  2431. return r.template convert_to<boost::long_long_type>();
  2432. }
  2433. template <class T, expression_template_option ExpressionTemplates>
  2434. inline boost::long_long_type lltrunc(const number<T, ExpressionTemplates>& v)
  2435. {
  2436. return lltrunc(v, boost::math::policies::policy<>());
  2437. }
  2438. #endif
  2439. template <class tag, class A1, class A2, class A3, class A4, class Policy>
  2440. inline typename detail::expression<tag, A1, A2, A3, A4>::result_type round(const detail::expression<tag, A1, A2, A3, A4>& v, const Policy& pol)
  2441. {
  2442. typedef typename detail::expression<tag, A1, A2, A3, A4>::result_type number_type;
  2443. return BOOST_MP_MOVE(round(static_cast<number_type>(v), pol));
  2444. }
  2445. template <class T, expression_template_option ExpressionTemplates, class Policy>
  2446. inline number<T, ExpressionTemplates> round(const number<T, ExpressionTemplates>& v, const Policy&)
  2447. {
  2448. using default_ops::eval_round;
  2449. detail::scoped_default_precision<multiprecision::number<T, ExpressionTemplates> > precision_guard(v);
  2450. number<T, ExpressionTemplates> result;
  2451. eval_round(result.backend(), v.backend());
  2452. return BOOST_MP_MOVE(result);
  2453. }
  2454. template <class tag, class A1, class A2, class A3, class A4, class Policy>
  2455. inline int iround(const detail::expression<tag, A1, A2, A3, A4>& v, const Policy& pol)
  2456. {
  2457. typedef typename detail::expression<tag, A1, A2, A3, A4>::result_type number_type;
  2458. number_type r(round(v, pol));
  2459. if((r > (std::numeric_limits<int>::max)()) || r < (std::numeric_limits<int>::min)() || !(boost::math::isfinite)(v))
  2460. return boost::math::policies::raise_rounding_error("boost::multiprecision::iround<%1%>(%1%)", 0, number_type(v), 0, pol);
  2461. return r.template convert_to<int>();
  2462. }
  2463. template <class tag, class A1, class A2, class A3, class A4>
  2464. inline int iround(const detail::expression<tag, A1, A2, A3, A4>& v)
  2465. {
  2466. return iround(v, boost::math::policies::policy<>());
  2467. }
  2468. template <class T, expression_template_option ExpressionTemplates, class Policy>
  2469. inline int iround(const number<T, ExpressionTemplates>& v, const Policy& pol)
  2470. {
  2471. number<T, ExpressionTemplates> r(round(v, pol));
  2472. if((r > (std::numeric_limits<int>::max)()) || r < (std::numeric_limits<int>::min)() || !(boost::math::isfinite)(v))
  2473. return boost::math::policies::raise_rounding_error("boost::multiprecision::iround<%1%>(%1%)", 0, v, 0, pol);
  2474. return r.template convert_to<int>();
  2475. }
  2476. template <class T, expression_template_option ExpressionTemplates>
  2477. inline int iround(const number<T, ExpressionTemplates>& v)
  2478. {
  2479. return iround(v, boost::math::policies::policy<>());
  2480. }
  2481. template <class tag, class A1, class A2, class A3, class A4, class Policy>
  2482. inline long lround(const detail::expression<tag, A1, A2, A3, A4>& v, const Policy& pol)
  2483. {
  2484. typedef typename detail::expression<tag, A1, A2, A3, A4>::result_type number_type;
  2485. number_type r(round(v, pol));
  2486. if((r > (std::numeric_limits<long>::max)()) || r < (std::numeric_limits<long>::min)() || !(boost::math::isfinite)(v))
  2487. return boost::math::policies::raise_rounding_error("boost::multiprecision::lround<%1%>(%1%)", 0, number_type(v), 0L, pol);
  2488. return r.template convert_to<long>();
  2489. }
  2490. template <class tag, class A1, class A2, class A3, class A4>
  2491. inline long lround(const detail::expression<tag, A1, A2, A3, A4>& v)
  2492. {
  2493. return lround(v, boost::math::policies::policy<>());
  2494. }
  2495. template <class T, expression_template_option ExpressionTemplates, class Policy>
  2496. inline long lround(const number<T, ExpressionTemplates>& v, const Policy& pol)
  2497. {
  2498. number<T, ExpressionTemplates> r(round(v, pol));
  2499. if((r > (std::numeric_limits<long>::max)()) || r < (std::numeric_limits<long>::min)() || !(boost::math::isfinite)(v))
  2500. return boost::math::policies::raise_rounding_error("boost::multiprecision::lround<%1%>(%1%)", 0, v, 0L, pol);
  2501. return r.template convert_to<long>();
  2502. }
  2503. template <class T, expression_template_option ExpressionTemplates>
  2504. inline long lround(const number<T, ExpressionTemplates>& v)
  2505. {
  2506. return lround(v, boost::math::policies::policy<>());
  2507. }
  2508. #ifndef BOOST_NO_LONG_LONG
  2509. template <class tag, class A1, class A2, class A3, class A4, class Policy>
  2510. inline boost::long_long_type llround(const detail::expression<tag, A1, A2, A3, A4>& v, const Policy& pol)
  2511. {
  2512. typedef typename detail::expression<tag, A1, A2, A3, A4>::result_type number_type;
  2513. number_type r(round(v, pol));
  2514. if((r > (std::numeric_limits<boost::long_long_type>::max)()) || r < (std::numeric_limits<boost::long_long_type>::min)() || !(boost::math::isfinite)(v))
  2515. return boost::math::policies::raise_rounding_error("boost::multiprecision::iround<%1%>(%1%)", 0, number_type(v), 0LL, pol);
  2516. return r.template convert_to<boost::long_long_type>();
  2517. }
  2518. template <class tag, class A1, class A2, class A3, class A4>
  2519. inline boost::long_long_type llround(const detail::expression<tag, A1, A2, A3, A4>& v)
  2520. {
  2521. return llround(v, boost::math::policies::policy<>());
  2522. }
  2523. template <class T, expression_template_option ExpressionTemplates, class Policy>
  2524. inline boost::long_long_type llround(const number<T, ExpressionTemplates>& v, const Policy& pol)
  2525. {
  2526. number<T, ExpressionTemplates> r(round(v, pol));
  2527. if((r > (std::numeric_limits<boost::long_long_type>::max)()) || r < (std::numeric_limits<boost::long_long_type>::min)() || !(boost::math::isfinite)(v))
  2528. return boost::math::policies::raise_rounding_error("boost::multiprecision::iround<%1%>(%1%)", 0, v, 0LL, pol);
  2529. return r.template convert_to<boost::long_long_type>();
  2530. }
  2531. template <class T, expression_template_option ExpressionTemplates>
  2532. inline boost::long_long_type llround(const number<T, ExpressionTemplates>& v)
  2533. {
  2534. return llround(v, boost::math::policies::policy<>());
  2535. }
  2536. #endif
  2537. //
  2538. // frexp does not return an expression template since we require the
  2539. // integer argument to be evaluated even if the returned value is
  2540. // not assigned to anything...
  2541. //
  2542. template <class T, expression_template_option ExpressionTemplates>
  2543. inline typename enable_if_c<number_category<T>::value == number_kind_floating_point, number<T, ExpressionTemplates> >::type frexp(const number<T, ExpressionTemplates>& v, short* pint)
  2544. {
  2545. using default_ops::eval_frexp;
  2546. detail::scoped_default_precision<multiprecision::number<T, ExpressionTemplates> > precision_guard(v);
  2547. number<T, ExpressionTemplates> result;
  2548. eval_frexp(result.backend(), v.backend(), pint);
  2549. return BOOST_MP_MOVE(result);
  2550. }
  2551. template <class tag, class A1, class A2, class A3, class A4>
  2552. inline typename enable_if_c<number_category<typename detail::expression<tag, A1, A2, A3, A4>::result_type>::value == number_kind_floating_point, typename detail::expression<tag, A1, A2, A3, A4>::result_type>::type
  2553. frexp(const detail::expression<tag, A1, A2, A3, A4>& v, short* pint)
  2554. {
  2555. typedef typename detail::expression<tag, A1, A2, A3, A4>::result_type number_type;
  2556. return BOOST_MP_MOVE(frexp(static_cast<number_type>(v), pint));
  2557. }
  2558. template <class T, expression_template_option ExpressionTemplates>
  2559. inline typename enable_if_c<number_category<T>::value == number_kind_floating_point, number<T, ExpressionTemplates> >::type frexp(const number<T, ExpressionTemplates>& v, int* pint)
  2560. {
  2561. using default_ops::eval_frexp;
  2562. detail::scoped_default_precision<multiprecision::number<T, ExpressionTemplates> > precision_guard(v);
  2563. number<T, ExpressionTemplates> result;
  2564. eval_frexp(result.backend(), v.backend(), pint);
  2565. return BOOST_MP_MOVE(result);
  2566. }
  2567. template <class tag, class A1, class A2, class A3, class A4>
  2568. inline typename enable_if_c<number_category<typename detail::expression<tag, A1, A2, A3, A4>::result_type>::value == number_kind_floating_point, typename detail::expression<tag, A1, A2, A3, A4>::result_type>::type
  2569. frexp(const detail::expression<tag, A1, A2, A3, A4>& v, int* pint)
  2570. {
  2571. typedef typename detail::expression<tag, A1, A2, A3, A4>::result_type number_type;
  2572. return BOOST_MP_MOVE(frexp(static_cast<number_type>(v), pint));
  2573. }
  2574. template <class T, expression_template_option ExpressionTemplates>
  2575. inline typename enable_if_c<number_category<T>::value == number_kind_floating_point, number<T, ExpressionTemplates> >::type frexp(const number<T, ExpressionTemplates>& v, long* pint)
  2576. {
  2577. using default_ops::eval_frexp;
  2578. detail::scoped_default_precision<multiprecision::number<T, ExpressionTemplates> > precision_guard(v);
  2579. number<T, ExpressionTemplates> result;
  2580. eval_frexp(result.backend(), v.backend(), pint);
  2581. return BOOST_MP_MOVE(result);
  2582. }
  2583. template <class tag, class A1, class A2, class A3, class A4>
  2584. inline typename enable_if_c<number_category<typename detail::expression<tag, A1, A2, A3, A4>::result_type>::value == number_kind_floating_point, typename detail::expression<tag, A1, A2, A3, A4>::result_type>::type
  2585. frexp(const detail::expression<tag, A1, A2, A3, A4>& v, long* pint)
  2586. {
  2587. typedef typename detail::expression<tag, A1, A2, A3, A4>::result_type number_type;
  2588. return BOOST_MP_MOVE(frexp(static_cast<number_type>(v), pint));
  2589. }
  2590. template <class T, expression_template_option ExpressionTemplates>
  2591. inline typename enable_if_c<number_category<T>::value == number_kind_floating_point, number<T, ExpressionTemplates> >::type frexp(const number<T, ExpressionTemplates>& v, boost::long_long_type* pint)
  2592. {
  2593. using default_ops::eval_frexp;
  2594. detail::scoped_default_precision<multiprecision::number<T, ExpressionTemplates> > precision_guard(v);
  2595. number<T, ExpressionTemplates> result;
  2596. eval_frexp(result.backend(), v.backend(), pint);
  2597. return BOOST_MP_MOVE(result);
  2598. }
  2599. template <class tag, class A1, class A2, class A3, class A4>
  2600. inline typename enable_if_c<number_category<typename detail::expression<tag, A1, A2, A3, A4>::result_type>::value == number_kind_floating_point, typename detail::expression<tag, A1, A2, A3, A4>::result_type>::type
  2601. frexp(const detail::expression<tag, A1, A2, A3, A4>& v, boost::long_long_type* pint)
  2602. {
  2603. typedef typename detail::expression<tag, A1, A2, A3, A4>::result_type number_type;
  2604. return BOOST_MP_MOVE(frexp(static_cast<number_type>(v), pint));
  2605. }
  2606. //
  2607. // modf does not return an expression template since we require the
  2608. // second argument to be evaluated even if the returned value is
  2609. // not assigned to anything...
  2610. //
  2611. template <class T, expression_template_option ExpressionTemplates>
  2612. inline typename enable_if_c<number_category<T>::value == number_kind_floating_point, number<T, ExpressionTemplates> >::type modf(const number<T, ExpressionTemplates>& v, number<T, ExpressionTemplates>* pipart)
  2613. {
  2614. using default_ops::eval_modf;
  2615. detail::scoped_default_precision<multiprecision::number<T, ExpressionTemplates> > precision_guard(v);
  2616. number<T, ExpressionTemplates> result;
  2617. eval_modf(result.backend(), v.backend(), pipart ? &pipart->backend() : 0);
  2618. return BOOST_MP_MOVE(result);
  2619. }
  2620. template <class T, expression_template_option ExpressionTemplates, class tag, class A1, class A2, class A3, class A4>
  2621. inline typename enable_if_c<number_category<T>::value == number_kind_floating_point, number<T, ExpressionTemplates> >::type modf(const detail::expression<tag, A1, A2, A3, A4>& v, number<T, ExpressionTemplates>* pipart)
  2622. {
  2623. using default_ops::eval_modf;
  2624. detail::scoped_default_precision<multiprecision::number<T, ExpressionTemplates> > precision_guard(v);
  2625. number<T, ExpressionTemplates> result, arg(v);
  2626. eval_modf(result.backend(), arg.backend(), pipart ? &pipart->backend() : 0);
  2627. return BOOST_MP_MOVE(result);
  2628. }
  2629. //
  2630. // Integer square root:
  2631. //
  2632. template <class B, expression_template_option ExpressionTemplates>
  2633. inline typename enable_if_c<number_category<B>::value == number_kind_integer, number<B, ExpressionTemplates> >::type
  2634. sqrt(const number<B, ExpressionTemplates>& x)
  2635. {
  2636. using default_ops::eval_integer_sqrt;
  2637. number<B, ExpressionTemplates> s, r;
  2638. eval_integer_sqrt(s.backend(), r.backend(), x.backend());
  2639. return s;
  2640. }
  2641. //
  2642. // fma:
  2643. //
  2644. namespace default_ops {
  2645. struct fma_func
  2646. {
  2647. template <class B, class T, class U, class V>
  2648. void operator()(B& result, const T& a, const U& b, const V& c)const
  2649. {
  2650. eval_multiply_add(result, a, b, c);
  2651. }
  2652. };
  2653. }
  2654. template <class Backend, class U, class V>
  2655. inline typename enable_if<
  2656. mpl::and_<
  2657. mpl::bool_<number_category<number<Backend, et_on> >::value == number_kind_floating_point>,
  2658. mpl::or_<
  2659. is_number<U>,
  2660. is_number_expression<U>,
  2661. is_arithmetic<U>
  2662. >,
  2663. mpl::or_<
  2664. is_number<V>,
  2665. is_number_expression<V>,
  2666. is_arithmetic<V>
  2667. >
  2668. >,
  2669. detail::expression<detail::function, default_ops::fma_func, number<Backend, et_on>, U, V>
  2670. >::type
  2671. fma(const number<Backend, et_on>& a, const U& b, const V& c)
  2672. {
  2673. return detail::expression<detail::function, default_ops::fma_func, number<Backend, et_on>, U, V>(
  2674. default_ops::fma_func(), a, b, c);
  2675. }
  2676. template <class tag, class Arg1, class Arg2, class Arg3, class Arg4, class U, class V>
  2677. inline typename enable_if<
  2678. mpl::and_<
  2679. mpl::bool_<number_category<typename detail::expression<tag, Arg1, Arg2, Arg3, Arg4>::result_type >::value == number_kind_floating_point>,
  2680. mpl::or_<
  2681. is_number<U>,
  2682. is_number_expression<U>,
  2683. is_arithmetic<U>
  2684. >,
  2685. mpl::or_<
  2686. is_number<V>,
  2687. is_number_expression<V>,
  2688. is_arithmetic<V>
  2689. >
  2690. >,
  2691. detail::expression<detail::function, default_ops::fma_func, detail::expression<tag, Arg1, Arg2, Arg3, Arg4>, U, V>
  2692. >::type
  2693. fma(const detail::expression<tag, Arg1, Arg2, Arg3, Arg4>& a, const U& b, const V& c)
  2694. {
  2695. return detail::expression<detail::function, default_ops::fma_func, detail::expression<tag, Arg1, Arg2, Arg3, Arg4>, U, V>(
  2696. default_ops::fma_func(), a, b, c);
  2697. }
  2698. template <class Backend, class U, class V>
  2699. inline typename enable_if<
  2700. mpl::and_<
  2701. mpl::bool_<number_category<number<Backend, et_off> >::value == number_kind_floating_point>,
  2702. mpl::or_<
  2703. is_number<U>,
  2704. is_number_expression<U>,
  2705. is_arithmetic<U>
  2706. >,
  2707. mpl::or_<
  2708. is_number<V>,
  2709. is_number_expression<V>,
  2710. is_arithmetic<V>
  2711. >
  2712. >,
  2713. number<Backend, et_off>
  2714. >::type
  2715. fma(const number<Backend, et_off>& a, const U& b, const V& c)
  2716. {
  2717. using default_ops::eval_multiply_add;
  2718. detail::scoped_default_precision<multiprecision::number<Backend, et_off> > precision_guard(a, b, c);
  2719. number<Backend, et_off> result;
  2720. eval_multiply_add(result.backend(), number<Backend, et_off>::canonical_value(a), number<Backend, et_off>::canonical_value(b), number<Backend, et_off>::canonical_value(c));
  2721. return BOOST_MP_MOVE(result);
  2722. }
  2723. template <class U, class Backend, class V>
  2724. inline typename enable_if<
  2725. mpl::and_<
  2726. mpl::bool_<number_category<number<Backend, et_on> >::value == number_kind_floating_point>,
  2727. is_arithmetic<U>,
  2728. mpl::or_<
  2729. is_number<V>,
  2730. is_number_expression<V>,
  2731. is_arithmetic<V>
  2732. >
  2733. >,
  2734. detail::expression<detail::function, default_ops::fma_func, U, number<Backend, et_on>, V>
  2735. >::type
  2736. fma(const U& a, const number<Backend, et_on>& b, const V& c)
  2737. {
  2738. return detail::expression<detail::function, default_ops::fma_func, U, number<Backend, et_on>, V>(
  2739. default_ops::fma_func(), a, b, c);
  2740. }
  2741. template <class U, class tag, class Arg1, class Arg2, class Arg3, class Arg4, class V>
  2742. inline typename enable_if<
  2743. mpl::and_<
  2744. mpl::bool_<number_category<typename detail::expression<tag, Arg1, Arg2, Arg3, Arg4>::result_type >::value == number_kind_floating_point>,
  2745. is_arithmetic<U>,
  2746. mpl::or_<
  2747. is_number<V>,
  2748. is_number_expression<V>,
  2749. is_arithmetic<V>
  2750. >
  2751. >,
  2752. detail::expression<detail::function, default_ops::fma_func, U, detail::expression<tag, Arg1, Arg2, Arg3, Arg4>, V>
  2753. >::type
  2754. fma(const U& a, const detail::expression<tag, Arg1, Arg2, Arg3, Arg4>& b, const V& c)
  2755. {
  2756. return detail::expression<detail::function, default_ops::fma_func, U, detail::expression<tag, Arg1, Arg2, Arg3, Arg4>, V>(
  2757. default_ops::fma_func(), a, b, c);
  2758. }
  2759. template <class U, class Backend, class V>
  2760. inline typename enable_if<
  2761. mpl::and_<
  2762. mpl::bool_<number_category<number<Backend, et_off> >::value == number_kind_floating_point>,
  2763. is_arithmetic<U>,
  2764. mpl::or_<
  2765. is_number<V>,
  2766. is_number_expression<V>,
  2767. is_arithmetic<V>
  2768. >
  2769. >,
  2770. number<Backend, et_off>
  2771. >::type
  2772. fma(const U& a, const number<Backend, et_off>& b, const V& c)
  2773. {
  2774. using default_ops::eval_multiply_add;
  2775. detail::scoped_default_precision<multiprecision::number<Backend, et_off> > precision_guard(a, b, c);
  2776. number<Backend, et_off> result;
  2777. eval_multiply_add(result.backend(), number<Backend, et_off>::canonical_value(a), number<Backend, et_off>::canonical_value(b), number<Backend, et_off>::canonical_value(c));
  2778. return BOOST_MP_MOVE(result);
  2779. }
  2780. template <class U, class V, class Backend>
  2781. inline typename enable_if<
  2782. mpl::and_<
  2783. mpl::bool_<number_category<number<Backend, et_on> >::value == number_kind_floating_point>,
  2784. is_arithmetic<U>,
  2785. is_arithmetic<V>
  2786. >,
  2787. detail::expression<detail::function, default_ops::fma_func, U, V, number<Backend, et_on> >
  2788. >::type
  2789. fma(const U& a, const V& b, const number<Backend, et_on>& c)
  2790. {
  2791. return detail::expression<detail::function, default_ops::fma_func, U, V, number<Backend, et_on> >(
  2792. default_ops::fma_func(), a, b, c);
  2793. }
  2794. template <class U, class V, class tag, class Arg1, class Arg2, class Arg3, class Arg4>
  2795. inline typename enable_if<
  2796. mpl::and_<
  2797. mpl::bool_<number_category<typename detail::expression<tag, Arg1, Arg2, Arg3, Arg4>::result_type >::value == number_kind_floating_point>,
  2798. is_arithmetic<U>,
  2799. is_arithmetic<V>
  2800. >,
  2801. detail::expression<detail::function, default_ops::fma_func, U, V, detail::expression<tag, Arg1, Arg2, Arg3, Arg4> >
  2802. >::type
  2803. fma(const U& a, const V& b, const detail::expression<tag, Arg1, Arg2, Arg3, Arg4>& c)
  2804. {
  2805. return detail::expression<detail::function, default_ops::fma_func, U, V, detail::expression<tag, Arg1, Arg2, Arg3, Arg4> >(
  2806. default_ops::fma_func(), a, b, c);
  2807. }
  2808. template <class U, class V, class Backend>
  2809. inline typename enable_if<
  2810. mpl::and_<
  2811. mpl::bool_<number_category<number<Backend, et_off> >::value == number_kind_floating_point>,
  2812. is_arithmetic<U>,
  2813. is_arithmetic<V>
  2814. >,
  2815. number<Backend, et_off>
  2816. >::type
  2817. fma(const U& a, const V& b, const number<Backend, et_off>& c)
  2818. {
  2819. using default_ops::eval_multiply_add;
  2820. detail::scoped_default_precision<multiprecision::number<Backend, et_off> > precision_guard(a, b, c);
  2821. number<Backend, et_off> result;
  2822. eval_multiply_add(result.backend(), number<Backend, et_off>::canonical_value(a), number<Backend, et_off>::canonical_value(b), number<Backend, et_off>::canonical_value(c));
  2823. return BOOST_MP_MOVE(result);
  2824. }
  2825. namespace default_ops {
  2826. struct remquo_func
  2827. {
  2828. template <class B, class T, class U>
  2829. void operator()(B& result, const T& a, const U& b, int* pi)const
  2830. {
  2831. eval_remquo(result, a, b, pi);
  2832. }
  2833. };
  2834. }
  2835. template <class Backend, class U>
  2836. inline typename enable_if_c<
  2837. number_category<number<Backend, et_on> >::value == number_kind_floating_point,
  2838. detail::expression<detail::function, default_ops::remquo_func, number<Backend, et_on>, U, int*>
  2839. >::type
  2840. remquo(const number<Backend, et_on>& a, const U& b, int* pi)
  2841. {
  2842. return detail::expression<detail::function, default_ops::remquo_func, number<Backend, et_on>, U, int*>(
  2843. default_ops::remquo_func(), a, b, pi);
  2844. }
  2845. template <class tag, class Arg1, class Arg2, class Arg3, class Arg4, class U>
  2846. inline typename enable_if_c<
  2847. number_category<typename detail::expression<tag, Arg1, Arg2, Arg3, Arg4>::result_type >::value == number_kind_floating_point,
  2848. detail::expression<detail::function, default_ops::remquo_func, detail::expression<tag, Arg1, Arg2, Arg3, Arg4>, U, int*>
  2849. >::type
  2850. remquo(const detail::expression<tag, Arg1, Arg2, Arg3, Arg4>& a, const U& b, int* pi)
  2851. {
  2852. return detail::expression<detail::function, default_ops::remquo_func, detail::expression<tag, Arg1, Arg2, Arg3, Arg4>, U, int*>(
  2853. default_ops::remquo_func(), a, b, pi);
  2854. }
  2855. template <class U, class Backend>
  2856. inline typename enable_if_c<
  2857. (number_category<number<Backend, et_on> >::value == number_kind_floating_point)
  2858. && !is_number<U>::value && !is_number_expression<U>::value,
  2859. detail::expression<detail::function, default_ops::remquo_func, U, number<Backend, et_on>, int*>
  2860. >::type
  2861. remquo(const U& a, const number<Backend, et_on>& b, int* pi)
  2862. {
  2863. return detail::expression<detail::function, default_ops::remquo_func, U, number<Backend, et_on>, int*>(
  2864. default_ops::remquo_func(), a, b, pi);
  2865. }
  2866. template <class U, class tag, class Arg1, class Arg2, class Arg3, class Arg4>
  2867. inline typename enable_if_c<
  2868. (number_category<typename detail::expression<tag, Arg1, Arg2, Arg3, Arg4>::result_type >::value == number_kind_floating_point)
  2869. && !is_number<U>::value && !is_number_expression<U>::value,
  2870. detail::expression<detail::function, default_ops::remquo_func, U, detail::expression<tag, Arg1, Arg2, Arg3, Arg4>, int*>
  2871. >::type
  2872. remquo(const U& a, const detail::expression<tag, Arg1, Arg2, Arg3, Arg4>& b, int* pi)
  2873. {
  2874. return detail::expression<detail::function, default_ops::remquo_func, U, detail::expression<tag, Arg1, Arg2, Arg3, Arg4>, int*>(
  2875. default_ops::remquo_func(), a, b, pi);
  2876. }
  2877. template <class Backend, class U>
  2878. inline typename enable_if_c<
  2879. number_category<number<Backend, et_on> >::value == number_kind_floating_point,
  2880. number<Backend, et_off>
  2881. >::type
  2882. remquo(const number<Backend, et_off>& a, const U& b, int* pi)
  2883. {
  2884. using default_ops::eval_remquo;
  2885. detail::scoped_default_precision<multiprecision::number<Backend, et_off> > precision_guard(a, b);
  2886. number<Backend, et_off> result;
  2887. eval_remquo(result.backend(), a.backend(), number<Backend, et_off>::canonical_value(b), pi);
  2888. return BOOST_MP_MOVE(result);
  2889. }
  2890. template <class U, class Backend>
  2891. inline typename enable_if_c<
  2892. (number_category<number<Backend, et_on> >::value == number_kind_floating_point)
  2893. && !is_number<U>::value && !is_number_expression<U>::value,
  2894. number<Backend, et_off>
  2895. >::type
  2896. remquo(const U& a, const number<Backend, et_off>& b, int* pi)
  2897. {
  2898. using default_ops::eval_remquo;
  2899. detail::scoped_default_precision<multiprecision::number<Backend, et_off> > precision_guard(a, b);
  2900. number<Backend, et_off> result;
  2901. eval_remquo(result.backend(), number<Backend, et_off>::canonical_value(a), b.backend(), pi);
  2902. return BOOST_MP_MOVE(result);
  2903. }
  2904. template <class B, expression_template_option ExpressionTemplates>
  2905. inline typename enable_if_c<number_category<B>::value == number_kind_integer, number<B, ExpressionTemplates> >::type
  2906. sqrt(const number<B, ExpressionTemplates>& x, number<B, ExpressionTemplates>& r)
  2907. {
  2908. using default_ops::eval_integer_sqrt;
  2909. detail::scoped_default_precision<multiprecision::number<B, ExpressionTemplates> > precision_guard(x, r);
  2910. number<B, ExpressionTemplates> s;
  2911. eval_integer_sqrt(s.backend(), r.backend(), x.backend());
  2912. return s;
  2913. }
  2914. #define UNARY_OP_FUNCTOR(func, category)\
  2915. namespace detail{\
  2916. template <class Backend> \
  2917. struct BOOST_JOIN(category, BOOST_JOIN(func, _funct))\
  2918. {\
  2919. void operator()(Backend& result, const Backend& arg)const\
  2920. {\
  2921. using default_ops::BOOST_JOIN(eval_,func);\
  2922. BOOST_JOIN(eval_,func)(result, arg);\
  2923. }\
  2924. template <class U>\
  2925. void operator()(U& result, const Backend& arg)const\
  2926. {\
  2927. using default_ops::BOOST_JOIN(eval_,func);\
  2928. Backend temp;\
  2929. BOOST_JOIN(eval_,func)(temp, arg);\
  2930. result = temp;\
  2931. }\
  2932. };\
  2933. \
  2934. }\
  2935. \
  2936. template <class tag, class A1, class A2, class A3, class A4> \
  2937. inline typename enable_if_c<number_category<detail::expression<tag, A1, A2, A3, A4> >::value == category,\
  2938. detail::expression<\
  2939. detail::function\
  2940. , detail::BOOST_JOIN(category, BOOST_JOIN(func, _funct))<typename detail::backend_type<detail::expression<tag, A1, A2, A3, A4> >::type> \
  2941. , detail::expression<tag, A1, A2, A3, A4> > \
  2942. >::type \
  2943. func(const detail::expression<tag, A1, A2, A3, A4>& arg)\
  2944. {\
  2945. return detail::expression<\
  2946. detail::function\
  2947. , detail::BOOST_JOIN(category, BOOST_JOIN(func, _funct))<typename detail::backend_type<detail::expression<tag, A1, A2, A3, A4> >::type> \
  2948. , detail::expression<tag, A1, A2, A3, A4> \
  2949. > (\
  2950. detail::BOOST_JOIN(category, BOOST_JOIN(func, _funct))<typename detail::backend_type<detail::expression<tag, A1, A2, A3, A4> >::type>() \
  2951. , arg \
  2952. );\
  2953. }\
  2954. template <class Backend> \
  2955. inline typename enable_if_c<number_category<Backend>::value == category,\
  2956. detail::expression<\
  2957. detail::function\
  2958. , detail::BOOST_JOIN(category, BOOST_JOIN(func, _funct))<Backend> \
  2959. , number<Backend, et_on> > \
  2960. >::type \
  2961. func(const number<Backend, et_on>& arg)\
  2962. {\
  2963. return detail::expression<\
  2964. detail::function\
  2965. , detail::BOOST_JOIN(category, BOOST_JOIN(func, _funct))<Backend> \
  2966. , number<Backend, et_on> \
  2967. >(\
  2968. detail::BOOST_JOIN(category, BOOST_JOIN(func, _funct))<Backend>() \
  2969. , arg \
  2970. );\
  2971. }\
  2972. template <class Backend> \
  2973. inline typename boost::enable_if_c<\
  2974. boost::multiprecision::number_category<Backend>::value == category,\
  2975. number<Backend, et_off> >::type \
  2976. func(const number<Backend, et_off>& arg)\
  2977. {\
  2978. detail::scoped_default_precision<multiprecision::number<Backend, et_off> > precision_guard(arg);\
  2979. number<Backend, et_off> result;\
  2980. using default_ops::BOOST_JOIN(eval_,func);\
  2981. BOOST_JOIN(eval_,func)(result.backend(), arg.backend());\
  2982. return BOOST_MP_MOVE(result);\
  2983. }
  2984. #define BINARY_OP_FUNCTOR(func, category)\
  2985. namespace detail{\
  2986. template <class Backend> \
  2987. struct BOOST_JOIN(category, BOOST_JOIN(func, _funct))\
  2988. {\
  2989. void operator()(Backend& result, const Backend& arg, const Backend& a)const\
  2990. {\
  2991. using default_ops:: BOOST_JOIN(eval_,func);\
  2992. BOOST_JOIN(eval_,func)(result, arg, a);\
  2993. }\
  2994. template <class Arithmetic> \
  2995. void operator()(Backend& result, const Backend& arg, const Arithmetic& a)const\
  2996. {\
  2997. using default_ops:: BOOST_JOIN(eval_,func);\
  2998. BOOST_JOIN(eval_,func)(result, arg, number<Backend>::canonical_value(a));\
  2999. }\
  3000. template <class Arithmetic> \
  3001. void operator()(Backend& result, const Arithmetic& arg, const Backend& a)const\
  3002. {\
  3003. using default_ops:: BOOST_JOIN(eval_,func);\
  3004. BOOST_JOIN(eval_,func)(result, number<Backend>::canonical_value(arg), a);\
  3005. }\
  3006. template <class U>\
  3007. void operator()(U& result, const Backend& arg, const Backend& a)const\
  3008. {\
  3009. using default_ops:: BOOST_JOIN(eval_,func);\
  3010. Backend r;\
  3011. BOOST_JOIN(eval_,func)(r, arg, a);\
  3012. result = r;\
  3013. }\
  3014. template <class U, class Arithmetic> \
  3015. void operator()(U& result, const Backend& arg, const Arithmetic& a)const\
  3016. {\
  3017. using default_ops:: BOOST_JOIN(eval_,func);\
  3018. Backend r;\
  3019. BOOST_JOIN(eval_,func)(r, arg, number<Backend>::canonical_value(a));\
  3020. result = r;\
  3021. }\
  3022. template <class U, class Arithmetic> \
  3023. void operator()(U& result, const Arithmetic& arg, const Backend& a)const\
  3024. {\
  3025. using default_ops:: BOOST_JOIN(eval_,func);\
  3026. Backend r;\
  3027. BOOST_JOIN(eval_,func)(r, number<Backend>::canonical_value(arg), a);\
  3028. result = r;\
  3029. }\
  3030. };\
  3031. \
  3032. }\
  3033. template <class Backend> \
  3034. inline typename enable_if_c<number_category<Backend>::value == category,\
  3035. detail::expression<\
  3036. detail::function\
  3037. , detail::BOOST_JOIN(category, BOOST_JOIN(func, _funct))<Backend> \
  3038. , number<Backend, et_on> \
  3039. , number<Backend, et_on> > \
  3040. >::type \
  3041. func(const number<Backend, et_on>& arg, const number<Backend, et_on>& a)\
  3042. {\
  3043. return detail::expression<\
  3044. detail::function\
  3045. , detail::BOOST_JOIN(category, BOOST_JOIN(func, _funct))<Backend> \
  3046. , number<Backend, et_on> \
  3047. , number<Backend, et_on> \
  3048. >(\
  3049. detail::BOOST_JOIN(category, BOOST_JOIN(func, _funct))<Backend>() \
  3050. , arg,\
  3051. a\
  3052. );\
  3053. }\
  3054. template <class Backend, class tag, class A1, class A2, class A3, class A4> \
  3055. inline typename enable_if_c<\
  3056. (number_category<Backend>::value == category) && (boost::is_convertible<typename detail::expression<tag, A1, A2, A3, A4>::result_type, number<Backend, et_on> >::value),\
  3057. detail::expression<\
  3058. detail::function\
  3059. , detail::BOOST_JOIN(category, BOOST_JOIN(func, _funct))<Backend> \
  3060. , number<Backend, et_on> \
  3061. , detail::expression<tag, A1, A2, A3, A4> > \
  3062. >::type \
  3063. func(const number<Backend, et_on>& arg, const detail::expression<tag, A1, A2, A3, A4>& a)\
  3064. {\
  3065. return detail::expression<\
  3066. detail::function\
  3067. , detail::BOOST_JOIN(category, BOOST_JOIN(func, _funct))<Backend> \
  3068. , number<Backend, et_on> \
  3069. , detail::expression<tag, A1, A2, A3, A4> \
  3070. >(\
  3071. detail::BOOST_JOIN(category, BOOST_JOIN(func, _funct))<Backend>() \
  3072. , arg,\
  3073. a\
  3074. );\
  3075. }\
  3076. template <class tag, class A1, class A2, class A3, class A4, class Backend> \
  3077. inline typename enable_if_c<\
  3078. (number_category<Backend>::value == category) && (boost::is_convertible<typename detail::expression<tag, A1, A2, A3, A4>::result_type, number<Backend, et_on> >::value),\
  3079. detail::expression<\
  3080. detail::function\
  3081. , detail::BOOST_JOIN(category, BOOST_JOIN(func, _funct))<Backend> \
  3082. , detail::expression<tag, A1, A2, A3, A4> \
  3083. , number<Backend, et_on> > \
  3084. >::type \
  3085. func(const detail::expression<tag, A1, A2, A3, A4>& arg, const number<Backend, et_on>& a)\
  3086. {\
  3087. return detail::expression<\
  3088. detail::function\
  3089. , detail::BOOST_JOIN(category, BOOST_JOIN(func, _funct))<Backend> \
  3090. , detail::expression<tag, A1, A2, A3, A4> \
  3091. , number<Backend, et_on> \
  3092. >(\
  3093. detail::BOOST_JOIN(category, BOOST_JOIN(func, _funct))<Backend>() \
  3094. , arg,\
  3095. a\
  3096. );\
  3097. }\
  3098. template <class tag, class A1, class A2, class A3, class A4, class tagb, class A1b, class A2b, class A3b, class A4b> \
  3099. inline typename enable_if_c<\
  3100. (number_category<detail::expression<tag, A1, A2, A3, A4> >::value == category) && (number_category<detail::expression<tagb, A1b, A2b, A3b, A4b> >::value == category),\
  3101. detail::expression<\
  3102. detail::function\
  3103. , detail::BOOST_JOIN(category, BOOST_JOIN(func, _funct))<typename detail::backend_type<detail::expression<tag, A1, A2, A3, A4> >::type> \
  3104. , detail::expression<tag, A1, A2, A3, A4> \
  3105. , detail::expression<tagb, A1b, A2b, A3b, A4b> > \
  3106. >::type \
  3107. func(const detail::expression<tag, A1, A2, A3, A4>& arg, const detail::expression<tagb, A1b, A2b, A3b, A4b>& a)\
  3108. {\
  3109. return detail::expression<\
  3110. detail::function\
  3111. , detail::BOOST_JOIN(category, BOOST_JOIN(func, _funct))<typename detail::backend_type<detail::expression<tag, A1, A2, A3, A4> >::type> \
  3112. , detail::expression<tag, A1, A2, A3, A4> \
  3113. , detail::expression<tagb, A1b, A2b, A3b, A4b> \
  3114. >(\
  3115. detail::BOOST_JOIN(category, BOOST_JOIN(func, _funct))<typename detail::backend_type<detail::expression<tag, A1, A2, A3, A4> >::type>() \
  3116. , arg,\
  3117. a\
  3118. );\
  3119. }\
  3120. template <class Backend, class Arithmetic> \
  3121. inline typename enable_if_c<\
  3122. is_compatible_arithmetic_type<Arithmetic, number<Backend, et_on> >::value && (number_category<Backend>::value == category),\
  3123. detail::expression<\
  3124. detail::function\
  3125. , detail::BOOST_JOIN(category, BOOST_JOIN(func, _funct))<Backend> \
  3126. , number<Backend, et_on> \
  3127. , Arithmetic\
  3128. > \
  3129. >::type \
  3130. func(const number<Backend, et_on>& arg, const Arithmetic& a)\
  3131. {\
  3132. return detail::expression<\
  3133. detail::function\
  3134. , detail::BOOST_JOIN(category, BOOST_JOIN(func, _funct))<Backend> \
  3135. , number<Backend, et_on> \
  3136. , Arithmetic\
  3137. >(\
  3138. detail::BOOST_JOIN(category, BOOST_JOIN(func, _funct))<Backend>() \
  3139. , arg,\
  3140. a\
  3141. );\
  3142. }\
  3143. template <class tag, class A1, class A2, class A3, class A4, class Arithmetic> \
  3144. inline typename enable_if_c<\
  3145. is_compatible_arithmetic_type<Arithmetic, typename detail::expression<tag, A1, A2, A3, A4>::result_type>::value && (number_category<detail::expression<tag, A1, A2, A3, A4> >::value == category),\
  3146. detail::expression<\
  3147. detail::function\
  3148. , detail::BOOST_JOIN(category, BOOST_JOIN(func, _funct))<typename detail::backend_type<detail::expression<tag, A1, A2, A3, A4> >::type> \
  3149. , detail::expression<tag, A1, A2, A3, A4> \
  3150. , Arithmetic\
  3151. > \
  3152. >::type \
  3153. func(const detail::expression<tag, A1, A2, A3, A4>& arg, const Arithmetic& a)\
  3154. {\
  3155. return detail::expression<\
  3156. detail::function\
  3157. , detail::BOOST_JOIN(category, BOOST_JOIN(func, _funct))<typename detail::backend_type<detail::expression<tag, A1, A2, A3, A4> >::type> \
  3158. , detail::expression<tag, A1, A2, A3, A4> \
  3159. , Arithmetic\
  3160. >(\
  3161. detail::BOOST_JOIN(category, BOOST_JOIN(func, _funct))<typename detail::backend_type<detail::expression<tag, A1, A2, A3, A4> >::type>() \
  3162. , arg,\
  3163. a\
  3164. );\
  3165. }\
  3166. template <class Backend, class Arithmetic> \
  3167. inline typename enable_if_c<\
  3168. is_compatible_arithmetic_type<Arithmetic, number<Backend, et_on> >::value && (number_category<Backend>::value == category),\
  3169. detail::expression<\
  3170. detail::function\
  3171. , detail::BOOST_JOIN(category, BOOST_JOIN(func, _funct))<Backend> \
  3172. , Arithmetic \
  3173. , number<Backend, et_on> \
  3174. > \
  3175. >::type \
  3176. func(const Arithmetic& arg, const number<Backend, et_on>& a)\
  3177. {\
  3178. return detail::expression<\
  3179. detail::function\
  3180. , detail::BOOST_JOIN(category, BOOST_JOIN(func, _funct))<Backend> \
  3181. , Arithmetic \
  3182. , number<Backend, et_on> \
  3183. >(\
  3184. detail::BOOST_JOIN(category, BOOST_JOIN(func, _funct))<Backend>() \
  3185. , arg,\
  3186. a\
  3187. );\
  3188. }\
  3189. template <class tag, class A1, class A2, class A3, class A4, class Arithmetic> \
  3190. inline typename enable_if_c<\
  3191. is_compatible_arithmetic_type<Arithmetic, typename detail::expression<tag, A1, A2, A3, A4>::result_type>::value && (number_category<detail::expression<tag, A1, A2, A3, A4> >::value == category),\
  3192. detail::expression<\
  3193. detail::function\
  3194. , detail::BOOST_JOIN(category, BOOST_JOIN(func, _funct))<typename detail::backend_type<detail::expression<tag, A1, A2, A3, A4> >::type> \
  3195. , Arithmetic \
  3196. , detail::expression<tag, A1, A2, A3, A4> \
  3197. > \
  3198. >::type \
  3199. func(const Arithmetic& arg, const detail::expression<tag, A1, A2, A3, A4>& a)\
  3200. {\
  3201. return detail::expression<\
  3202. detail::function\
  3203. , detail::BOOST_JOIN(category, BOOST_JOIN(func, _funct))<typename detail::backend_type<detail::expression<tag, A1, A2, A3, A4> >::type> \
  3204. , Arithmetic \
  3205. , detail::expression<tag, A1, A2, A3, A4> \
  3206. >(\
  3207. detail::BOOST_JOIN(category, BOOST_JOIN(func, _funct))<typename detail::backend_type<detail::expression<tag, A1, A2, A3, A4> >::type>() \
  3208. , arg,\
  3209. a\
  3210. );\
  3211. }\
  3212. template <class Backend> \
  3213. inline typename enable_if_c<(number_category<Backend>::value == category),\
  3214. number<Backend, et_off> >::type \
  3215. func(const number<Backend, et_off>& arg, const number<Backend, et_off>& a)\
  3216. {\
  3217. detail::scoped_default_precision<multiprecision::number<Backend, et_off> > precision_guard(arg, a);\
  3218. number<Backend, et_off> result;\
  3219. using default_ops:: BOOST_JOIN(eval_,func);\
  3220. BOOST_JOIN(eval_,func)(result.backend(), arg.backend(), a.backend());\
  3221. return BOOST_MP_MOVE(result);\
  3222. }\
  3223. template <class Backend, class Arithmetic> \
  3224. inline typename enable_if_c<\
  3225. is_compatible_arithmetic_type<Arithmetic, number<Backend, et_off> >::value && (number_category<Backend>::value == category),\
  3226. number<Backend, et_off> \
  3227. >::type \
  3228. func(const number<Backend, et_off>& arg, const Arithmetic& a)\
  3229. {\
  3230. detail::scoped_default_precision<multiprecision::number<Backend, et_off> > precision_guard(arg);\
  3231. number<Backend, et_off> result;\
  3232. using default_ops:: BOOST_JOIN(eval_,func);\
  3233. BOOST_JOIN(eval_,func)(result.backend(), arg.backend(), number<Backend, et_off>::canonical_value(a));\
  3234. return BOOST_MP_MOVE(result);\
  3235. }\
  3236. template <class Backend, class Arithmetic> \
  3237. inline typename enable_if_c<\
  3238. is_compatible_arithmetic_type<Arithmetic, number<Backend, et_off> >::value && (number_category<Backend>::value == category),\
  3239. number<Backend, et_off> \
  3240. >::type \
  3241. func(const Arithmetic& a, const number<Backend, et_off>& arg)\
  3242. {\
  3243. detail::scoped_default_precision<multiprecision::number<Backend, et_off> > precision_guard(arg);\
  3244. number<Backend, et_off> result;\
  3245. using default_ops:: BOOST_JOIN(eval_,func);\
  3246. BOOST_JOIN(eval_,func)(result.backend(), number<Backend, et_off>::canonical_value(a), arg.backend());\
  3247. return BOOST_MP_MOVE(result);\
  3248. }\
  3249. #define HETERO_BINARY_OP_FUNCTOR_B(func, Arg2, category)\
  3250. template <class tag, class A1, class A2, class A3, class A4> \
  3251. inline typename enable_if_c<\
  3252. (number_category<detail::expression<tag, A1, A2, A3, A4> >::value == category),\
  3253. detail::expression<\
  3254. detail::function\
  3255. , detail::BOOST_JOIN(category, BOOST_JOIN(func, _funct))<typename detail::backend_type<detail::expression<tag, A1, A2, A3, A4> >::type> \
  3256. , detail::expression<tag, A1, A2, A3, A4> \
  3257. , Arg2> \
  3258. >::type \
  3259. func(const detail::expression<tag, A1, A2, A3, A4>& arg, Arg2 const& a)\
  3260. {\
  3261. return detail::expression<\
  3262. detail::function\
  3263. , detail::BOOST_JOIN(category, BOOST_JOIN(func, _funct))<typename detail::backend_type<detail::expression<tag, A1, A2, A3, A4> >::type> \
  3264. , detail::expression<tag, A1, A2, A3, A4> \
  3265. , Arg2\
  3266. >(\
  3267. detail::BOOST_JOIN(category, BOOST_JOIN(func, _funct))<typename detail::backend_type<detail::expression<tag, A1, A2, A3, A4> >::type>() \
  3268. , arg, a \
  3269. );\
  3270. }\
  3271. template <class Backend> \
  3272. inline typename enable_if_c<\
  3273. (number_category<Backend>::value == category),\
  3274. detail::expression<\
  3275. detail::function\
  3276. , detail::BOOST_JOIN(category, BOOST_JOIN(func, _funct))<Backend> \
  3277. , number<Backend, et_on> \
  3278. , Arg2> \
  3279. >::type \
  3280. func(const number<Backend, et_on>& arg, Arg2 const& a)\
  3281. {\
  3282. return detail::expression<\
  3283. detail::function\
  3284. , detail::BOOST_JOIN(category, BOOST_JOIN(func, _funct))<Backend> \
  3285. , number<Backend, et_on> \
  3286. , Arg2\
  3287. >(\
  3288. detail::BOOST_JOIN(category, BOOST_JOIN(func, _funct))<Backend>() \
  3289. , arg,\
  3290. a\
  3291. );\
  3292. }\
  3293. template <class Backend> \
  3294. inline typename enable_if_c<\
  3295. (number_category<Backend>::value == category),\
  3296. number<Backend, et_off> >::type \
  3297. func(const number<Backend, et_off>& arg, Arg2 const& a)\
  3298. {\
  3299. detail::scoped_default_precision<multiprecision::number<Backend, et_off> > precision_guard(arg, a);\
  3300. number<Backend, et_off> result;\
  3301. using default_ops:: BOOST_JOIN(eval_,func);\
  3302. BOOST_JOIN(eval_,func)(result.backend(), arg.backend(), a);\
  3303. return BOOST_MP_MOVE(result);\
  3304. }\
  3305. #define HETERO_BINARY_OP_FUNCTOR(func, Arg2, category)\
  3306. namespace detail{\
  3307. template <class Backend> \
  3308. struct BOOST_JOIN(category, BOOST_JOIN(func, _funct))\
  3309. {\
  3310. template <class Arg>\
  3311. void operator()(Backend& result, Backend const& arg, Arg a)const\
  3312. {\
  3313. using default_ops:: BOOST_JOIN(eval_,func);\
  3314. BOOST_JOIN(eval_,func)(result, arg, a);\
  3315. }\
  3316. };\
  3317. \
  3318. }\
  3319. \
  3320. HETERO_BINARY_OP_FUNCTOR_B(func, Arg2, category)
  3321. namespace detail{
  3322. template <class Backend>
  3323. struct abs_funct
  3324. {
  3325. void operator()(Backend& result, const Backend& arg)const
  3326. {
  3327. using default_ops::eval_abs;
  3328. eval_abs(result, arg);
  3329. }
  3330. };
  3331. template <class Backend>
  3332. struct conj_funct
  3333. {
  3334. void operator()(Backend& result, const Backend& arg)const
  3335. {
  3336. using default_ops::eval_conj;
  3337. eval_conj(result, arg);
  3338. }
  3339. };
  3340. template <class Backend>
  3341. struct proj_funct
  3342. {
  3343. void operator()(Backend& result, const Backend& arg)const
  3344. {
  3345. using default_ops::eval_proj;
  3346. eval_proj(result, arg);
  3347. }
  3348. };
  3349. }
  3350. template <class tag, class A1, class A2, class A3, class A4>
  3351. inline typename boost::disable_if_c<number_category<typename detail::expression<tag, A1, A2, A3, A4>::result_type>::value == number_kind_complex,
  3352. detail::expression<
  3353. detail::function
  3354. , detail::abs_funct<typename detail::backend_type<detail::expression<tag, A1, A2, A3, A4> >::type>
  3355. , detail::expression<tag, A1, A2, A3, A4> > >::type
  3356. abs(const detail::expression<tag, A1, A2, A3, A4>& arg)
  3357. {
  3358. return detail::expression<
  3359. detail::function
  3360. , detail::abs_funct<typename detail::backend_type<detail::expression<tag, A1, A2, A3, A4> >::type>
  3361. , detail::expression<tag, A1, A2, A3, A4>
  3362. > (
  3363. detail::abs_funct<typename detail::backend_type<detail::expression<tag, A1, A2, A3, A4> >::type>()
  3364. , arg
  3365. );
  3366. }
  3367. template <class Backend>
  3368. inline typename disable_if_c<number_category<Backend>::value == number_kind_complex,
  3369. detail::expression<
  3370. detail::function
  3371. , detail::abs_funct<Backend>
  3372. , number<Backend, et_on> > >::type
  3373. abs(const number<Backend, et_on>& arg)
  3374. {
  3375. return detail::expression<
  3376. detail::function
  3377. , detail::abs_funct<Backend>
  3378. , number<Backend, et_on>
  3379. >(
  3380. detail::abs_funct<Backend>()
  3381. , arg
  3382. );
  3383. }
  3384. template <class Backend>
  3385. inline typename disable_if_c<number_category<Backend>::value == number_kind_complex, number<Backend, et_off> >::type
  3386. abs(const number<Backend, et_off>& arg)
  3387. {
  3388. detail::scoped_default_precision<multiprecision::number<Backend, et_off> > precision_guard(arg);
  3389. number<Backend, et_off> result;
  3390. using default_ops::eval_abs;
  3391. eval_abs(result.backend(), arg.backend());
  3392. return BOOST_MP_MOVE(result);
  3393. }
  3394. template <class tag, class A1, class A2, class A3, class A4>
  3395. inline detail::expression<
  3396. detail::function
  3397. , detail::conj_funct<typename detail::backend_type<detail::expression<tag, A1, A2, A3, A4> >::type>
  3398. , detail::expression<tag, A1, A2, A3, A4> >
  3399. conj(const detail::expression<tag, A1, A2, A3, A4>& arg)
  3400. {
  3401. return detail::expression<
  3402. detail::function
  3403. , detail::conj_funct<typename detail::backend_type<detail::expression<tag, A1, A2, A3, A4> >::type>
  3404. , detail::expression<tag, A1, A2, A3, A4>
  3405. > (
  3406. detail::conj_funct<typename detail::backend_type<detail::expression<tag, A1, A2, A3, A4> >::type>()
  3407. , arg
  3408. );
  3409. }
  3410. template <class Backend>
  3411. inline detail::expression<
  3412. detail::function
  3413. , detail::conj_funct<Backend>
  3414. , number<Backend, et_on> >
  3415. conj(const number<Backend, et_on>& arg)
  3416. {
  3417. return detail::expression<
  3418. detail::function
  3419. , detail::conj_funct<Backend>
  3420. , number<Backend, et_on>
  3421. >(
  3422. detail::conj_funct<Backend>()
  3423. , arg
  3424. );
  3425. }
  3426. template <class Backend>
  3427. inline number<Backend, et_off>
  3428. conj(const number<Backend, et_off>& arg)
  3429. {
  3430. detail::scoped_default_precision<multiprecision::number<Backend, et_off> > precision_guard(arg);
  3431. number<Backend, et_off> result;
  3432. using default_ops::eval_conj;
  3433. eval_conj(result.backend(), arg.backend());
  3434. return BOOST_MP_MOVE(result);
  3435. }
  3436. template <class tag, class A1, class A2, class A3, class A4>
  3437. inline detail::expression<
  3438. detail::function
  3439. , detail::proj_funct<typename detail::backend_type<detail::expression<tag, A1, A2, A3, A4> >::type>
  3440. , detail::expression<tag, A1, A2, A3, A4> >
  3441. proj(const detail::expression<tag, A1, A2, A3, A4>& arg)
  3442. {
  3443. return detail::expression<
  3444. detail::function
  3445. , detail::proj_funct<typename detail::backend_type<detail::expression<tag, A1, A2, A3, A4> >::type>
  3446. , detail::expression<tag, A1, A2, A3, A4>
  3447. > (
  3448. detail::proj_funct<typename detail::backend_type<detail::expression<tag, A1, A2, A3, A4> >::type>()
  3449. , arg
  3450. );
  3451. }
  3452. template <class Backend>
  3453. inline detail::expression<
  3454. detail::function
  3455. , detail::proj_funct<Backend>
  3456. , number<Backend, et_on> >
  3457. proj(const number<Backend, et_on>& arg)
  3458. {
  3459. return detail::expression<
  3460. detail::function
  3461. , detail::proj_funct<Backend>
  3462. , number<Backend, et_on>
  3463. >(
  3464. detail::proj_funct<Backend>()
  3465. , arg
  3466. );
  3467. }
  3468. template <class Backend>
  3469. inline number<Backend, et_off>
  3470. proj(const number<Backend, et_off>& arg)
  3471. {
  3472. detail::scoped_default_precision<multiprecision::number<Backend, et_off> > precision_guard(arg);
  3473. number<Backend, et_off> result;
  3474. using default_ops::eval_proj;
  3475. eval_proj(result.backend(), arg.backend());
  3476. return BOOST_MP_MOVE(result);
  3477. }
  3478. UNARY_OP_FUNCTOR(fabs, number_kind_floating_point)
  3479. UNARY_OP_FUNCTOR(sqrt, number_kind_floating_point)
  3480. UNARY_OP_FUNCTOR(floor, number_kind_floating_point)
  3481. UNARY_OP_FUNCTOR(ceil, number_kind_floating_point)
  3482. UNARY_OP_FUNCTOR(trunc, number_kind_floating_point)
  3483. UNARY_OP_FUNCTOR(round, number_kind_floating_point)
  3484. UNARY_OP_FUNCTOR(exp, number_kind_floating_point)
  3485. UNARY_OP_FUNCTOR(exp2, number_kind_floating_point)
  3486. UNARY_OP_FUNCTOR(log, number_kind_floating_point)
  3487. UNARY_OP_FUNCTOR(log10, number_kind_floating_point)
  3488. UNARY_OP_FUNCTOR(cos, number_kind_floating_point)
  3489. UNARY_OP_FUNCTOR(sin, number_kind_floating_point)
  3490. UNARY_OP_FUNCTOR(tan, number_kind_floating_point)
  3491. UNARY_OP_FUNCTOR(asin, number_kind_floating_point)
  3492. UNARY_OP_FUNCTOR(acos, number_kind_floating_point)
  3493. UNARY_OP_FUNCTOR(atan, number_kind_floating_point)
  3494. UNARY_OP_FUNCTOR(cosh, number_kind_floating_point)
  3495. UNARY_OP_FUNCTOR(sinh, number_kind_floating_point)
  3496. UNARY_OP_FUNCTOR(tanh, number_kind_floating_point)
  3497. UNARY_OP_FUNCTOR(log2, number_kind_floating_point)
  3498. UNARY_OP_FUNCTOR(nearbyint, number_kind_floating_point)
  3499. UNARY_OP_FUNCTOR(rint, number_kind_floating_point)
  3500. HETERO_BINARY_OP_FUNCTOR(ldexp, short, number_kind_floating_point)
  3501. //HETERO_BINARY_OP_FUNCTOR(frexp, short*, number_kind_floating_point)
  3502. HETERO_BINARY_OP_FUNCTOR_B(ldexp, int, number_kind_floating_point)
  3503. //HETERO_BINARY_OP_FUNCTOR_B(frexp, int*, number_kind_floating_point)
  3504. HETERO_BINARY_OP_FUNCTOR_B(ldexp, long, number_kind_floating_point)
  3505. //HETERO_BINARY_OP_FUNCTOR_B(frexp, long*, number_kind_floating_point)
  3506. HETERO_BINARY_OP_FUNCTOR_B(ldexp, boost::long_long_type, number_kind_floating_point)
  3507. //HETERO_BINARY_OP_FUNCTOR_B(frexp, boost::long_long_type*, number_kind_floating_point)
  3508. BINARY_OP_FUNCTOR(pow, number_kind_floating_point)
  3509. BINARY_OP_FUNCTOR(fmod, number_kind_floating_point)
  3510. BINARY_OP_FUNCTOR(fmax, number_kind_floating_point)
  3511. BINARY_OP_FUNCTOR(fmin, number_kind_floating_point)
  3512. BINARY_OP_FUNCTOR(atan2, number_kind_floating_point)
  3513. BINARY_OP_FUNCTOR(fdim, number_kind_floating_point)
  3514. BINARY_OP_FUNCTOR(hypot, number_kind_floating_point)
  3515. BINARY_OP_FUNCTOR(remainder, number_kind_floating_point)
  3516. UNARY_OP_FUNCTOR(logb, number_kind_floating_point)
  3517. HETERO_BINARY_OP_FUNCTOR(scalbn, short, number_kind_floating_point)
  3518. HETERO_BINARY_OP_FUNCTOR(scalbln, short, number_kind_floating_point)
  3519. HETERO_BINARY_OP_FUNCTOR_B(scalbn, int, number_kind_floating_point)
  3520. HETERO_BINARY_OP_FUNCTOR_B(scalbln, int, number_kind_floating_point)
  3521. HETERO_BINARY_OP_FUNCTOR_B(scalbn, long, number_kind_floating_point)
  3522. HETERO_BINARY_OP_FUNCTOR_B(scalbln, long, number_kind_floating_point)
  3523. HETERO_BINARY_OP_FUNCTOR_B(scalbn, boost::long_long_type, number_kind_floating_point)
  3524. HETERO_BINARY_OP_FUNCTOR_B(scalbln, boost::long_long_type, number_kind_floating_point)
  3525. //
  3526. // Complex functions:
  3527. //
  3528. UNARY_OP_FUNCTOR(exp, number_kind_complex)
  3529. UNARY_OP_FUNCTOR(log, number_kind_complex)
  3530. UNARY_OP_FUNCTOR(log10, number_kind_complex)
  3531. BINARY_OP_FUNCTOR(pow, number_kind_complex)
  3532. UNARY_OP_FUNCTOR(sqrt, number_kind_complex)
  3533. UNARY_OP_FUNCTOR(sin, number_kind_complex)
  3534. UNARY_OP_FUNCTOR(cos, number_kind_complex)
  3535. UNARY_OP_FUNCTOR(tan, number_kind_complex)
  3536. UNARY_OP_FUNCTOR(asin, number_kind_complex)
  3537. UNARY_OP_FUNCTOR(acos, number_kind_complex)
  3538. UNARY_OP_FUNCTOR(atan, number_kind_complex)
  3539. UNARY_OP_FUNCTOR(sinh, number_kind_complex)
  3540. UNARY_OP_FUNCTOR(cosh, number_kind_complex)
  3541. UNARY_OP_FUNCTOR(tanh, number_kind_complex)
  3542. UNARY_OP_FUNCTOR(asinh, number_kind_complex)
  3543. UNARY_OP_FUNCTOR(acosh, number_kind_complex)
  3544. UNARY_OP_FUNCTOR(atanh, number_kind_complex)
  3545. //
  3546. // Integer functions:
  3547. //
  3548. BINARY_OP_FUNCTOR(gcd, number_kind_integer)
  3549. BINARY_OP_FUNCTOR(lcm, number_kind_integer)
  3550. HETERO_BINARY_OP_FUNCTOR(pow, unsigned, number_kind_integer)
  3551. #undef BINARY_OP_FUNCTOR
  3552. #undef UNARY_OP_FUNCTOR
  3553. //
  3554. // ilogb:
  3555. //
  3556. template <class Backend, multiprecision::expression_template_option ExpressionTemplates>
  3557. inline typename enable_if_c<number_category<Backend>::value == number_kind_floating_point, typename Backend::exponent_type>::type
  3558. ilogb(const multiprecision::number<Backend, ExpressionTemplates>& val)
  3559. {
  3560. using default_ops::eval_ilogb;
  3561. return eval_ilogb(val.backend());
  3562. }
  3563. template <class tag, class A1, class A2, class A3, class A4>
  3564. inline typename enable_if_c<number_category<detail::expression<tag, A1, A2, A3, A4> >::value == number_kind_floating_point, typename multiprecision::detail::expression<tag, A1, A2, A3, A4>::result_type::backend_type::exponent_type>::type
  3565. ilogb(const detail::expression<tag, A1, A2, A3, A4>& val)
  3566. {
  3567. using default_ops::eval_ilogb;
  3568. typename multiprecision::detail::expression<tag, A1, A2, A3, A4>::result_type arg(val);
  3569. return eval_ilogb(arg.backend());
  3570. }
  3571. } //namespace multiprecision
  3572. namespace math{
  3573. //
  3574. // Overload of Boost.Math functions that find the wrong overload when used with number:
  3575. //
  3576. namespace detail{
  3577. template <class T> T sinc_pi_imp(T);
  3578. template <class T> T sinhc_pi_imp(T);
  3579. }
  3580. template <class Backend, multiprecision::expression_template_option ExpressionTemplates>
  3581. inline multiprecision::number<Backend, ExpressionTemplates> sinc_pi(const multiprecision::number<Backend, ExpressionTemplates>& x)
  3582. {
  3583. boost::multiprecision::detail::scoped_default_precision<multiprecision::number<Backend, ExpressionTemplates> > precision_guard(x);
  3584. return BOOST_MP_MOVE(detail::sinc_pi_imp(x));
  3585. }
  3586. template <class Backend, multiprecision::expression_template_option ExpressionTemplates, class Policy>
  3587. inline multiprecision::number<Backend, ExpressionTemplates> sinc_pi(const multiprecision::number<Backend, ExpressionTemplates>& x, const Policy&)
  3588. {
  3589. boost::multiprecision::detail::scoped_default_precision<multiprecision::number<Backend, ExpressionTemplates> > precision_guard(x);
  3590. return BOOST_MP_MOVE(detail::sinc_pi_imp(x));
  3591. }
  3592. template <class Backend, multiprecision::expression_template_option ExpressionTemplates>
  3593. inline multiprecision::number<Backend, ExpressionTemplates> sinhc_pi(const multiprecision::number<Backend, ExpressionTemplates>& x)
  3594. {
  3595. boost::multiprecision::detail::scoped_default_precision<multiprecision::number<Backend, ExpressionTemplates> > precision_guard(x);
  3596. return BOOST_MP_MOVE(detail::sinhc_pi_imp(x));
  3597. }
  3598. template <class Backend, multiprecision::expression_template_option ExpressionTemplates, class Policy>
  3599. inline multiprecision::number<Backend, ExpressionTemplates> sinhc_pi(const multiprecision::number<Backend, ExpressionTemplates>& x, const Policy&)
  3600. {
  3601. boost::multiprecision::detail::scoped_default_precision<multiprecision::number<Backend, ExpressionTemplates> > precision_guard(x);
  3602. return BOOST_MP_MOVE(boost::math::sinhc_pi(x));
  3603. }
  3604. using boost::multiprecision::gcd;
  3605. using boost::multiprecision::lcm;
  3606. #ifdef BOOST_MSVC
  3607. #pragma warning(pop)
  3608. #endif
  3609. } // namespace math
  3610. namespace integer {
  3611. using boost::multiprecision::gcd;
  3612. using boost::multiprecision::lcm;
  3613. }
  3614. } // namespace boost
  3615. //
  3616. // This has to come last of all:
  3617. //
  3618. #include <boost/multiprecision/detail/no_et_ops.hpp>
  3619. #include <boost/multiprecision/detail/et_ops.hpp>
  3620. //
  3621. // min/max overloads:
  3622. //
  3623. #include <boost/multiprecision/detail/min_max.hpp>
  3624. #endif