1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200 |
- ///////////////////////////////////////////////////////////////////////////////
- // Copyright 2011 John Maddock. Distributed under the Boost
- // Software License, Version 1.0. (See accompanying file
- // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
- #ifndef BOOST_MATH_BIG_NUM_DEF_OPS
- #define BOOST_MATH_BIG_NUM_DEF_OPS
- #include <boost/math/policies/error_handling.hpp>
- #include <boost/multiprecision/detail/number_base.hpp>
- #include <boost/math/special_functions/fpclassify.hpp>
- #include <boost/utility/enable_if.hpp>
- #include <boost/mpl/front.hpp>
- #include <boost/mpl/fold.hpp>
- #include <boost/cstdint.hpp>
- #include <boost/type_traits/make_unsigned.hpp>
- #ifndef INSTRUMENT_BACKEND
- #ifndef BOOST_MP_INSTRUMENT
- #define INSTRUMENT_BACKEND(x)
- #else
- #define INSTRUMENT_BACKEND(x)\
- std::cout << BOOST_STRINGIZE(x) << " = " << x.str(0, std::ios_base::scientific) << std::endl;
- #endif
- #endif
- namespace boost{ namespace multiprecision{ namespace default_ops{
- #ifdef BOOST_MSVC
- // warning C4127: conditional expression is constant
- #pragma warning(push)
- #pragma warning(disable:4127)
- #endif
- //
- // Default versions of mixed arithmetic, these just construct a temporary
- // from the arithmetic value and then do the arithmetic on that, two versions
- // of each depending on whether the backend can be directly constructed from type V.
- //
- // Note that we have to provide *all* the template parameters to class number when used in
- // enable_if as MSVC-10 won't compile the code if we rely on a computed-default parameter.
- // Since the result of the test doesn't depend on whether expression templates are on or off
- // we just use et_on everywhere. We could use a BOOST_WORKAROUND but that just obfuscates the
- // code even more....
- //
- template <class T, class V>
- inline typename enable_if_c<is_convertible<V, number<T, et_on> >::value && !is_convertible<V, T>::value >::type
- eval_add(T& result, V const& v)
- {
- T t;
- t = v;
- eval_add(result, t);
- }
- template <class T, class V>
- inline typename enable_if_c<is_convertible<V, number<T, et_on> >::value && is_convertible<V, T>::value >::type
- eval_add(T& result, V const& v)
- {
- T t(v);
- eval_add(result, t);
- }
- template <class T, class V>
- inline typename enable_if_c<is_convertible<V, number<T, et_on> >::value && !is_convertible<V, T>::value>::type
- eval_subtract(T& result, V const& v)
- {
- T t;
- t = v;
- eval_subtract(result, t);
- }
- template <class T, class V>
- inline typename enable_if_c<is_convertible<V, number<T, et_on> >::value && is_convertible<V, T>::value>::type
- eval_subtract(T& result, V const& v)
- {
- T t(v);
- eval_subtract(result, t);
- }
- template <class T, class V>
- inline typename enable_if_c<is_convertible<V, number<T, et_on> >::value && !is_convertible<V, T>::value>::type
- eval_multiply(T& result, V const& v)
- {
- T t;
- t = v;
- eval_multiply(result, t);
- }
- template <class T, class V>
- inline typename enable_if_c<is_convertible<V, number<T, et_on> >::value && is_convertible<V, T>::value>::type
- eval_multiply(T& result, V const& v)
- {
- T t(v);
- eval_multiply(result, t);
- }
- template <class T, class U, class V>
- void eval_multiply(T& t, const U& u, const V& v);
- template <class T, class U, class V>
- 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)
- {
- T z;
- eval_multiply(z, u, v);
- eval_add(t, z);
- }
- template <class T, class U, class V>
- 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)
- {
- eval_multiply_add(t, v, u);
- }
- template <class T, class U, class V>
- 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)
- {
- T z;
- eval_multiply(z, u, v);
- eval_subtract(t, z);
- }
- template <class T, class U, class V>
- 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)
- {
- eval_multiply_subtract(t, v, u);
- }
- template <class T, class V>
- inline typename enable_if_c<is_convertible<V, number<T, et_on> >::value && !is_convertible<V, T>::value>::type
- eval_divide(T& result, V const& v)
- {
- T t;
- t = v;
- eval_divide(result, t);
- }
- template <class T, class V>
- inline typename enable_if_c<is_convertible<V, number<T, et_on> >::value && is_convertible<V, T>::value>::type
- eval_divide(T& result, V const& v)
- {
- T t(v);
- eval_divide(result, t);
- }
- template <class T, class V>
- inline typename enable_if_c<is_convertible<V, number<T, et_on> >::value && !is_convertible<V, T>::value>::type
- eval_modulus(T& result, V const& v)
- {
- T t;
- t = v;
- eval_modulus(result, t);
- }
- template <class T, class V>
- inline typename enable_if_c<is_convertible<V, number<T, et_on> >::value&& is_convertible<V, T>::value>::type
- eval_modulus(T& result, V const& v)
- {
- T t(v);
- eval_modulus(result, t);
- }
- template <class T, class V>
- inline typename enable_if_c<is_convertible<V, number<T, et_on> >::value && !is_convertible<V, T>::value>::type
- eval_bitwise_and(T& result, V const& v)
- {
- T t;
- t = v;
- eval_bitwise_and(result, t);
- }
- template <class T, class V>
- inline typename enable_if_c<is_convertible<V, number<T, et_on> >::value && is_convertible<V, T>::value>::type
- eval_bitwise_and(T& result, V const& v)
- {
- T t(v);
- eval_bitwise_and(result, t);
- }
- template <class T, class V>
- inline typename enable_if_c<is_convertible<V, number<T, et_on> >::value && !is_convertible<V, T>::value>::type
- eval_bitwise_or(T& result, V const& v)
- {
- T t;
- t = v;
- eval_bitwise_or(result, t);
- }
- template <class T, class V>
- inline typename enable_if_c<is_convertible<V, number<T, et_on> >::value && is_convertible<V, T>::value>::type
- eval_bitwise_or(T& result, V const& v)
- {
- T t(v);
- eval_bitwise_or(result, t);
- }
- template <class T, class V>
- inline typename enable_if_c<is_convertible<V, number<T, et_on> >::value && !is_convertible<V, T>::value>::type
- eval_bitwise_xor(T& result, V const& v)
- {
- T t;
- t = v;
- eval_bitwise_xor(result, t);
- }
- template <class T, class V>
- inline typename enable_if_c<is_convertible<V, number<T, et_on> >::value && is_convertible<V, T>::value>::type
- eval_bitwise_xor(T& result, V const& v)
- {
- T t(v);
- eval_bitwise_xor(result, t);
- }
- template <class T, class V>
- inline typename enable_if_c<is_convertible<V, number<T, et_on> >::value && !is_convertible<V, T>::value>::type
- eval_complement(T& result, V const& v)
- {
- T t;
- t = v;
- eval_complement(result, t);
- }
- template <class T, class V>
- inline typename enable_if_c<is_convertible<V, number<T, et_on> >::value && is_convertible<V, T>::value>::type
- eval_complement(T& result, V const& v)
- {
- T t(v);
- eval_complement(result, t);
- }
- //
- // Default versions of 3-arg arithmetic functions, these mostly just forward to the 2 arg versions:
- //
- template <class T, class U, class V>
- void eval_add(T& t, const U& u, const V& v);
- template <class T>
- inline void eval_add_default(T& t, const T& u, const T& v)
- {
- if(&t == &v)
- {
- eval_add(t, u);
- }
- else if(&t == &u)
- {
- eval_add(t, v);
- }
- else
- {
- t = u;
- eval_add(t, v);
- }
- }
- template <class T, class U>
- 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)
- {
- T vv;
- vv = v;
- eval_add(t, u, vv);
- }
- template <class T, class U>
- 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)
- {
- T vv(v);
- eval_add(t, u, vv);
- }
- template <class T, class U>
- 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)
- {
- eval_add(t, v, u);
- }
- template <class T, class U, class V>
- inline void eval_add_default(T& t, const U& u, const V& v)
- {
- if(is_same<T, V>::value && ((void*)&t == (void*)&v))
- {
- eval_add(t, u);
- }
- else
- {
- t = u;
- eval_add(t, v);
- }
- }
- template <class T, class U, class V>
- inline void eval_add(T& t, const U& u, const V& v)
- {
- eval_add_default(t, u, v);
- }
- template <class T, class U, class V>
- void eval_subtract(T& t, const U& u, const V& v);
- template <class T>
- inline void eval_subtract_default(T& t, const T& u, const T& v)
- {
- if((&t == &v) && is_signed_number<T>::value)
- {
- eval_subtract(t, u);
- t.negate();
- }
- else if(&t == &u)
- {
- eval_subtract(t, v);
- }
- else
- {
- t = u;
- eval_subtract(t, v);
- }
- }
- template <class T, class U>
- 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)
- {
- T vv;
- vv = v;
- eval_subtract(t, u, vv);
- }
- template <class T, class U>
- 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)
- {
- T vv(v);
- eval_subtract(t, u, vv);
- }
- template <class T, class U>
- 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)
- {
- eval_subtract(t, v, u);
- t.negate();
- }
- template <class T, class U>
- inline typename enable_if_c<is_convertible<U, number<T, et_on> >::value && is_unsigned_number<T>::value>::type eval_subtract_default(T& t, const U& u, const T& v)
- {
- T temp(u);
- eval_subtract(t, temp, v);
- }
- template <class T, class U, class V>
- inline void eval_subtract_default(T& t, const U& u, const V& v)
- {
- if(is_same<T, V>::value && ((void*)&t == (void*)&v))
- {
- eval_subtract(t, u);
- t.negate();
- }
- else
- {
- t = u;
- eval_subtract(t, v);
- }
- }
- template <class T, class U, class V>
- inline void eval_subtract(T& t, const U& u, const V& v)
- {
- eval_subtract_default(t, u, v);
- }
- template <class T>
- inline void eval_multiply_default(T& t, const T& u, const T& v)
- {
- if(&t == &v)
- {
- eval_multiply(t, u);
- }
- else if(&t == &u)
- {
- eval_multiply(t, v);
- }
- else
- {
- t = u;
- eval_multiply(t, v);
- }
- }
- template <class T, class U>
- 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)
- {
- T vv;
- vv = v;
- eval_multiply(t, u, vv);
- }
- template <class T, class U>
- 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)
- {
- T vv(v);
- eval_multiply(t, u, vv);
- }
- template <class T, class U>
- 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)
- {
- eval_multiply(t, v, u);
- }
- template <class T, class U, class V>
- inline void eval_multiply_default(T& t, const U& u, const V& v)
- {
- if(is_same<T, V>::value && ((void*)&t == (void*)&v))
- {
- eval_multiply(t, u);
- }
- else
- {
- t = u;
- eval_multiply(t, v);
- }
- }
- template <class T, class U, class V>
- inline void eval_multiply(T& t, const U& u, const V& v)
- {
- eval_multiply_default(t, u, v);
- }
- template <class T, class U, class V, class X>
- 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)
- {
- if((void*)&x == (void*)&t)
- {
- T z;
- z = x;
- eval_multiply_add(t, u, v, z);
- }
- else
- {
- eval_multiply(t, u, v);
- eval_add(t, x);
- }
- }
- template <class T, class U, class V, class X>
- 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)
- {
- eval_multiply_add(t, v, u, x);
- }
- template <class T, class U, class V, class X>
- 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)
- {
- if((void*)&x == (void*)&t)
- {
- T z;
- z = x;
- eval_multiply_subtract(t, u, v, z);
- }
- else
- {
- eval_multiply(t, u, v);
- eval_subtract(t, x);
- }
- }
- template <class T, class U, class V, class X>
- 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)
- {
- eval_multiply_subtract(t, v, u, x);
- }
- template <class T, class U, class V>
- void eval_divide(T& t, const U& u, const V& v);
- template <class T>
- inline void eval_divide_default(T& t, const T& u, const T& v)
- {
- if(&t == &u)
- eval_divide(t, v);
- else if(&t == &v)
- {
- T temp;
- eval_divide(temp, u, v);
- temp.swap(t);
- }
- else
- {
- t = u;
- eval_divide(t, v);
- }
- }
- template <class T, class U>
- 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)
- {
- T vv;
- vv = v;
- eval_divide(t, u, vv);
- }
- template <class T, class U>
- 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)
- {
- T vv(v);
- eval_divide(t, u, vv);
- }
- template <class T, class U>
- 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)
- {
- T uu;
- uu = u;
- eval_divide(t, uu, v);
- }
- template <class T, class U>
- 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)
- {
- T uu(u);
- eval_divide(t, uu, v);
- }
- template <class T, class U, class V>
- inline void eval_divide_default(T& t, const U& u, const V& v)
- {
- if(is_same<T, V>::value && ((void*)&t == (void*)&v))
- {
- T temp(u);
- eval_divide(temp, v);
- t = temp;
- }
- else
- {
- t = u;
- eval_divide(t, v);
- }
- }
- template <class T, class U, class V>
- inline void eval_divide(T& t, const U& u, const V& v)
- {
- eval_divide_default(t, u, v);
- }
- template <class T, class U, class V>
- void eval_modulus(T& t, const U& u, const V& v);
- template <class T>
- inline void eval_modulus_default(T& t, const T& u, const T& v)
- {
- if(&t == &u)
- eval_modulus(t, v);
- else if(&t == &v)
- {
- T temp;
- eval_modulus(temp, u, v);
- temp.swap(t);
- }
- else
- {
- t = u;
- eval_modulus(t, v);
- }
- }
- template <class T, class U>
- 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)
- {
- T vv;
- vv = v;
- eval_modulus(t, u, vv);
- }
- template <class T, class U>
- 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)
- {
- T vv(v);
- eval_modulus(t, u, vv);
- }
- template <class T, class U>
- 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)
- {
- T uu;
- uu = u;
- eval_modulus(t, uu, v);
- }
- template <class T, class U>
- 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)
- {
- T uu(u);
- eval_modulus(t, uu, v);
- }
- template <class T, class U, class V>
- inline void eval_modulus_default(T& t, const U& u, const V& v)
- {
- if(is_same<T, V>::value && ((void*)&t == (void*)&v))
- {
- T temp(u);
- eval_modulus(temp, v);
- t = temp;
- }
- else
- {
- t = u;
- eval_modulus(t, v);
- }
- }
- template <class T, class U, class V>
- inline void eval_modulus(T& t, const U& u, const V& v)
- {
- eval_modulus_default(t, u, v);
- }
- template <class T, class U, class V>
- void eval_bitwise_and(T& t, const U& u, const V& v);
- template <class T>
- inline void eval_bitwise_and_default(T& t, const T& u, const T& v)
- {
- if(&t == &v)
- {
- eval_bitwise_and(t, u);
- }
- else if(&t == &u)
- {
- eval_bitwise_and(t, v);
- }
- else
- {
- t = u;
- eval_bitwise_and(t, v);
- }
- }
- template <class T, class U>
- inline typename enable_if_c<is_convertible<U, number<T, et_on> >::value && !is_convertible<U, T>::value>::type eval_bitwise_and_default(T& t, const T& u, const U& v)
- {
- T vv;
- vv = v;
- eval_bitwise_and(t, u, vv);
- }
- template <class T, class U>
- inline typename enable_if_c<is_convertible<U, number<T, et_on> >::value && is_convertible<U, T>::value>::type eval_bitwise_and_default(T& t, const T& u, const U& v)
- {
- T vv(v);
- eval_bitwise_and(t, u, vv);
- }
- template <class T, class U>
- 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)
- {
- eval_bitwise_and(t, v, u);
- }
- template <class T, class U, class V>
- inline void eval_bitwise_and_default(T& t, const U& u, const V& v)
- {
- if(is_same<T, V>::value && ((void*)&t == (void*)&v))
- {
- eval_bitwise_and(t, u);
- }
- else
- {
- t = u;
- eval_bitwise_and(t, v);
- }
- }
- template <class T, class U, class V>
- inline void eval_bitwise_and(T& t, const U& u, const V& v)
- {
- eval_bitwise_and_default(t, u, v);
- }
- template <class T, class U, class V>
- void eval_bitwise_or(T& t, const U& u, const V& v);
- template <class T>
- inline void eval_bitwise_or_default(T& t, const T& u, const T& v)
- {
- if(&t == &v)
- {
- eval_bitwise_or(t, u);
- }
- else if(&t == &u)
- {
- eval_bitwise_or(t, v);
- }
- else
- {
- t = u;
- eval_bitwise_or(t, v);
- }
- }
- template <class T, class U>
- 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)
- {
- T vv;
- vv = v;
- eval_bitwise_or(t, u, vv);
- }
- template <class T, class U>
- 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)
- {
- T vv(v);
- eval_bitwise_or(t, u, vv);
- }
- template <class T, class U>
- 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)
- {
- eval_bitwise_or(t, v, u);
- }
- template <class T, class U, class V>
- inline void eval_bitwise_or_default(T& t, const U& u, const V& v)
- {
- if(is_same<T, V>::value && ((void*)&t == (void*)&v))
- {
- eval_bitwise_or(t, u);
- }
- else
- {
- t = u;
- eval_bitwise_or(t, v);
- }
- }
- template <class T, class U, class V>
- inline void eval_bitwise_or(T& t, const U& u, const V& v)
- {
- eval_bitwise_or_default(t, u, v);
- }
- template <class T, class U, class V>
- void eval_bitwise_xor(T& t, const U& u, const V& v);
- template <class T>
- inline void eval_bitwise_xor_default(T& t, const T& u, const T& v)
- {
- if(&t == &v)
- {
- eval_bitwise_xor(t, u);
- }
- else if(&t == &u)
- {
- eval_bitwise_xor(t, v);
- }
- else
- {
- t = u;
- eval_bitwise_xor(t, v);
- }
- }
- template <class T, class U>
- 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)
- {
- T vv;
- vv = v;
- eval_bitwise_xor(t, u, vv);
- }
- template <class T, class U>
- 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)
- {
- T vv(v);
- eval_bitwise_xor(t, u, vv);
- }
- template <class T, class U>
- 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)
- {
- eval_bitwise_xor(t, v, u);
- }
- template <class T, class U, class V>
- inline void eval_bitwise_xor_default(T& t, const U& u, const V& v)
- {
- if(is_same<T, V>::value && ((void*)&t == (void*)&v))
- {
- eval_bitwise_xor(t, u);
- }
- else
- {
- t = u;
- eval_bitwise_xor(t, v);
- }
- }
- template <class T, class U, class V>
- inline void eval_bitwise_xor(T& t, const U& u, const V& v)
- {
- eval_bitwise_xor_default(t, u, v);
- }
- template <class T>
- inline void eval_increment(T& val)
- {
- typedef typename mpl::front<typename T::unsigned_types>::type ui_type;
- eval_add(val, static_cast<ui_type>(1u));
- }
- template <class T>
- inline void eval_decrement(T& val)
- {
- typedef typename mpl::front<typename T::unsigned_types>::type ui_type;
- eval_subtract(val, static_cast<ui_type>(1u));
- }
- template <class T, class V>
- inline void eval_left_shift(T& result, const T& arg, const V val)
- {
- result = arg;
- eval_left_shift(result, val);
- }
- template <class T, class V>
- inline void eval_right_shift(T& result, const T& arg, const V val)
- {
- result = arg;
- eval_right_shift(result, val);
- }
- template <class T>
- inline bool eval_is_zero(const T& val)
- {
- typedef typename mpl::front<typename T::unsigned_types>::type ui_type;
- return val.compare(static_cast<ui_type>(0)) == 0;
- }
- template <class T>
- inline int eval_get_sign(const T& val)
- {
- typedef typename mpl::front<typename T::unsigned_types>::type ui_type;
- return val.compare(static_cast<ui_type>(0));
- }
- template <class T, class V>
- inline void assign_components_imp(T& result, const V& v1, const V& v2, const mpl::int_<number_kind_rational>&)
- {
- result = v1;
- T t;
- t = v2;
- eval_divide(result, t);
- }
- template <class T, class V>
- inline void assign_components(T& result, const V& v1, const V& v2)
- {
- return assign_components_imp(result, v1, v2, typename number_category<T>::type());
- }
- template <class R, int b>
- struct has_enough_bits
- {
- template <class T>
- struct type : public mpl::and_<mpl::not_<is_same<R, T> >, mpl::bool_<std::numeric_limits<T>::digits >= b> >{};
- };
- template <class R>
- struct terminal
- {
- terminal(const R& v) : value(v){}
- terminal(){}
- terminal& operator = (R val) { value = val; return *this; }
- R value;
- operator R()const { return value; }
- };
- template<class R, class B>
- struct calculate_next_larger_type
- {
- // Find which list we're looking through:
- typedef typename mpl::if_<
- is_signed<R>,
- typename B::signed_types,
- typename mpl::if_<
- is_unsigned<R>,
- typename B::unsigned_types,
- typename B::float_types
- >::type
- >::type list_type;
- // A predicate to find a type with enough bits:
- typedef typename has_enough_bits<R, std::numeric_limits<R>::digits>::template type<mpl::_> pred_type;
- // See if the last type is in the list, if so we have to start after this:
- typedef typename mpl::find_if<
- list_type,
- is_same<R, mpl::_>
- >::type start_last;
- // Where we're starting from, either the start of the sequence or the last type found:
- 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;
- // The range we're searching:
- typedef mpl::iterator_range<start_seq, typename mpl::end<list_type>::type> range;
- // Find the next type:
- typedef typename mpl::find_if<
- range,
- pred_type
- >::type iter_type;
- // Either the next type, or a "terminal" to indicate we've run out of types to search:
- typedef typename mpl::eval_if<
- is_same<typename mpl::end<list_type>::type, iter_type>,
- mpl::identity<terminal<R> >,
- mpl::deref<iter_type>
- >::type type;
- };
- template <class R, class T>
- inline bool check_in_range(const T& t)
- {
- // Can t fit in an R?
- if(std::numeric_limits<R>::is_specialized && std::numeric_limits<R>::is_bounded && (t > (std::numeric_limits<R>::max)()))
- return true;
- return false;
- }
- template <class R, class T>
- inline bool check_in_range(const terminal<T>&)
- {
- return false;
- }
- template <class R, class B>
- inline void eval_convert_to(R* result, const B& backend)
- {
- typedef typename calculate_next_larger_type<R, B>::type next_type;
- next_type n;
- eval_convert_to(&n, backend);
- if(check_in_range<R>(n))
- {
- *result = (std::numeric_limits<R>::max)();
- }
- else
- *result = static_cast<R>(n);
- }
- template <class R, class B>
- inline void eval_convert_to(terminal<R>* result, const B& backend)
- {
- //
- // We ran out of types to try for the conversion, try
- // a lexical_cast and hope for the best:
- //
- result->value = boost::lexical_cast<R>(backend.str(0, std::ios_base::fmtflags(0)));
- }
- template <class B>
- inline void eval_convert_to(std::string* result, const B& backend)
- {
- *result = backend.str(0, std::ios_base::fmtflags(0));
- }
- //
- // Functions:
- //
- template <class T>
- void eval_abs(T& result, const T& arg)
- {
- typedef typename T::signed_types type_list;
- typedef typename mpl::front<type_list>::type front;
- result = arg;
- if(arg.compare(front(0)) < 0)
- result.negate();
- }
- template <class T>
- void eval_fabs(T& result, const T& arg)
- {
- BOOST_STATIC_ASSERT_MSG(number_category<T>::value == number_kind_floating_point, "The fabs function is only valid for floating point types.");
- typedef typename T::signed_types type_list;
- typedef typename mpl::front<type_list>::type front;
- result = arg;
- if(arg.compare(front(0)) < 0)
- result.negate();
- }
- template <class Backend>
- inline int eval_fpclassify(const Backend& arg)
- {
- BOOST_STATIC_ASSERT_MSG(number_category<Backend>::value == number_kind_floating_point, "The fpclassify function is only valid for floating point types.");
- return eval_is_zero(arg) ? FP_ZERO : FP_NORMAL;
- }
- template <class T>
- inline void eval_fmod(T& result, const T& a, const T& b)
- {
- BOOST_STATIC_ASSERT_MSG(number_category<T>::value == number_kind_floating_point, "The fmod function is only valid for floating point types.");
- if((&result == &a) || (&result == &b))
- {
- T temp;
- eval_fmod(temp, a, b);
- result = temp;
- return;
- }
- T n;
- eval_divide(result, a, b);
- if(eval_get_sign(result) < 0)
- eval_ceil(n, result);
- else
- eval_floor(n, result);
- eval_multiply(n, b);
- eval_subtract(result, a, n);
- }
- template<class T, class A>
- inline typename enable_if<is_arithmetic<A>, void>::type eval_fmod(T& result, const T& x, const A& a)
- {
- typedef typename boost::multiprecision::detail::canonical<A, T>::type canonical_type;
- typedef typename mpl::if_<is_same<A, canonical_type>, T, canonical_type>::type cast_type;
- cast_type c;
- c = a;
- eval_fmod(result, x, c);
- }
- template<class T, class A>
- inline typename enable_if<is_arithmetic<A>, void>::type eval_fmod(T& result, const A& x, const T& a)
- {
- typedef typename boost::multiprecision::detail::canonical<A, T>::type canonical_type;
- typedef typename mpl::if_<is_same<A, canonical_type>, T, canonical_type>::type cast_type;
- cast_type c;
- c = x;
- eval_fmod(result, c, a);
- }
- template <class T>
- inline void eval_trunc(T& result, const T& a)
- {
- BOOST_STATIC_ASSERT_MSG(number_category<T>::value == number_kind_floating_point, "The trunc function is only valid for floating point types.");
- int c = eval_fpclassify(a);
- if(c == (int)FP_NAN || c == (int)FP_INFINITE)
- {
- result = boost::math::policies::raise_rounding_error("boost::multiprecision::trunc<%1%>(%1%)", 0, number<T>(a), number<T>(a), boost::math::policies::policy<>()).backend();
- return;
- }
- if(eval_get_sign(a) < 0)
- eval_ceil(result, a);
- else
- eval_floor(result, a);
- }
- template <class T>
- inline void eval_round(T& result, const T& a)
- {
- BOOST_STATIC_ASSERT_MSG(number_category<T>::value == number_kind_floating_point, "The round function is only valid for floating point types.");
- typedef typename boost::multiprecision::detail::canonical<float, T>::type fp_type;
- int c = eval_fpclassify(a);
- if((c == (int)FP_NAN) || (c == (int)FP_INFINITE))
- {
- result = boost::math::policies::raise_rounding_error("boost::multiprecision::round<%1%>(%1%)", 0, number<T>(a), number<T>(a), boost::math::policies::policy<>()).backend();
- return;
- }
- if(eval_get_sign(a) < 0)
- {
- eval_subtract(result, a, fp_type(0.5f));
- eval_ceil(result, result);
- }
- else
- {
- eval_add(result, a, fp_type(0.5f));
- eval_floor(result, result);
- }
- }
- template <class B>
- void eval_lcm(B& result, const B& a, const B& b);
- template <class B>
- void eval_gcd(B& result, const B& a, const B& b);
- template <class T, class Arithmetic>
- inline typename enable_if<is_integral<Arithmetic> >::type eval_gcd(T& result, const T& a, const Arithmetic& b)
- {
- typedef typename boost::multiprecision::detail::canonical<Arithmetic, T>::type si_type;
- using default_ops::eval_gcd;
- T t;
- t = static_cast<si_type>(b);
- eval_gcd(result, a, t);
- }
- template <class T, class Arithmetic>
- inline typename enable_if<is_integral<Arithmetic> >::type eval_gcd(T& result, const Arithmetic& a, const T& b)
- {
- eval_gcd(result, b, a);
- }
- template <class T, class Arithmetic>
- inline typename enable_if<is_integral<Arithmetic> >::type eval_lcm(T& result, const T& a, const Arithmetic& b)
- {
- typedef typename boost::multiprecision::detail::canonical<Arithmetic, T>::type si_type;
- using default_ops::eval_lcm;
- T t;
- t = static_cast<si_type>(b);
- eval_lcm(result, a, t);
- }
- template <class T, class Arithmetic>
- inline typename enable_if<is_integral<Arithmetic> >::type eval_lcm(T& result, const Arithmetic& a, const T& b)
- {
- eval_lcm(result, b, a);
- }
- template <class T>
- inline unsigned eval_lsb(const T& val)
- {
- typedef typename boost::multiprecision::detail::canonical<unsigned, T>::type ui_type;
- int c = eval_get_sign(val);
- if(c == 0)
- {
- BOOST_THROW_EXCEPTION(std::range_error("No bits were set in the operand."));
- }
- if(c < 0)
- {
- BOOST_THROW_EXCEPTION(std::range_error("Testing individual bits in negative values is not supported - results are undefined."));
- }
- unsigned result = 0;
- T mask, t;
- mask = ui_type(1);
- do
- {
- eval_bitwise_and(t, mask, val);
- ++result;
- eval_left_shift(mask, 1);
- }
- while(eval_is_zero(t));
-
- return --result;
- }
- template <class T>
- inline int eval_msb(const T& val)
- {
- int c = eval_get_sign(val);
- if(c == 0)
- {
- BOOST_THROW_EXCEPTION(std::range_error("No bits were set in the operand."));
- }
- if(c < 0)
- {
- BOOST_THROW_EXCEPTION(std::range_error("Testing individual bits in negative values is not supported - results are undefined."));
- }
- //
- // This implementation is really really rubbish - it does
- // a linear scan for the most-significant-bit. We should really
- // do a binary search, but as none of our backends actually needs
- // this implementation, we'll leave it for now. In fact for most
- // backends it's likely that there will always be a more efficient
- // native implementation possible.
- //
- unsigned result = 0;
- T t(val);
- while(!eval_is_zero(t))
- {
- eval_right_shift(t, 1);
- ++result;
- }
- return --result;
- }
- template <class T>
- inline bool eval_bit_test(const T& val, unsigned index)
- {
- typedef typename boost::multiprecision::detail::canonical<unsigned, T>::type ui_type;
- T mask, t;
- mask = ui_type(1);
- eval_left_shift(mask, index);
- eval_bitwise_and(t, mask, val);
- return !eval_is_zero(t);
- }
- template <class T>
- inline void eval_bit_set(T& val, unsigned index)
- {
- typedef typename boost::multiprecision::detail::canonical<unsigned, T>::type ui_type;
- T mask;
- mask = ui_type(1);
- eval_left_shift(mask, index);
- eval_bitwise_or(val, mask);
- }
- template <class T>
- inline void eval_bit_flip(T& val, unsigned index)
- {
- typedef typename boost::multiprecision::detail::canonical<unsigned, T>::type ui_type;
- T mask;
- mask = ui_type(1);
- eval_left_shift(mask, index);
- eval_bitwise_xor(val, mask);
- }
- template <class T>
- inline void eval_bit_unset(T& val, unsigned index)
- {
- typedef typename boost::multiprecision::detail::canonical<unsigned, T>::type ui_type;
- T mask, t;
- mask = ui_type(1);
- eval_left_shift(mask, index);
- eval_bitwise_and(t, mask, val);
- if(!eval_is_zero(t))
- eval_bitwise_xor(val, mask);
- }
- template <class B>
- void eval_integer_sqrt(B& s, B& r, const B& x)
- {
- //
- // This is slow bit-by-bit integer square root, see for example
- // http://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Binary_numeral_system_.28base_2.29
- // There are better methods such as http://hal.inria.fr/docs/00/07/28/54/PDF/RR-3805.pdf
- // and http://hal.inria.fr/docs/00/07/21/13/PDF/RR-4475.pdf which should be implemented
- // at some point.
- //
- typedef typename boost::multiprecision::detail::canonical<unsigned char, B>::type ui_type;
- s = ui_type(0u);
- if(eval_get_sign(x) == 0)
- {
- r = ui_type(0u);
- return;
- }
- int g = eval_msb(x);
- if(g == 0)
- {
- r = ui_type(1);
- return;
- }
-
- B t;
- r = x;
- g /= 2;
- int org_g = g;
- eval_bit_set(s, g);
- eval_bit_set(t, 2 * g);
- eval_subtract(r, x, t);
- --g;
- if(eval_get_sign(r) == 0)
- return;
- int msbr = eval_msb(r);
- do
- {
- if(msbr >= org_g + g + 1)
- {
- t = s;
- eval_left_shift(t, g + 1);
- eval_bit_set(t, 2 * g);
- if(t.compare(r) <= 0)
- {
- eval_bit_set(s, g);
- eval_subtract(r, t);
- if(eval_get_sign(r) == 0)
- return;
- msbr = eval_msb(r);
- }
- }
- --g;
- }
- while(g >= 0);
- }
- //
- // These have to implemented by the backend, declared here so that our macro generated code compiles OK.
- //
- template <class T>
- typename enable_if_c<sizeof(T) == 0>::type eval_floor();
- template <class T>
- typename enable_if_c<sizeof(T) == 0>::type eval_ceil();
- template <class T>
- typename enable_if_c<sizeof(T) == 0>::type eval_trunc();
- template <class T>
- typename enable_if_c<sizeof(T) == 0>::type eval_sqrt();
- template <class T>
- typename enable_if_c<sizeof(T) == 0>::type eval_ldexp();
- template <class T>
- typename enable_if_c<sizeof(T) == 0>::type eval_frexp();
- //
- // eval_logb and eval_scalbn simply assume base 2 and forward to
- // eval_ldexp and eval_frexp:
- //
- template <class B>
- inline typename B::exponent_type eval_ilogb(const B& val)
- {
- 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");
- typename B::exponent_type e;
- B result;
- eval_frexp(result, val, &e);
- return e - 1;
- }
- template <class B>
- inline void eval_logb(B& result, const B& val)
- {
- typedef typename boost::mpl::if_c<boost::is_same<boost::intmax_t, long>::value, boost::long_long_type, boost::intmax_t>::type max_t;
- result = static_cast<max_t>(eval_ilogb(val));
- }
- template <class B, class A>
- inline void eval_scalbn(B& result, const B& val, A e)
- {
- 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");
- eval_ldexp(result, val, static_cast<typename B::exponent_type>(e));
- }
- //
- // These functions are implemented in separate files, but expanded inline here,
- // DO NOT CHANGE THE ORDER OF THESE INCLUDES:
- //
- #include <boost/multiprecision/detail/functions/constants.hpp>
- #include <boost/multiprecision/detail/functions/pow.hpp>
- #include <boost/multiprecision/detail/functions/trig.hpp>
- }
- } // namespace multiprecision
- namespace math{
- //
- // Default versions of floating point classification routines:
- //
- template <class Backend, multiprecision::expression_template_option ExpressionTemplates>
- inline int fpclassify BOOST_PREVENT_MACRO_SUBSTITUTION(const multiprecision::number<Backend, ExpressionTemplates>& arg)
- {
- using multiprecision::default_ops::eval_fpclassify;
- return eval_fpclassify(arg.backend());
- }
- template <class tag, class A1, class A2, class A3, class A4>
- inline int fpclassify BOOST_PREVENT_MACRO_SUBSTITUTION(const multiprecision::detail::expression<tag, A1, A2, A3, A4>& arg)
- {
- typedef typename multiprecision::detail::expression<tag, A1, A2, A3, A4>::result_type value_type;
- return (fpclassify)(value_type(arg));
- }
- template <class Backend, multiprecision::expression_template_option ExpressionTemplates>
- inline bool isfinite BOOST_PREVENT_MACRO_SUBSTITUTION(const multiprecision::number<Backend, ExpressionTemplates>& arg)
- {
- int v = (fpclassify)(arg);
- return (v != (int)FP_INFINITE) && (v != (int)FP_NAN);
- }
- template <class tag, class A1, class A2, class A3, class A4>
- inline bool isfinite BOOST_PREVENT_MACRO_SUBSTITUTION(const multiprecision::detail::expression<tag, A1, A2, A3, A4>& arg)
- {
- typedef typename multiprecision::detail::expression<tag, A1, A2, A3, A4>::result_type value_type;
- return (isfinite)(value_type(arg));
- }
- template <class Backend, multiprecision::expression_template_option ExpressionTemplates>
- inline bool isnan BOOST_PREVENT_MACRO_SUBSTITUTION(const multiprecision::number<Backend, ExpressionTemplates>& arg)
- {
- return (fpclassify)(arg) == (int)FP_NAN;
- }
- template <class tag, class A1, class A2, class A3, class A4>
- inline bool isnan BOOST_PREVENT_MACRO_SUBSTITUTION(const multiprecision::detail::expression<tag, A1, A2, A3, A4>& arg)
- {
- typedef typename multiprecision::detail::expression<tag, A1, A2, A3, A4>::result_type value_type;
- return (isnan)(value_type(arg));
- }
- template <class Backend, multiprecision::expression_template_option ExpressionTemplates>
- inline bool isinf BOOST_PREVENT_MACRO_SUBSTITUTION(const multiprecision::number<Backend, ExpressionTemplates>& arg)
- {
- return (fpclassify)(arg) == (int)FP_INFINITE;
- }
- template <class tag, class A1, class A2, class A3, class A4>
- inline bool isinf BOOST_PREVENT_MACRO_SUBSTITUTION(const multiprecision::detail::expression<tag, A1, A2, A3, A4>& arg)
- {
- typedef typename multiprecision::detail::expression<tag, A1, A2, A3, A4>::result_type value_type;
- return (isinf)(value_type(arg));
- }
- template <class Backend, multiprecision::expression_template_option ExpressionTemplates>
- inline bool isnormal BOOST_PREVENT_MACRO_SUBSTITUTION(const multiprecision::number<Backend, ExpressionTemplates>& arg)
- {
- return (fpclassify)(arg) == (int)FP_NORMAL;
- }
- template <class tag, class A1, class A2, class A3, class A4>
- inline bool isnormal BOOST_PREVENT_MACRO_SUBSTITUTION(const multiprecision::detail::expression<tag, A1, A2, A3, A4>& arg)
- {
- typedef typename multiprecision::detail::expression<tag, A1, A2, A3, A4>::result_type value_type;
- return (isnormal)(value_type(arg));
- }
- } // namespace math
- namespace multiprecision{
- template <class B1, class B2, class B3, expression_template_option ET1, expression_template_option ET2, expression_template_option ET3>
- inline number<B1, ET1>& add(number<B1, ET1>& result, const number<B2, ET2>& a, const number<B3, ET3>& b)
- {
- BOOST_STATIC_ASSERT_MSG((is_convertible<B2, B1>::value), "No conversion to the target of a mixed precision addition exists");
- BOOST_STATIC_ASSERT_MSG((is_convertible<B3, B1>::value), "No conversion to the target of a mixed precision addition exists");
- using default_ops::eval_add;
- eval_add(result.backend(), a.backend(), b.backend());
- return result;
- }
- template <class B1, class B2, class B3, expression_template_option ET1, expression_template_option ET2, expression_template_option ET3>
- inline number<B1, ET1>& subtract(number<B1, ET1>& result, const number<B2, ET2>& a, const number<B3, ET3>& b)
- {
- BOOST_STATIC_ASSERT_MSG((is_convertible<B2, B1>::value), "No conversion to the target of a mixed precision addition exists");
- BOOST_STATIC_ASSERT_MSG((is_convertible<B3, B1>::value), "No conversion to the target of a mixed precision addition exists");
- using default_ops::eval_subtract;
- eval_subtract(result.backend(), a.backend(), b.backend());
- return result;
- }
- template <class B1, class B2, class B3, expression_template_option ET1, expression_template_option ET2, expression_template_option ET3>
- inline number<B1, ET1>& multiply(number<B1, ET1>& result, const number<B2, ET2>& a, const number<B3, ET3>& b)
- {
- BOOST_STATIC_ASSERT_MSG((is_convertible<B2, B1>::value), "No conversion to the target of a mixed precision addition exists");
- BOOST_STATIC_ASSERT_MSG((is_convertible<B3, B1>::value), "No conversion to the target of a mixed precision addition exists");
- using default_ops::eval_multiply;
- eval_multiply(result.backend(), a.backend(), b.backend());
- return result;
- }
- template <class B, expression_template_option ET, class I>
- inline typename enable_if_c<is_integral<I>::value, number<B, ET>&>::type
- add(number<B, ET>& result, const I& a, const I& b)
- {
- using default_ops::eval_add;
- typedef typename detail::canonical<I, B>::type canonical_type;
- eval_add(result.backend(), static_cast<canonical_type>(a), static_cast<canonical_type>(b));
- return result;
- }
- template <class B, expression_template_option ET, class I>
- inline typename enable_if_c<is_integral<I>::value, number<B, ET>&>::type
- subtract(number<B, ET>& result, const I& a, const I& b)
- {
- using default_ops::eval_subtract;
- typedef typename detail::canonical<I, B>::type canonical_type;
- eval_subtract(result.backend(), static_cast<canonical_type>(a), static_cast<canonical_type>(b));
- return result;
- }
- template <class B, expression_template_option ET, class I>
- inline typename enable_if_c<is_integral<I>::value, number<B, ET>&>::type
- multiply(number<B, ET>& result, const I& a, const I& b)
- {
- using default_ops::eval_multiply;
- typedef typename detail::canonical<I, B>::type canonical_type;
- eval_multiply(result.backend(), static_cast<canonical_type>(a), static_cast<canonical_type>(b));
- return result;
- }
- template <class tag, class A1, class A2, class A3, class A4, class Policy>
- inline typename detail::expression<tag, A1, A2, A3, A4>::result_type trunc(const detail::expression<tag, A1, A2, A3, A4>& v, const Policy& pol)
- {
- typedef typename detail::expression<tag, A1, A2, A3, A4>::result_type number_type;
- return BOOST_MP_MOVE(trunc(number_type(v), pol));
- }
- template <class Backend, expression_template_option ExpressionTemplates, class Policy>
- inline number<Backend, ExpressionTemplates> trunc(const number<Backend, ExpressionTemplates>& v, const Policy&)
- {
- using default_ops::eval_trunc;
- number<Backend, ExpressionTemplates> result;
- eval_trunc(result.backend(), v.backend());
- return BOOST_MP_MOVE(result);
- }
- template <class tag, class A1, class A2, class A3, class A4, class Policy>
- inline int itrunc(const detail::expression<tag, A1, A2, A3, A4>& v, const Policy& pol)
- {
- typedef typename detail::expression<tag, A1, A2, A3, A4>::result_type number_type;
- number_type r = trunc(v, pol);
- if((r > (std::numeric_limits<int>::max)()) || r < (std::numeric_limits<int>::min)() || !(boost::math::isfinite)(v))
- return boost::math::policies::raise_rounding_error("boost::multiprecision::itrunc<%1%>(%1%)", 0, number_type(v), 0, pol);
- return r.template convert_to<int>();
- }
- template <class tag, class A1, class A2, class A3, class A4>
- inline int itrunc(const detail::expression<tag, A1, A2, A3, A4>& v)
- {
- return itrunc(v, boost::math::policies::policy<>());
- }
- template <class Backend, expression_template_option ExpressionTemplates, class Policy>
- inline int itrunc(const number<Backend, ExpressionTemplates>& v, const Policy& pol)
- {
- number<Backend, ExpressionTemplates> r = trunc(v, pol);
- if((r > (std::numeric_limits<int>::max)()) || r < (std::numeric_limits<int>::min)() || !(boost::math::isfinite)(v))
- return boost::math::policies::raise_rounding_error("boost::multiprecision::itrunc<%1%>(%1%)", 0, v, 0, pol);
- return r.template convert_to<int>();
- }
- template <class Backend, expression_template_option ExpressionTemplates>
- inline int itrunc(const number<Backend, ExpressionTemplates>& v)
- {
- return itrunc(v, boost::math::policies::policy<>());
- }
- template <class tag, class A1, class A2, class A3, class A4, class Policy>
- inline long ltrunc(const detail::expression<tag, A1, A2, A3, A4>& v, const Policy& pol)
- {
- typedef typename detail::expression<tag, A1, A2, A3, A4>::result_type number_type;
- number_type r = trunc(v, pol);
- if((r > (std::numeric_limits<long>::max)()) || r < (std::numeric_limits<long>::min)() || !(boost::math::isfinite)(v))
- return boost::math::policies::raise_rounding_error("boost::multiprecision::ltrunc<%1%>(%1%)", 0, number_type(v), 0L, pol);
- return r.template convert_to<long>();
- }
- template <class tag, class A1, class A2, class A3, class A4>
- inline long ltrunc(const detail::expression<tag, A1, A2, A3, A4>& v)
- {
- return ltrunc(v, boost::math::policies::policy<>());
- }
- template <class T, expression_template_option ExpressionTemplates, class Policy>
- inline long ltrunc(const number<T, ExpressionTemplates>& v, const Policy& pol)
- {
- number<T, ExpressionTemplates> r = trunc(v, pol);
- if((r > (std::numeric_limits<long>::max)()) || r < (std::numeric_limits<long>::min)() || !(boost::math::isfinite)(v))
- return boost::math::policies::raise_rounding_error("boost::multiprecision::ltrunc<%1%>(%1%)", 0, v, 0L, pol);
- return r.template convert_to<long>();
- }
- template <class T, expression_template_option ExpressionTemplates>
- inline long ltrunc(const number<T, ExpressionTemplates>& v)
- {
- return ltrunc(v, boost::math::policies::policy<>());
- }
- #ifndef BOOST_NO_LONG_LONG
- template <class tag, class A1, class A2, class A3, class A4, class Policy>
- inline boost::long_long_type lltrunc(const detail::expression<tag, A1, A2, A3, A4>& v, const Policy& pol)
- {
- typedef typename detail::expression<tag, A1, A2, A3, A4>::result_type number_type;
- number_type r = trunc(v, pol);
- if((r > (std::numeric_limits<boost::long_long_type>::max)()) || r < (std::numeric_limits<boost::long_long_type>::min)() || !(boost::math::isfinite)(v))
- return boost::math::policies::raise_rounding_error("boost::multiprecision::lltrunc<%1%>(%1%)", 0, number_type(v), 0LL, pol);
- return r.template convert_to<boost::long_long_type>();
- }
- template <class tag, class A1, class A2, class A3, class A4>
- inline boost::long_long_type lltrunc(const detail::expression<tag, A1, A2, A3, A4>& v)
- {
- return lltrunc(v, boost::math::policies::policy<>());
- }
- template <class T, expression_template_option ExpressionTemplates, class Policy>
- inline boost::long_long_type lltrunc(const number<T, ExpressionTemplates>& v, const Policy& pol)
- {
- number<T, ExpressionTemplates> r = trunc(v, pol);
- if((r > (std::numeric_limits<boost::long_long_type>::max)()) || r < (std::numeric_limits<boost::long_long_type>::min)() || !(boost::math::isfinite)(v))
- return boost::math::policies::raise_rounding_error("boost::multiprecision::lltrunc<%1%>(%1%)", 0, v, 0LL, pol);
- return r.template convert_to<boost::long_long_type>();
- }
- template <class T, expression_template_option ExpressionTemplates>
- inline boost::long_long_type lltrunc(const number<T, ExpressionTemplates>& v)
- {
- return lltrunc(v, boost::math::policies::policy<>());
- }
- #endif
- template <class tag, class A1, class A2, class A3, class A4, class Policy>
- inline typename detail::expression<tag, A1, A2, A3, A4>::result_type round(const detail::expression<tag, A1, A2, A3, A4>& v, const Policy& pol)
- {
- typedef typename detail::expression<tag, A1, A2, A3, A4>::result_type number_type;
- return BOOST_MP_MOVE(round(static_cast<number_type>(v), pol));
- }
- template <class T, expression_template_option ExpressionTemplates, class Policy>
- inline number<T, ExpressionTemplates> round(const number<T, ExpressionTemplates>& v, const Policy&)
- {
- using default_ops::eval_round;
- number<T, ExpressionTemplates> result;
- eval_round(result.backend(), v.backend());
- return BOOST_MP_MOVE(result);
- }
- template <class tag, class A1, class A2, class A3, class A4, class Policy>
- inline int iround(const detail::expression<tag, A1, A2, A3, A4>& v, const Policy& pol)
- {
- typedef typename detail::expression<tag, A1, A2, A3, A4>::result_type number_type;
- number_type r = round(v, pol);
- if((r > (std::numeric_limits<int>::max)()) || r < (std::numeric_limits<int>::min)() || !(boost::math::isfinite)(v))
- return boost::math::policies::raise_rounding_error("boost::multiprecision::iround<%1%>(%1%)", 0, number_type(v), 0, pol);
- return r.template convert_to<int>();
- }
- template <class tag, class A1, class A2, class A3, class A4>
- inline int iround(const detail::expression<tag, A1, A2, A3, A4>& v)
- {
- return iround(v, boost::math::policies::policy<>());
- }
- template <class T, expression_template_option ExpressionTemplates, class Policy>
- inline int iround(const number<T, ExpressionTemplates>& v, const Policy& pol)
- {
- number<T, ExpressionTemplates> r = round(v, pol);
- if((r > (std::numeric_limits<int>::max)()) || r < (std::numeric_limits<int>::min)() || !(boost::math::isfinite)(v))
- return boost::math::policies::raise_rounding_error("boost::multiprecision::iround<%1%>(%1%)", 0, v, 0, pol);
- return r.template convert_to<int>();
- }
- template <class T, expression_template_option ExpressionTemplates>
- inline int iround(const number<T, ExpressionTemplates>& v)
- {
- return iround(v, boost::math::policies::policy<>());
- }
- template <class tag, class A1, class A2, class A3, class A4, class Policy>
- inline long lround(const detail::expression<tag, A1, A2, A3, A4>& v, const Policy& pol)
- {
- typedef typename detail::expression<tag, A1, A2, A3, A4>::result_type number_type;
- number_type r = round(v, pol);
- if((r > (std::numeric_limits<long>::max)()) || r < (std::numeric_limits<long>::min)() || !(boost::math::isfinite)(v))
- return boost::math::policies::raise_rounding_error("boost::multiprecision::lround<%1%>(%1%)", 0, number_type(v), 0L, pol);
- return r.template convert_to<long>();
- }
- template <class tag, class A1, class A2, class A3, class A4>
- inline long lround(const detail::expression<tag, A1, A2, A3, A4>& v)
- {
- return lround(v, boost::math::policies::policy<>());
- }
- template <class T, expression_template_option ExpressionTemplates, class Policy>
- inline long lround(const number<T, ExpressionTemplates>& v, const Policy& pol)
- {
- number<T, ExpressionTemplates> r = round(v, pol);
- if((r > (std::numeric_limits<long>::max)()) || r < (std::numeric_limits<long>::min)() || !(boost::math::isfinite)(v))
- return boost::math::policies::raise_rounding_error("boost::multiprecision::lround<%1%>(%1%)", 0, v, 0L, pol);
- return r.template convert_to<long>();
- }
- template <class T, expression_template_option ExpressionTemplates>
- inline long lround(const number<T, ExpressionTemplates>& v)
- {
- return lround(v, boost::math::policies::policy<>());
- }
- #ifndef BOOST_NO_LONG_LONG
- template <class tag, class A1, class A2, class A3, class A4, class Policy>
- inline boost::long_long_type llround(const detail::expression<tag, A1, A2, A3, A4>& v, const Policy& pol)
- {
- typedef typename detail::expression<tag, A1, A2, A3, A4>::result_type number_type;
- number_type r = round(v, pol);
- if((r > (std::numeric_limits<boost::long_long_type>::max)()) || r < (std::numeric_limits<boost::long_long_type>::min)() || !(boost::math::isfinite)(v))
- return boost::math::policies::raise_rounding_error("boost::multiprecision::iround<%1%>(%1%)", 0, number_type(v), 0LL, pol);
- return r.template convert_to<boost::long_long_type>();
- }
- template <class tag, class A1, class A2, class A3, class A4>
- inline boost::long_long_type llround(const detail::expression<tag, A1, A2, A3, A4>& v)
- {
- return llround(v, boost::math::policies::policy<>());
- }
- template <class T, expression_template_option ExpressionTemplates, class Policy>
- inline boost::long_long_type llround(const number<T, ExpressionTemplates>& v, const Policy& pol)
- {
- number<T, ExpressionTemplates> r = round(v, pol);
- if((r > (std::numeric_limits<boost::long_long_type>::max)()) || r < (std::numeric_limits<boost::long_long_type>::min)() || !(boost::math::isfinite)(v))
- return boost::math::policies::raise_rounding_error("boost::multiprecision::iround<%1%>(%1%)", 0, v, 0LL, pol);
- return r.template convert_to<boost::long_long_type>();
- }
- template <class T, expression_template_option ExpressionTemplates>
- inline boost::long_long_type llround(const number<T, ExpressionTemplates>& v)
- {
- return llround(v, boost::math::policies::policy<>());
- }
- #endif
- //
- // frexp does not return an expression template since we require the
- // integer argument to be evaluated even if the returned value is
- // not assigned to anything...
- //
- template <class T, expression_template_option ExpressionTemplates>
- 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)
- {
- using default_ops::eval_frexp;
- number<T, ExpressionTemplates> result;
- eval_frexp(result.backend(), v.backend(), pint);
- return BOOST_MP_MOVE(result);
- }
- template <class tag, class A1, class A2, class A3, class A4>
- 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
- frexp(const detail::expression<tag, A1, A2, A3, A4>& v, short* pint)
- {
- typedef typename detail::expression<tag, A1, A2, A3, A4>::result_type number_type;
- return BOOST_MP_MOVE(frexp(static_cast<number_type>(v), pint));
- }
- template <class T, expression_template_option ExpressionTemplates>
- 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)
- {
- using default_ops::eval_frexp;
- number<T, ExpressionTemplates> result;
- eval_frexp(result.backend(), v.backend(), pint);
- return BOOST_MP_MOVE(result);
- }
- template <class tag, class A1, class A2, class A3, class A4>
- 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
- frexp(const detail::expression<tag, A1, A2, A3, A4>& v, int* pint)
- {
- typedef typename detail::expression<tag, A1, A2, A3, A4>::result_type number_type;
- return BOOST_MP_MOVE(frexp(static_cast<number_type>(v), pint));
- }
- template <class T, expression_template_option ExpressionTemplates>
- 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)
- {
- using default_ops::eval_frexp;
- number<T, ExpressionTemplates> result;
- eval_frexp(result.backend(), v.backend(), pint);
- return BOOST_MP_MOVE(result);
- }
- template <class tag, class A1, class A2, class A3, class A4>
- 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
- frexp(const detail::expression<tag, A1, A2, A3, A4>& v, long* pint)
- {
- typedef typename detail::expression<tag, A1, A2, A3, A4>::result_type number_type;
- return BOOST_MP_MOVE(frexp(static_cast<number_type>(v), pint));
- }
- template <class T, expression_template_option ExpressionTemplates>
- 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)
- {
- using default_ops::eval_frexp;
- number<T, ExpressionTemplates> result;
- eval_frexp(result.backend(), v.backend(), pint);
- return BOOST_MP_MOVE(result);
- }
- template <class tag, class A1, class A2, class A3, class A4>
- 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
- frexp(const detail::expression<tag, A1, A2, A3, A4>& v, boost::long_long_type* pint)
- {
- typedef typename detail::expression<tag, A1, A2, A3, A4>::result_type number_type;
- return BOOST_MP_MOVE(frexp(static_cast<number_type>(v), pint));
- }
- template <class B, expression_template_option ExpressionTemplates>
- inline typename enable_if_c<number_category<B>::value == number_kind_integer, number<B, ExpressionTemplates> >::type
- sqrt(const number<B, ExpressionTemplates>& x)
- {
- using default_ops::eval_integer_sqrt;
- number<B, ExpressionTemplates> s, r;
- eval_integer_sqrt(s.backend(), r.backend(), x.backend());
- return s;
- }
- template <class B, expression_template_option ExpressionTemplates>
- inline typename enable_if_c<number_category<B>::value == number_kind_integer, number<B, ExpressionTemplates> >::type
- sqrt(const number<B, ExpressionTemplates>& x, number<B, ExpressionTemplates>& r)
- {
- using default_ops::eval_integer_sqrt;
- number<B, ExpressionTemplates> s;
- eval_integer_sqrt(s.backend(), r.backend(), x.backend());
- return s;
- }
- #define UNARY_OP_FUNCTOR(func, category)\
- namespace detail{\
- template <class Backend> \
- struct BOOST_JOIN(func, _funct)\
- {\
- void operator()(Backend& result, const Backend& arg)const\
- {\
- using default_ops::BOOST_JOIN(eval_,func);\
- BOOST_JOIN(eval_,func)(result, arg);\
- }\
- };\
- \
- }\
- \
- template <class tag, class A1, class A2, class A3, class A4> \
- inline typename enable_if_c<number_category<detail::expression<tag, A1, A2, A3, A4> >::value == category,\
- detail::expression<\
- detail::function\
- , detail::BOOST_JOIN(func, _funct)<typename detail::backend_type<detail::expression<tag, A1, A2, A3, A4> >::type> \
- , detail::expression<tag, A1, A2, A3, A4> > \
- >::type \
- func(const detail::expression<tag, A1, A2, A3, A4>& arg)\
- {\
- return detail::expression<\
- detail::function\
- , detail::BOOST_JOIN(func, _funct)<typename detail::backend_type<detail::expression<tag, A1, A2, A3, A4> >::type> \
- , detail::expression<tag, A1, A2, A3, A4> \
- > (\
- detail::BOOST_JOIN(func, _funct)<typename detail::backend_type<detail::expression<tag, A1, A2, A3, A4> >::type>() \
- , arg \
- );\
- }\
- template <class Backend> \
- inline typename enable_if_c<number_category<Backend>::value == category,\
- detail::expression<\
- detail::function\
- , detail::BOOST_JOIN(func, _funct)<Backend> \
- , number<Backend, et_on> > \
- >::type \
- func(const number<Backend, et_on>& arg)\
- {\
- return detail::expression<\
- detail::function\
- , detail::BOOST_JOIN(func, _funct)<Backend> \
- , number<Backend, et_on> \
- >(\
- detail::BOOST_JOIN(func, _funct)<Backend>() \
- , arg \
- );\
- }\
- template <class Backend> \
- inline typename boost::enable_if_c<\
- boost::multiprecision::number_category<Backend>::value == category,\
- number<Backend, et_off> >::type \
- func(const number<Backend, et_off>& arg)\
- {\
- number<Backend, et_off> result;\
- using default_ops::BOOST_JOIN(eval_,func);\
- BOOST_JOIN(eval_,func)(result.backend(), arg.backend());\
- return BOOST_MP_MOVE(result);\
- }
- #define BINARY_OP_FUNCTOR(func, category)\
- namespace detail{\
- template <class Backend> \
- struct BOOST_JOIN(func, _funct)\
- {\
- void operator()(Backend& result, const Backend& arg, const Backend& a)const\
- {\
- using default_ops:: BOOST_JOIN(eval_,func);\
- BOOST_JOIN(eval_,func)(result, arg, a);\
- }\
- template <class Arithmetic> \
- void operator()(Backend& result, const Backend& arg, const Arithmetic& a)const\
- {\
- using default_ops:: BOOST_JOIN(eval_,func);\
- BOOST_JOIN(eval_,func)(result, arg, a);\
- }\
- template <class Arithmetic> \
- void operator()(Backend& result, const Arithmetic& arg, const Backend& a)const\
- {\
- using default_ops:: BOOST_JOIN(eval_,func);\
- BOOST_JOIN(eval_,func)(result, arg, a);\
- }\
- };\
- \
- }\
- template <class Backend> \
- inline typename enable_if_c<number_category<Backend>::value == category,\
- detail::expression<\
- detail::function\
- , detail::BOOST_JOIN(func, _funct)<Backend> \
- , number<Backend, et_on> \
- , number<Backend, et_on> > \
- >::type \
- func(const number<Backend, et_on>& arg, const number<Backend, et_on>& a)\
- {\
- return detail::expression<\
- detail::function\
- , detail::BOOST_JOIN(func, _funct)<Backend> \
- , number<Backend, et_on> \
- , number<Backend, et_on> \
- >(\
- detail::BOOST_JOIN(func, _funct)<Backend>() \
- , arg,\
- a\
- );\
- }\
- template <class Backend, class tag, class A1, class A2, class A3, class A4> \
- inline typename enable_if_c<\
- (number_category<Backend>::value == category) && (number_category<detail::expression<tag, A1, A2, A3, A4> >::value == category),\
- detail::expression<\
- detail::function\
- , detail::BOOST_JOIN(func, _funct)<Backend> \
- , number<Backend, et_on> \
- , detail::expression<tag, A1, A2, A3, A4> > \
- >::type \
- func(const number<Backend, et_on>& arg, const detail::expression<tag, A1, A2, A3, A4>& a)\
- {\
- return detail::expression<\
- detail::function\
- , detail::BOOST_JOIN(func, _funct)<Backend> \
- , number<Backend, et_on> \
- , detail::expression<tag, A1, A2, A3, A4> \
- >(\
- detail::BOOST_JOIN(func, _funct)<Backend>() \
- , arg,\
- a\
- );\
- }\
- template <class tag, class A1, class A2, class A3, class A4, class Backend> \
- inline typename enable_if_c<\
- (number_category<Backend>::value == category) && (number_category<detail::expression<tag, A1, A2, A3, A4> >::value == category),\
- detail::expression<\
- detail::function\
- , detail::BOOST_JOIN(func, _funct)<Backend> \
- , detail::expression<tag, A1, A2, A3, A4> \
- , number<Backend, et_on> > \
- >::type \
- func(const detail::expression<tag, A1, A2, A3, A4>& arg, const number<Backend, et_on>& a)\
- {\
- return detail::expression<\
- detail::function\
- , detail::BOOST_JOIN(func, _funct)<Backend> \
- , detail::expression<tag, A1, A2, A3, A4> \
- , number<Backend, et_on> \
- >(\
- detail::BOOST_JOIN(func, _funct)<Backend>() \
- , arg,\
- a\
- );\
- }\
- template <class tag, class A1, class A2, class A3, class A4, class tagb, class A1b, class A2b, class A3b, class A4b> \
- inline typename enable_if_c<\
- (number_category<detail::expression<tag, A1, A2, A3, A4> >::value == category) && (number_category<detail::expression<tagb, A1b, A2b, A3b, A4b> >::value == category),\
- detail::expression<\
- detail::function\
- , detail::BOOST_JOIN(func, _funct)<typename detail::backend_type<detail::expression<tag, A1, A2, A3, A4> >::type> \
- , detail::expression<tag, A1, A2, A3, A4> \
- , detail::expression<tagb, A1b, A2b, A3b, A4b> > \
- >::type \
- func(const detail::expression<tag, A1, A2, A3, A4>& arg, const detail::expression<tagb, A1b, A2b, A3b, A4b>& a)\
- {\
- return detail::expression<\
- detail::function\
- , detail::BOOST_JOIN(func, _funct)<typename detail::backend_type<detail::expression<tag, A1, A2, A3, A4> >::type> \
- , detail::expression<tag, A1, A2, A3, A4> \
- , detail::expression<tagb, A1b, A2b, A3b, A4b> \
- >(\
- detail::BOOST_JOIN(func, _funct)<typename detail::backend_type<detail::expression<tag, A1, A2, A3, A4> >::type>() \
- , arg,\
- a\
- );\
- }\
- template <class Backend, class Arithmetic> \
- inline typename enable_if_c<\
- is_arithmetic<Arithmetic>::value && (number_category<Backend>::value == category),\
- detail::expression<\
- detail::function\
- , detail::BOOST_JOIN(func, _funct)<Backend> \
- , number<Backend, et_on> \
- , Arithmetic\
- > \
- >::type \
- func(const number<Backend, et_on>& arg, const Arithmetic& a)\
- {\
- return detail::expression<\
- detail::function\
- , detail::BOOST_JOIN(func, _funct)<Backend> \
- , number<Backend, et_on> \
- , Arithmetic\
- >(\
- detail::BOOST_JOIN(func, _funct)<Backend>() \
- , arg,\
- a\
- );\
- }\
- template <class tag, class A1, class A2, class A3, class A4, class Arithmetic> \
- inline typename enable_if_c<\
- is_arithmetic<Arithmetic>::value && (number_category<detail::expression<tag, A1, A2, A3, A4> >::value == category),\
- detail::expression<\
- detail::function\
- , detail::BOOST_JOIN(func, _funct)<typename detail::backend_type<detail::expression<tag, A1, A2, A3, A4> >::type> \
- , detail::expression<tag, A1, A2, A3, A4> \
- , Arithmetic\
- > \
- >::type \
- func(const detail::expression<tag, A1, A2, A3, A4>& arg, const Arithmetic& a)\
- {\
- return detail::expression<\
- detail::function\
- , detail::BOOST_JOIN(func, _funct)<typename detail::backend_type<detail::expression<tag, A1, A2, A3, A4> >::type> \
- , detail::expression<tag, A1, A2, A3, A4> \
- , Arithmetic\
- >(\
- detail::BOOST_JOIN(func, _funct)<typename detail::backend_type<detail::expression<tag, A1, A2, A3, A4> >::type>() \
- , arg,\
- a\
- );\
- }\
- template <class Backend, class Arithmetic> \
- inline typename enable_if_c<\
- is_arithmetic<Arithmetic>::value && (number_category<Backend>::value == category),\
- detail::expression<\
- detail::function\
- , detail::BOOST_JOIN(func, _funct)<Backend> \
- , Arithmetic \
- , number<Backend, et_on> \
- > \
- >::type \
- func(const Arithmetic& arg, const number<Backend, et_on>& a)\
- {\
- return detail::expression<\
- detail::function\
- , detail::BOOST_JOIN(func, _funct)<Backend> \
- , Arithmetic \
- , number<Backend, et_on> \
- >(\
- detail::BOOST_JOIN(func, _funct)<Backend>() \
- , arg,\
- a\
- );\
- }\
- template <class tag, class A1, class A2, class A3, class A4, class Arithmetic> \
- inline typename enable_if_c<\
- is_arithmetic<Arithmetic>::value && (number_category<detail::expression<tag, A1, A2, A3, A4> >::value == category),\
- detail::expression<\
- detail::function\
- , detail::BOOST_JOIN(func, _funct)<typename detail::backend_type<detail::expression<tag, A1, A2, A3, A4> >::type> \
- , Arithmetic \
- , detail::expression<tag, A1, A2, A3, A4> \
- > \
- >::type \
- func(const Arithmetic& arg, const detail::expression<tag, A1, A2, A3, A4>& a)\
- {\
- return detail::expression<\
- detail::function\
- , detail::BOOST_JOIN(func, _funct)<typename detail::backend_type<detail::expression<tag, A1, A2, A3, A4> >::type> \
- , Arithmetic \
- , detail::expression<tag, A1, A2, A3, A4> \
- >(\
- detail::BOOST_JOIN(func, _funct)<typename detail::backend_type<detail::expression<tag, A1, A2, A3, A4> >::type>() \
- , arg,\
- a\
- );\
- }\
- template <class Backend> \
- inline typename enable_if_c<(number_category<Backend>::value == category),\
- number<Backend, et_off> >::type \
- func(const number<Backend, et_off>& arg, const number<Backend, et_off>& a)\
- {\
- number<Backend, et_off> result;\
- using default_ops:: BOOST_JOIN(eval_,func);\
- BOOST_JOIN(eval_,func)(result.backend(), arg.backend(), a.backend());\
- return BOOST_MP_MOVE(result);\
- }\
- template <class Backend, class Arithmetic> \
- inline typename enable_if_c<\
- is_arithmetic<Arithmetic>::value && (number_category<Backend>::value == category),\
- number<Backend, et_off> \
- >::type \
- func(const number<Backend, et_off>& arg, const Arithmetic& a)\
- {\
- typedef typename detail::canonical<Arithmetic, Backend>::type canonical_type;\
- number<Backend, et_off> result;\
- using default_ops:: BOOST_JOIN(eval_,func);\
- BOOST_JOIN(eval_,func)(result.backend(), arg.backend(), static_cast<canonical_type>(a));\
- return BOOST_MP_MOVE(result);\
- }\
- template <class Backend, class Arithmetic> \
- inline typename enable_if_c<\
- is_arithmetic<Arithmetic>::value && (number_category<Backend>::value == category),\
- number<Backend, et_off> \
- >::type \
- func(const Arithmetic& a, const number<Backend, et_off>& arg)\
- {\
- typedef typename detail::canonical<Arithmetic, Backend>::type canonical_type;\
- number<Backend, et_off> result;\
- using default_ops:: BOOST_JOIN(eval_,func);\
- BOOST_JOIN(eval_,func)(result.backend(), static_cast<canonical_type>(a), arg.backend());\
- return BOOST_MP_MOVE(result);\
- }\
- #define HETERO_BINARY_OP_FUNCTOR_B(func, Arg2, category)\
- template <class tag, class A1, class A2, class A3, class A4> \
- inline typename enable_if_c<\
- (number_category<detail::expression<tag, A1, A2, A3, A4> >::value == category),\
- detail::expression<\
- detail::function\
- , detail::BOOST_JOIN(func, _funct)<typename detail::backend_type<detail::expression<tag, A1, A2, A3, A4> >::type> \
- , detail::expression<tag, A1, A2, A3, A4> \
- , Arg2> \
- >::type \
- func(const detail::expression<tag, A1, A2, A3, A4>& arg, Arg2 const& a)\
- {\
- return detail::expression<\
- detail::function\
- , detail::BOOST_JOIN(func, _funct)<typename detail::backend_type<detail::expression<tag, A1, A2, A3, A4> >::type> \
- , detail::expression<tag, A1, A2, A3, A4> \
- , Arg2\
- >(\
- detail::BOOST_JOIN(func, _funct)<typename detail::backend_type<detail::expression<tag, A1, A2, A3, A4> >::type>() \
- , arg, a \
- );\
- }\
- template <class Backend> \
- inline typename enable_if_c<\
- (number_category<Backend>::value == category),\
- detail::expression<\
- detail::function\
- , detail::BOOST_JOIN(func, _funct)<Backend> \
- , number<Backend, et_on> \
- , Arg2> \
- >::type \
- func(const number<Backend, et_on>& arg, Arg2 const& a)\
- {\
- return detail::expression<\
- detail::function\
- , detail::BOOST_JOIN(func, _funct)<Backend> \
- , number<Backend, et_on> \
- , Arg2\
- >(\
- detail::BOOST_JOIN(func, _funct)<Backend>() \
- , arg,\
- a\
- );\
- }\
- template <class Backend> \
- inline typename enable_if_c<\
- (number_category<Backend>::value == category),\
- number<Backend, et_off> >::type \
- func(const number<Backend, et_off>& arg, Arg2 const& a)\
- {\
- number<Backend, et_off> result;\
- using default_ops:: BOOST_JOIN(eval_,func);\
- BOOST_JOIN(eval_,func)(result.backend(), arg.backend(), a);\
- return BOOST_MP_MOVE(result);\
- }\
- #define HETERO_BINARY_OP_FUNCTOR(func, Arg2, category)\
- namespace detail{\
- template <class Backend> \
- struct BOOST_JOIN(func, _funct)\
- {\
- template <class Arg>\
- void operator()(Backend& result, Backend const& arg, Arg a)const\
- {\
- using default_ops:: BOOST_JOIN(eval_,func);\
- BOOST_JOIN(eval_,func)(result, arg, a);\
- }\
- };\
- \
- }\
- \
- HETERO_BINARY_OP_FUNCTOR_B(func, Arg2, category)
- namespace detail{
- template <class Backend>
- struct abs_funct
- {
- void operator()(Backend& result, const Backend& arg)const
- {
- using default_ops::eval_abs;
- eval_abs(result, arg);
- }
- };
- }
- template <class tag, class A1, class A2, class A3, class A4>
- inline detail::expression<
- detail::function
- , detail::abs_funct<typename detail::backend_type<detail::expression<tag, A1, A2, A3, A4> >::type>
- , detail::expression<tag, A1, A2, A3, A4> >
- abs(const detail::expression<tag, A1, A2, A3, A4>& arg)
- {
- return detail::expression<
- detail::function
- , detail::abs_funct<typename detail::backend_type<detail::expression<tag, A1, A2, A3, A4> >::type>
- , detail::expression<tag, A1, A2, A3, A4>
- > (
- detail::abs_funct<typename detail::backend_type<detail::expression<tag, A1, A2, A3, A4> >::type>()
- , arg
- );
- }
- template <class Backend>
- inline detail::expression<
- detail::function
- , detail::abs_funct<Backend>
- , number<Backend, et_on> >
- abs(const number<Backend, et_on>& arg)
- {
- return detail::expression<
- detail::function
- , detail::abs_funct<Backend>
- , number<Backend, et_on>
- >(
- detail::abs_funct<Backend>()
- , arg
- );
- }
- template <class Backend>
- inline number<Backend, et_off>
- abs(const number<Backend, et_off>& arg)
- {
- number<Backend, et_off> result;
- using default_ops::eval_abs;
- eval_abs(result.backend(), arg.backend());
- return BOOST_MP_MOVE(result);
- }
- UNARY_OP_FUNCTOR(fabs, number_kind_floating_point)
- UNARY_OP_FUNCTOR(sqrt, number_kind_floating_point)
- UNARY_OP_FUNCTOR(floor, number_kind_floating_point)
- UNARY_OP_FUNCTOR(ceil, number_kind_floating_point)
- UNARY_OP_FUNCTOR(trunc, number_kind_floating_point)
- UNARY_OP_FUNCTOR(round, number_kind_floating_point)
- UNARY_OP_FUNCTOR(exp, number_kind_floating_point)
- UNARY_OP_FUNCTOR(log, number_kind_floating_point)
- UNARY_OP_FUNCTOR(log10, number_kind_floating_point)
- UNARY_OP_FUNCTOR(cos, number_kind_floating_point)
- UNARY_OP_FUNCTOR(sin, number_kind_floating_point)
- UNARY_OP_FUNCTOR(tan, number_kind_floating_point)
- UNARY_OP_FUNCTOR(asin, number_kind_floating_point)
- UNARY_OP_FUNCTOR(acos, number_kind_floating_point)
- UNARY_OP_FUNCTOR(atan, number_kind_floating_point)
- UNARY_OP_FUNCTOR(cosh, number_kind_floating_point)
- UNARY_OP_FUNCTOR(sinh, number_kind_floating_point)
- UNARY_OP_FUNCTOR(tanh, number_kind_floating_point)
- HETERO_BINARY_OP_FUNCTOR(ldexp, short, number_kind_floating_point)
- //HETERO_BINARY_OP_FUNCTOR(frexp, short*, number_kind_floating_point)
- HETERO_BINARY_OP_FUNCTOR_B(ldexp, int, number_kind_floating_point)
- //HETERO_BINARY_OP_FUNCTOR_B(frexp, int*, number_kind_floating_point)
- HETERO_BINARY_OP_FUNCTOR_B(ldexp, long, number_kind_floating_point)
- //HETERO_BINARY_OP_FUNCTOR_B(frexp, long*, number_kind_floating_point)
- HETERO_BINARY_OP_FUNCTOR_B(ldexp, boost::long_long_type, number_kind_floating_point)
- //HETERO_BINARY_OP_FUNCTOR_B(frexp, boost::long_long_type*, number_kind_floating_point)
- BINARY_OP_FUNCTOR(pow, number_kind_floating_point)
- BINARY_OP_FUNCTOR(fmod, number_kind_floating_point)
- BINARY_OP_FUNCTOR(atan2, number_kind_floating_point)
- UNARY_OP_FUNCTOR(logb, number_kind_floating_point)
- HETERO_BINARY_OP_FUNCTOR(scalbn, short, number_kind_floating_point)
- HETERO_BINARY_OP_FUNCTOR_B(scalbn, int, number_kind_floating_point)
- HETERO_BINARY_OP_FUNCTOR_B(scalbn, long, number_kind_floating_point)
- HETERO_BINARY_OP_FUNCTOR_B(scalbn, boost::long_long_type, number_kind_floating_point)
- //
- // Integer functions:
- //
- BINARY_OP_FUNCTOR(gcd, number_kind_integer)
- BINARY_OP_FUNCTOR(lcm, number_kind_integer)
- HETERO_BINARY_OP_FUNCTOR_B(pow, unsigned, number_kind_integer)
- #undef BINARY_OP_FUNCTOR
- #undef UNARY_OP_FUNCTOR
- //
- // ilogb:
- //
- template <class Backend, multiprecision::expression_template_option ExpressionTemplates>
- inline typename enable_if_c<number_category<Backend>::value == number_kind_floating_point, typename Backend::exponent_type>::type
- ilogb(const multiprecision::number<Backend, ExpressionTemplates>& val)
- {
- using default_ops::eval_ilogb;
- return eval_ilogb(val.backend());
- }
- template <class tag, class A1, class A2, class A3, class A4>
- 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
- ilogb(const detail::expression<tag, A1, A2, A3, A4>& val)
- {
- using default_ops::eval_ilogb;
- typename multiprecision::detail::expression<tag, A1, A2, A3, A4>::result_type arg(val);
- return eval_ilogb(arg.backend());
- }
- } //namespace multiprecision
- namespace math{
- //
- // Overload of Boost.Math functions that find the wrong overload when used with number:
- //
- namespace detail{
- template <class T> T sinc_pi_imp(T);
- template <class T> T sinhc_pi_imp(T);
- }
- template <class Backend, multiprecision::expression_template_option ExpressionTemplates>
- inline multiprecision::number<Backend, ExpressionTemplates> sinc_pi(const multiprecision::number<Backend, ExpressionTemplates>& x)
- {
- return BOOST_MP_MOVE(detail::sinc_pi_imp(x));
- }
- template <class Backend, multiprecision::expression_template_option ExpressionTemplates, class Policy>
- inline multiprecision::number<Backend, ExpressionTemplates> sinc_pi(const multiprecision::number<Backend, ExpressionTemplates>& x, const Policy&)
- {
- return BOOST_MP_MOVE(detail::sinc_pi_imp(x));
- }
- template <class Backend, multiprecision::expression_template_option ExpressionTemplates>
- inline multiprecision::number<Backend, ExpressionTemplates> sinhc_pi(const multiprecision::number<Backend, ExpressionTemplates>& x)
- {
- return BOOST_MP_MOVE(detail::sinhc_pi_imp(x));
- }
- template <class Backend, multiprecision::expression_template_option ExpressionTemplates, class Policy>
- inline multiprecision::number<Backend, ExpressionTemplates> sinhc_pi(const multiprecision::number<Backend, ExpressionTemplates>& x, const Policy&)
- {
- return BOOST_MP_MOVE(boost::math::sinhc_pi(x));
- }
- #ifdef BOOST_MSVC
- #pragma warning(pop)
- #endif
- } // namespace math
- } // namespace boost
- //
- // This has to come last of all:
- //
- #include <boost/multiprecision/detail/no_et_ops.hpp>
- #include <boost/multiprecision/detail/et_ops.hpp>
- //
- // min/max overloads:
- //
- #include <boost/multiprecision/detail/min_max.hpp>
- #endif
|