Simplify pow2 via ctor from init-list add test

This commit is contained in:
Christopher Kormanyos
2021-03-31 15:30:37 +02:00
parent 5349c05523
commit e1fbbfaebf
3 changed files with 106 additions and 279 deletions

View File

@@ -17,10 +17,13 @@
#define BOOST_MP_CPP_DEC_FLOAT_BACKEND_HPP
#include <boost/config.hpp>
#include <cstdint>
#include <limits>
#include <algorithm>
#include <array>
#include <cstdint>
#include <initializer_list>
#include <limits>
#include <boost/multiprecision/detail/hash.hpp>
#include <boost/multiprecision/number.hpp>
#include <boost/multiprecision/detail/big_lanczos.hpp>
@@ -549,6 +552,23 @@ class cpp_dec_float
}
private:
cpp_dec_float(std::initializer_list<std::uint32_t> lst,
const exponent_type e = 0,
const bool n = false) : data(),
exp(e),
neg(n),
fpclass(cpp_dec_float_finite),
prec_elem(cpp_dec_float_elem_number)
{
std::copy(lst.begin(),
lst.begin() + (std::min)(std::int32_t(lst.size()), cpp_dec_float_elem_number),
data.begin());
std::fill(data.begin() + (std::min)(std::int32_t(lst.size()), cpp_dec_float_elem_number),
data.end(),
std::uint32_t(0u));
}
static bool data_elem_is_non_zero_predicate(const std::uint32_t& d) { return (d != static_cast<std::uint32_t>(0u)); }
static bool data_elem_is_non_nine_predicate(const std::uint32_t& d) { return (d != static_cast<std::uint32_t>(cpp_dec_float::cpp_dec_float_elem_mask - 1)); }
static bool char_is_nonzero_predicate(const char& c) { return (c != static_cast<char>('0')); }
@@ -2350,284 +2370,34 @@ std::uint32_t cpp_dec_float<Digits10, ExponentType, Allocator>::div_loop_n(std::
template <unsigned Digits10, class ExponentType, class Allocator>
cpp_dec_float<Digits10, ExponentType, Allocator> cpp_dec_float<Digits10, ExponentType, Allocator>::pow2(const boost::long_long_type p)
{
// Create a static const table of p^2 for -128 < p < +128.
// Note: The size of this table must be odd-numbered and
// symmetric about 0.
static const std::array<cpp_dec_float<Digits10, ExponentType, Allocator>, 255u> p2_data =
{{cpp_dec_float("5.877471754111437539843682686111228389093327783860437607543758531392086297273635864257812500000000000e-39"),
cpp_dec_float("1.175494350822287507968736537222245677818665556772087521508751706278417259454727172851562500000000000e-38"),
cpp_dec_float("2.350988701644575015937473074444491355637331113544175043017503412556834518909454345703125000000000000e-38"),
cpp_dec_float("4.701977403289150031874946148888982711274662227088350086035006825113669037818908691406250000000000000e-38"),
cpp_dec_float("9.403954806578300063749892297777965422549324454176700172070013650227338075637817382812500000000000000e-38"),
cpp_dec_float("1.880790961315660012749978459555593084509864890835340034414002730045467615127563476562500000000000000e-37"),
cpp_dec_float("3.761581922631320025499956919111186169019729781670680068828005460090935230255126953125000000000000000e-37"),
cpp_dec_float("7.523163845262640050999913838222372338039459563341360137656010920181870460510253906250000000000000000e-37"),
cpp_dec_float("1.504632769052528010199982767644474467607891912668272027531202184036374092102050781250000000000000000e-36"),
cpp_dec_float("3.009265538105056020399965535288948935215783825336544055062404368072748184204101562500000000000000000e-36"),
cpp_dec_float("6.018531076210112040799931070577897870431567650673088110124808736145496368408203125000000000000000000e-36"),
cpp_dec_float("1.203706215242022408159986214115579574086313530134617622024961747229099273681640625000000000000000000e-35"),
cpp_dec_float("2.407412430484044816319972428231159148172627060269235244049923494458198547363281250000000000000000000e-35"),
cpp_dec_float("4.814824860968089632639944856462318296345254120538470488099846988916397094726562500000000000000000000e-35"),
cpp_dec_float("9.629649721936179265279889712924636592690508241076940976199693977832794189453125000000000000000000000e-35"),
cpp_dec_float("1.925929944387235853055977942584927318538101648215388195239938795566558837890625000000000000000000000e-34"),
cpp_dec_float("3.851859888774471706111955885169854637076203296430776390479877591133117675781250000000000000000000000e-34"),
cpp_dec_float("7.703719777548943412223911770339709274152406592861552780959755182266235351562500000000000000000000000e-34"),
cpp_dec_float("1.540743955509788682444782354067941854830481318572310556191951036453247070312500000000000000000000000e-33"),
cpp_dec_float("3.081487911019577364889564708135883709660962637144621112383902072906494140625000000000000000000000000e-33"),
cpp_dec_float("6.162975822039154729779129416271767419321925274289242224767804145812988281250000000000000000000000000e-33"),
cpp_dec_float("1.232595164407830945955825883254353483864385054857848444953560829162597656250000000000000000000000000e-32"),
cpp_dec_float("2.465190328815661891911651766508706967728770109715696889907121658325195312500000000000000000000000000e-32"),
cpp_dec_float("4.930380657631323783823303533017413935457540219431393779814243316650390625000000000000000000000000000e-32"),
cpp_dec_float("9.860761315262647567646607066034827870915080438862787559628486633300781250000000000000000000000000000e-32"),
cpp_dec_float("1.972152263052529513529321413206965574183016087772557511925697326660156250000000000000000000000000000e-31"),
cpp_dec_float("3.944304526105059027058642826413931148366032175545115023851394653320312500000000000000000000000000000e-31"),
cpp_dec_float("7.888609052210118054117285652827862296732064351090230047702789306640625000000000000000000000000000000e-31"),
cpp_dec_float("1.577721810442023610823457130565572459346412870218046009540557861328125000000000000000000000000000000e-30"),
cpp_dec_float("3.155443620884047221646914261131144918692825740436092019081115722656250000000000000000000000000000000e-30"),
cpp_dec_float("6.310887241768094443293828522262289837385651480872184038162231445312500000000000000000000000000000000e-30"),
cpp_dec_float("1.262177448353618888658765704452457967477130296174436807632446289062500000000000000000000000000000000e-29"),
cpp_dec_float("2.524354896707237777317531408904915934954260592348873615264892578125000000000000000000000000000000000e-29"),
cpp_dec_float("5.048709793414475554635062817809831869908521184697747230529785156250000000000000000000000000000000000e-29"),
cpp_dec_float("1.009741958682895110927012563561966373981704236939549446105957031250000000000000000000000000000000000e-28"),
cpp_dec_float("2.019483917365790221854025127123932747963408473879098892211914062500000000000000000000000000000000000e-28"),
cpp_dec_float("4.038967834731580443708050254247865495926816947758197784423828125000000000000000000000000000000000000e-28"),
cpp_dec_float("8.077935669463160887416100508495730991853633895516395568847656250000000000000000000000000000000000000e-28"),
cpp_dec_float("1.615587133892632177483220101699146198370726779103279113769531250000000000000000000000000000000000000e-27"),
cpp_dec_float("3.231174267785264354966440203398292396741453558206558227539062500000000000000000000000000000000000000e-27"),
cpp_dec_float("6.462348535570528709932880406796584793482907116413116455078125000000000000000000000000000000000000000e-27"),
cpp_dec_float("1.292469707114105741986576081359316958696581423282623291015625000000000000000000000000000000000000000e-26"),
cpp_dec_float("2.584939414228211483973152162718633917393162846565246582031250000000000000000000000000000000000000000e-26"),
cpp_dec_float("5.169878828456422967946304325437267834786325693130493164062500000000000000000000000000000000000000000e-26"),
cpp_dec_float("1.033975765691284593589260865087453566957265138626098632812500000000000000000000000000000000000000000e-25"),
cpp_dec_float("2.067951531382569187178521730174907133914530277252197265625000000000000000000000000000000000000000000e-25"),
cpp_dec_float("4.135903062765138374357043460349814267829060554504394531250000000000000000000000000000000000000000000e-25"),
cpp_dec_float("8.271806125530276748714086920699628535658121109008789062500000000000000000000000000000000000000000000e-25"),
cpp_dec_float("1.654361225106055349742817384139925707131624221801757812500000000000000000000000000000000000000000000e-24"),
cpp_dec_float("3.308722450212110699485634768279851414263248443603515625000000000000000000000000000000000000000000000e-24"),
cpp_dec_float("6.617444900424221398971269536559702828526496887207031250000000000000000000000000000000000000000000000e-24"),
cpp_dec_float("1.323488980084844279794253907311940565705299377441406250000000000000000000000000000000000000000000000e-23"),
cpp_dec_float("2.646977960169688559588507814623881131410598754882812500000000000000000000000000000000000000000000000e-23"),
cpp_dec_float("5.293955920339377119177015629247762262821197509765625000000000000000000000000000000000000000000000000e-23"),
cpp_dec_float("1.058791184067875423835403125849552452564239501953125000000000000000000000000000000000000000000000000e-22"),
cpp_dec_float("2.117582368135750847670806251699104905128479003906250000000000000000000000000000000000000000000000000e-22"),
cpp_dec_float("4.235164736271501695341612503398209810256958007812500000000000000000000000000000000000000000000000000e-22"),
cpp_dec_float("8.470329472543003390683225006796419620513916015625000000000000000000000000000000000000000000000000000e-22"),
cpp_dec_float("1.694065894508600678136645001359283924102783203125000000000000000000000000000000000000000000000000000e-21"),
cpp_dec_float("3.388131789017201356273290002718567848205566406250000000000000000000000000000000000000000000000000000e-21"),
cpp_dec_float("6.776263578034402712546580005437135696411132812500000000000000000000000000000000000000000000000000000e-21"),
cpp_dec_float("1.355252715606880542509316001087427139282226562500000000000000000000000000000000000000000000000000000e-20"),
cpp_dec_float("2.710505431213761085018632002174854278564453125000000000000000000000000000000000000000000000000000000e-20"),
cpp_dec_float("5.421010862427522170037264004349708557128906250000000000000000000000000000000000000000000000000000000e-20"),
cpp_dec_float("1.084202172485504434007452800869941711425781250000000000000000000000000000000000000000000000000000000e-19"),
cpp_dec_float("2.168404344971008868014905601739883422851562500000000000000000000000000000000000000000000000000000000e-19"),
cpp_dec_float("4.336808689942017736029811203479766845703125000000000000000000000000000000000000000000000000000000000e-19"),
cpp_dec_float("8.673617379884035472059622406959533691406250000000000000000000000000000000000000000000000000000000000e-19"),
cpp_dec_float("1.734723475976807094411924481391906738281250000000000000000000000000000000000000000000000000000000000e-18"),
cpp_dec_float("3.469446951953614188823848962783813476562500000000000000000000000000000000000000000000000000000000000e-18"),
cpp_dec_float("6.938893903907228377647697925567626953125000000000000000000000000000000000000000000000000000000000000e-18"),
cpp_dec_float("1.387778780781445675529539585113525390625000000000000000000000000000000000000000000000000000000000000e-17"),
cpp_dec_float("2.775557561562891351059079170227050781250000000000000000000000000000000000000000000000000000000000000e-17"),
cpp_dec_float("5.551115123125782702118158340454101562500000000000000000000000000000000000000000000000000000000000000e-17"),
cpp_dec_float("1.110223024625156540423631668090820312500000000000000000000000000000000000000000000000000000000000000e-16"),
cpp_dec_float("2.220446049250313080847263336181640625000000000000000000000000000000000000000000000000000000000000000e-16"),
cpp_dec_float("4.440892098500626161694526672363281250000000000000000000000000000000000000000000000000000000000000000e-16"),
cpp_dec_float("8.881784197001252323389053344726562500000000000000000000000000000000000000000000000000000000000000000e-16"),
cpp_dec_float("1.776356839400250464677810668945312500000000000000000000000000000000000000000000000000000000000000000e-15"),
cpp_dec_float("3.552713678800500929355621337890625000000000000000000000000000000000000000000000000000000000000000000e-15"),
cpp_dec_float("7.105427357601001858711242675781250000000000000000000000000000000000000000000000000000000000000000000e-15"),
cpp_dec_float("1.421085471520200371742248535156250000000000000000000000000000000000000000000000000000000000000000000e-14"),
cpp_dec_float("2.842170943040400743484497070312500000000000000000000000000000000000000000000000000000000000000000000e-14"),
cpp_dec_float("5.684341886080801486968994140625000000000000000000000000000000000000000000000000000000000000000000000e-14"),
cpp_dec_float("1.136868377216160297393798828125000000000000000000000000000000000000000000000000000000000000000000000e-13"),
cpp_dec_float("2.273736754432320594787597656250000000000000000000000000000000000000000000000000000000000000000000000e-13"),
cpp_dec_float("4.547473508864641189575195312500000000000000000000000000000000000000000000000000000000000000000000000e-13"),
cpp_dec_float("9.094947017729282379150390625000000000000000000000000000000000000000000000000000000000000000000000000e-13"),
cpp_dec_float("1.818989403545856475830078125000000000000000000000000000000000000000000000000000000000000000000000000e-12"),
cpp_dec_float("3.637978807091712951660156250000000000000000000000000000000000000000000000000000000000000000000000000e-12"),
cpp_dec_float("7.275957614183425903320312500000000000000000000000000000000000000000000000000000000000000000000000000e-12"),
cpp_dec_float("1.455191522836685180664062500000000000000000000000000000000000000000000000000000000000000000000000000e-11"),
cpp_dec_float("2.910383045673370361328125000000000000000000000000000000000000000000000000000000000000000000000000000e-11"),
cpp_dec_float("5.820766091346740722656250000000000000000000000000000000000000000000000000000000000000000000000000000e-11"),
cpp_dec_float("1.164153218269348144531250000000000000000000000000000000000000000000000000000000000000000000000000000e-10"),
cpp_dec_float("2.328306436538696289062500000000000000000000000000000000000000000000000000000000000000000000000000000e-10"),
cpp_dec_float("4.656612873077392578125000000000000000000000000000000000000000000000000000000000000000000000000000000e-10"),
cpp_dec_float("9.313225746154785156250000000000000000000000000000000000000000000000000000000000000000000000000000000e-10"),
cpp_dec_float("1.862645149230957031250000000000000000000000000000000000000000000000000000000000000000000000000000000e-9"),
cpp_dec_float("3.725290298461914062500000000000000000000000000000000000000000000000000000000000000000000000000000000e-9"),
cpp_dec_float("7.450580596923828125000000000000000000000000000000000000000000000000000000000000000000000000000000000e-9"),
cpp_dec_float("1.490116119384765625000000000000000000000000000000000000000000000000000000000000000000000000000000000e-8"),
cpp_dec_float("2.980232238769531250000000000000000000000000000000000000000000000000000000000000000000000000000000000e-8"),
cpp_dec_float("5.960464477539062500000000000000000000000000000000000000000000000000000000000000000000000000000000000e-8"),
cpp_dec_float("1.192092895507812500000000000000000000000000000000000000000000000000000000000000000000000000000000000e-7"),
cpp_dec_float("2.384185791015625000000000000000000000000000000000000000000000000000000000000000000000000000000000000e-7"),
cpp_dec_float("4.768371582031250000000000000000000000000000000000000000000000000000000000000000000000000000000000000e-7"),
cpp_dec_float("9.536743164062500000000000000000000000000000000000000000000000000000000000000000000000000000000000000e-7"),
cpp_dec_float("1.907348632812500000000000000000000000000000000000000000000000000000000000000000000000000000000000000e-6"),
cpp_dec_float("3.814697265625000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e-6"),
cpp_dec_float("7.629394531250000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e-6"),
cpp_dec_float("0.000015258789062500000000000000000000000000000000000000000000000000000000000000000000000000000000000000"),
cpp_dec_float("0.000030517578125000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"),
cpp_dec_float("0.000061035156250000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"),
cpp_dec_float("0.000122070312500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"),
cpp_dec_float("0.000244140625000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"),
cpp_dec_float("0.000488281250000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"),
cpp_dec_float("0.000976562500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"),
cpp_dec_float("0.001953125000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"),
cpp_dec_float("0.003906250000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"),
cpp_dec_float("0.007812500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"),
cpp_dec_float("0.01562500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"),
cpp_dec_float("0.03125000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"),
cpp_dec_float("0.06250000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"),
cpp_dec_float("0.125"),
cpp_dec_float("0.25"),
cpp_dec_float("0.5"),
one(),
two(),
cpp_dec_float(static_cast<boost::ulong_long_type>(4)),
cpp_dec_float(static_cast<boost::ulong_long_type>(8)),
cpp_dec_float(static_cast<boost::ulong_long_type>(16)),
cpp_dec_float(static_cast<boost::ulong_long_type>(32)),
cpp_dec_float(static_cast<boost::ulong_long_type>(64)),
cpp_dec_float(static_cast<boost::ulong_long_type>(128)),
cpp_dec_float(static_cast<boost::ulong_long_type>(256)),
cpp_dec_float(static_cast<boost::ulong_long_type>(512)),
cpp_dec_float(static_cast<boost::ulong_long_type>(1024)),
cpp_dec_float(static_cast<boost::ulong_long_type>(2048)),
cpp_dec_float(static_cast<boost::ulong_long_type>(4096)),
cpp_dec_float(static_cast<boost::ulong_long_type>(8192)),
cpp_dec_float(static_cast<boost::ulong_long_type>(16384)),
cpp_dec_float(static_cast<boost::ulong_long_type>(32768)),
cpp_dec_float(static_cast<boost::ulong_long_type>(65536)),
cpp_dec_float(static_cast<boost::ulong_long_type>(131072)),
cpp_dec_float(static_cast<boost::ulong_long_type>(262144)),
cpp_dec_float(static_cast<boost::ulong_long_type>(524288)),
cpp_dec_float(static_cast<std::uint64_t>(1uL << 20u)),
cpp_dec_float(static_cast<std::uint64_t>(1uL << 21u)),
cpp_dec_float(static_cast<std::uint64_t>(1uL << 22u)),
cpp_dec_float(static_cast<std::uint64_t>(1uL << 23u)),
cpp_dec_float(static_cast<std::uint64_t>(1uL << 24u)),
cpp_dec_float(static_cast<std::uint64_t>(1uL << 25u)),
cpp_dec_float(static_cast<std::uint64_t>(1uL << 26u)),
cpp_dec_float(static_cast<std::uint64_t>(1uL << 27u)),
cpp_dec_float(static_cast<std::uint64_t>(1uL << 28u)),
cpp_dec_float(static_cast<std::uint64_t>(1uL << 29u)),
cpp_dec_float(static_cast<std::uint64_t>(1uL << 30u)),
cpp_dec_float(static_cast<std::uint64_t>(1uL << 31u)),
cpp_dec_float(static_cast<std::uint64_t>(1uLL << 32u)),
cpp_dec_float(static_cast<std::uint64_t>(1uLL << 33u)),
cpp_dec_float(static_cast<std::uint64_t>(1uLL << 34u)),
cpp_dec_float(static_cast<std::uint64_t>(1uLL << 35u)),
cpp_dec_float(static_cast<std::uint64_t>(1uLL << 36u)),
cpp_dec_float(static_cast<std::uint64_t>(1uLL << 37u)),
cpp_dec_float(static_cast<std::uint64_t>(1uLL << 38u)),
cpp_dec_float(static_cast<std::uint64_t>(1uLL << 39u)),
cpp_dec_float(static_cast<std::uint64_t>(1uLL << 40u)),
cpp_dec_float(static_cast<std::uint64_t>(1uLL << 41u)),
cpp_dec_float(static_cast<std::uint64_t>(1uLL << 42u)),
cpp_dec_float(static_cast<std::uint64_t>(1uLL << 43u)),
cpp_dec_float(static_cast<std::uint64_t>(1uLL << 44u)),
cpp_dec_float(static_cast<std::uint64_t>(1uLL << 45u)),
cpp_dec_float(static_cast<std::uint64_t>(1uLL << 46u)),
cpp_dec_float(static_cast<std::uint64_t>(1uLL << 47u)),
cpp_dec_float(static_cast<std::uint64_t>(1uLL << 48u)),
cpp_dec_float(static_cast<std::uint64_t>(1uLL << 49u)),
cpp_dec_float(static_cast<std::uint64_t>(1uLL << 50u)),
cpp_dec_float(static_cast<std::uint64_t>(1uLL << 51u)),
cpp_dec_float(static_cast<std::uint64_t>(1uLL << 52u)),
cpp_dec_float(static_cast<std::uint64_t>(1uLL << 53u)),
cpp_dec_float(static_cast<std::uint64_t>(1uLL << 54u)),
cpp_dec_float(static_cast<std::uint64_t>(1uLL << 55u)),
cpp_dec_float(static_cast<std::uint64_t>(1uLL << 56u)),
cpp_dec_float(static_cast<std::uint64_t>(1uLL << 57u)),
cpp_dec_float(static_cast<std::uint64_t>(1uLL << 58u)),
cpp_dec_float(static_cast<std::uint64_t>(1uLL << 59u)),
cpp_dec_float(static_cast<std::uint64_t>(1uLL << 60u)),
cpp_dec_float(static_cast<std::uint64_t>(1uLL << 61u)),
cpp_dec_float(static_cast<std::uint64_t>(1uLL << 62u)),
cpp_dec_float(static_cast<std::uint64_t>(1uLL << 63u)),
cpp_dec_float("1.844674407370955161600000000000000000000000000000000000000000000000000000000000000000000000000000000e19"),
cpp_dec_float("3.689348814741910323200000000000000000000000000000000000000000000000000000000000000000000000000000000e19"),
cpp_dec_float("7.378697629483820646400000000000000000000000000000000000000000000000000000000000000000000000000000000e19"),
cpp_dec_float("1.475739525896764129280000000000000000000000000000000000000000000000000000000000000000000000000000000e20"),
cpp_dec_float("2.951479051793528258560000000000000000000000000000000000000000000000000000000000000000000000000000000e20"),
cpp_dec_float("5.902958103587056517120000000000000000000000000000000000000000000000000000000000000000000000000000000e20"),
cpp_dec_float("1.180591620717411303424000000000000000000000000000000000000000000000000000000000000000000000000000000e21"),
cpp_dec_float("2.361183241434822606848000000000000000000000000000000000000000000000000000000000000000000000000000000e21"),
cpp_dec_float("4.722366482869645213696000000000000000000000000000000000000000000000000000000000000000000000000000000e21"),
cpp_dec_float("9.444732965739290427392000000000000000000000000000000000000000000000000000000000000000000000000000000e21"),
cpp_dec_float("1.888946593147858085478400000000000000000000000000000000000000000000000000000000000000000000000000000e22"),
cpp_dec_float("3.777893186295716170956800000000000000000000000000000000000000000000000000000000000000000000000000000e22"),
cpp_dec_float("7.555786372591432341913600000000000000000000000000000000000000000000000000000000000000000000000000000e22"),
cpp_dec_float("1.511157274518286468382720000000000000000000000000000000000000000000000000000000000000000000000000000e23"),
cpp_dec_float("3.022314549036572936765440000000000000000000000000000000000000000000000000000000000000000000000000000e23"),
cpp_dec_float("6.044629098073145873530880000000000000000000000000000000000000000000000000000000000000000000000000000e23"),
cpp_dec_float("1.208925819614629174706176000000000000000000000000000000000000000000000000000000000000000000000000000e24"),
cpp_dec_float("2.417851639229258349412352000000000000000000000000000000000000000000000000000000000000000000000000000e24"),
cpp_dec_float("4.835703278458516698824704000000000000000000000000000000000000000000000000000000000000000000000000000e24"),
cpp_dec_float("9.671406556917033397649408000000000000000000000000000000000000000000000000000000000000000000000000000e24"),
cpp_dec_float("1.934281311383406679529881600000000000000000000000000000000000000000000000000000000000000000000000000e25"),
cpp_dec_float("3.868562622766813359059763200000000000000000000000000000000000000000000000000000000000000000000000000e25"),
cpp_dec_float("7.737125245533626718119526400000000000000000000000000000000000000000000000000000000000000000000000000e25"),
cpp_dec_float("1.547425049106725343623905280000000000000000000000000000000000000000000000000000000000000000000000000e26"),
cpp_dec_float("3.094850098213450687247810560000000000000000000000000000000000000000000000000000000000000000000000000e26"),
cpp_dec_float("6.189700196426901374495621120000000000000000000000000000000000000000000000000000000000000000000000000e26"),
cpp_dec_float("1.237940039285380274899124224000000000000000000000000000000000000000000000000000000000000000000000000e27"),
cpp_dec_float("2.475880078570760549798248448000000000000000000000000000000000000000000000000000000000000000000000000e27"),
cpp_dec_float("4.951760157141521099596496896000000000000000000000000000000000000000000000000000000000000000000000000e27"),
cpp_dec_float("9.903520314283042199192993792000000000000000000000000000000000000000000000000000000000000000000000000e27"),
cpp_dec_float("1.980704062856608439838598758400000000000000000000000000000000000000000000000000000000000000000000000e28"),
cpp_dec_float("3.961408125713216879677197516800000000000000000000000000000000000000000000000000000000000000000000000e28"),
cpp_dec_float("7.922816251426433759354395033600000000000000000000000000000000000000000000000000000000000000000000000e28"),
cpp_dec_float("1.584563250285286751870879006720000000000000000000000000000000000000000000000000000000000000000000000e29"),
cpp_dec_float("3.169126500570573503741758013440000000000000000000000000000000000000000000000000000000000000000000000e29"),
cpp_dec_float("6.338253001141147007483516026880000000000000000000000000000000000000000000000000000000000000000000000e29"),
cpp_dec_float("1.267650600228229401496703205376000000000000000000000000000000000000000000000000000000000000000000000e30"),
cpp_dec_float("2.535301200456458802993406410752000000000000000000000000000000000000000000000000000000000000000000000e30"),
cpp_dec_float("5.070602400912917605986812821504000000000000000000000000000000000000000000000000000000000000000000000e30"),
cpp_dec_float("1.014120480182583521197362564300800000000000000000000000000000000000000000000000000000000000000000000e31"),
cpp_dec_float("2.028240960365167042394725128601600000000000000000000000000000000000000000000000000000000000000000000e31"),
cpp_dec_float("4.056481920730334084789450257203200000000000000000000000000000000000000000000000000000000000000000000e31"),
cpp_dec_float("8.112963841460668169578900514406400000000000000000000000000000000000000000000000000000000000000000000e31"),
cpp_dec_float("1.622592768292133633915780102881280000000000000000000000000000000000000000000000000000000000000000000e32"),
cpp_dec_float("3.245185536584267267831560205762560000000000000000000000000000000000000000000000000000000000000000000e32"),
cpp_dec_float("6.490371073168534535663120411525120000000000000000000000000000000000000000000000000000000000000000000e32"),
cpp_dec_float("1.298074214633706907132624082305024000000000000000000000000000000000000000000000000000000000000000000e33"),
cpp_dec_float("2.596148429267413814265248164610048000000000000000000000000000000000000000000000000000000000000000000e33"),
cpp_dec_float("5.192296858534827628530496329220096000000000000000000000000000000000000000000000000000000000000000000e33"),
cpp_dec_float("1.038459371706965525706099265844019200000000000000000000000000000000000000000000000000000000000000000e34"),
cpp_dec_float("2.076918743413931051412198531688038400000000000000000000000000000000000000000000000000000000000000000e34"),
cpp_dec_float("4.153837486827862102824397063376076800000000000000000000000000000000000000000000000000000000000000000e34"),
cpp_dec_float("8.307674973655724205648794126752153600000000000000000000000000000000000000000000000000000000000000000e34"),
cpp_dec_float("1.661534994731144841129758825350430720000000000000000000000000000000000000000000000000000000000000000e35"),
cpp_dec_float("3.323069989462289682259517650700861440000000000000000000000000000000000000000000000000000000000000000e35"),
cpp_dec_float("6.646139978924579364519035301401722880000000000000000000000000000000000000000000000000000000000000000e35"),
cpp_dec_float("1.329227995784915872903807060280344576000000000000000000000000000000000000000000000000000000000000000e36"),
cpp_dec_float("2.658455991569831745807614120560689152000000000000000000000000000000000000000000000000000000000000000e36"),
cpp_dec_float("5.316911983139663491615228241121378304000000000000000000000000000000000000000000000000000000000000000e36"),
cpp_dec_float("1.063382396627932698323045648224275660800000000000000000000000000000000000000000000000000000000000000e37"),
cpp_dec_float("2.126764793255865396646091296448551321600000000000000000000000000000000000000000000000000000000000000e37"),
cpp_dec_float("4.253529586511730793292182592897102643200000000000000000000000000000000000000000000000000000000000000e37"),
cpp_dec_float("8.507059173023461586584365185794205286400000000000000000000000000000000000000000000000000000000000000e37"),
cpp_dec_float("1.701411834604692317316873037158841057280000000000000000000000000000000000000000000000000000000000000e38")}};
static const std::array<cpp_dec_float<Digits10, ExponentType, Allocator>, 9u> local_pow2_data =
{{
cpp_dec_float<Digits10, ExponentType, Allocator>({ 6250000u }, -8),
cpp_dec_float<Digits10, ExponentType, Allocator>({ 12500000u }, -8),
cpp_dec_float<Digits10, ExponentType, Allocator>({ 25000000u }, -8),
cpp_dec_float<Digits10, ExponentType, Allocator>({ 50000000u }, -8),
cpp_dec_float<Digits10, ExponentType, Allocator>({ 1u }),
cpp_dec_float<Digits10, ExponentType, Allocator>({ 2u }),
cpp_dec_float<Digits10, ExponentType, Allocator>({ 4u }),
cpp_dec_float<Digits10, ExponentType, Allocator>({ 8u }),
cpp_dec_float<Digits10, ExponentType, Allocator>({ 16u })
}};
if ((p > static_cast<boost::long_long_type>(-128)) && (p < static_cast<boost::long_long_type>(+128)))
{
return p2_data[static_cast<std::size_t>(p + ((p2_data.size() - 1u) / 2u))];
}
else
{
// Compute and return 2^p.
if (p < static_cast<boost::long_long_type>(0))
{
return pow2(static_cast<boost::long_long_type>(-p)).calculate_inv();
}
else
{
cpp_dec_float<Digits10, ExponentType, Allocator> t;
default_ops::detail::pow_imp(t, two(), p, std::integral_constant<bool, true>());
return t;
}
}
cpp_dec_float<Digits10, ExponentType, Allocator> t;
if (p < -4) { default_ops::detail::pow_imp(t, local_pow2_data[3u], boost::ulong_long_type(-p), std::integral_constant<bool, false>()); }
else if (p == -4) { t = local_pow2_data[0u]; }
else if (p == -3) { t = local_pow2_data[1u]; }
else if (p == -2) { t = local_pow2_data[2u]; }
else if (p == -1) { t = local_pow2_data[3u]; }
else if (p == 0) { t = local_pow2_data[4u]; }
else if (p == 1) { t = local_pow2_data[5u]; }
else if (p == 2) { t = local_pow2_data[6u]; }
else if (p == 3) { t = local_pow2_data[7u]; }
else if (p == 4) { t = local_pow2_data[8u]; }
else { default_ops::detail::pow_imp(t, local_pow2_data[5u], boost::ulong_long_type(p), std::integral_constant<bool, false>()); }
return t;
}
template <unsigned Digits10, class ExponentType, class Allocator>

View File

@@ -1034,6 +1034,7 @@ test-suite misc :
[ run git_issue_248.cpp ]
[ run git_issue_265.cpp : : : [ check-target-builds ../config//has_mpfr : <source>gmp <source>mpfr : <build>no ] ]
[ run git_issue_277.cpp ]
[ run git_issue_313.cpp ]
[ compile git_issue_98.cpp :
[ check-target-builds ../config//has_float128 : <define>TEST_FLOAT128 <source>quadmath : ]
[ check-target-builds ../config//has_gmp : <define>TEST_GMP <source>gmp : ]

56
test/git_issue_313.cpp Normal file
View File

@@ -0,0 +1,56 @@
///////////////////////////////////////////////////////////////////////////////
// Copyright 2021 Christopher Kormanyos. 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)
#include <iomanip>
#include <sstream>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include "test.hpp"
void test()
{
using local_decfloat_type = boost::multiprecision::cpp_dec_float_100;
bool result0_is_ok = false;
bool result1_is_ok = false;
{
const local_decfloat_type test = pow(local_decfloat_type{2}, 30) * pow(local_decfloat_type{10}, -3);
std::stringstream strm;
strm << std::setprecision(std::numeric_limits<local_decfloat_type>::digits10)
<< std::fixed
<< test;
result0_is_ok =
(strm.str() == "1073741.8240000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000");
}
{
const local_decfloat_type test(0.625F);
std::stringstream strm;
strm << std::setprecision(std::numeric_limits<local_decfloat_type>::digits10)
<< std::fixed
<< test;
result1_is_ok =
(strm.str() == "0.6250000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000");
}
const bool result_is_ok = (result0_is_ok && result1_is_ok);
BOOST_CHECK_EQUAL(result_is_ok, true);
}
int main()
{
test();
return boost::report_errors();
}