Files
multiprecision/test/test_exp.cpp
John Maddock b8a60ca6ca Rename "big_number*" to "mp_number*".
[SVN r74671]
2011-10-03 17:15:55 +00:00

130 lines
23 KiB
C++

///////////////////////////////////////////////////////////////
// Copyright Christopher Kormanyos 2002 - 2011.
// 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_
//
// This work is based on an earlier work:
// "Algorithm 910: A Portable C++ Multiple-Precision System for Special-Function Calculations",
// in ACM TOMS, {VOL 37, ISSUE 4, (February 2011)} (C) ACM, 2011. http://doi.acm.org/10.1145/1916461.1916469
#include <boost/detail/lightweight_test.hpp>
#include <boost/array.hpp>
#if !defined(TEST_MPF50) && !defined(TEST_MPF) && !defined(TEST_BACKEND) && !defined(TEST_MPZ) && !defined(TEST_E_FLOAT) && !defined(TEST_MPFR) && !defined(TEST_MPFR_50) && !defined(TEST_MPQ)
# define TEST_MPF50
//# define TEST_MPF
# define TEST_BACKEND
# define TEST_E_FLOAT
#ifdef _MSC_VER
#pragma message("CAUTION!!: No backend type specified so testing everything.... this will take some time!!")
#endif
#ifdef __GNUC__
#pragma warning "CAUTION!!: No backend type specified so testing everything.... this will take some time!!"
#endif
#endif
#if defined(TEST_MPF50)
#include <boost/multiprecision/gmp.hpp>
#endif
#ifdef TEST_BACKEND
#include <boost/multiprecision/concepts/mp_number_architypes.hpp>
#endif
#ifdef TEST_E_FLOAT
#include <boost/multiprecision/e_float.hpp>
#endif
template <class T>
void test()
{
static const boost::array<T, 51u> data =
{{
T("1."),
T("9.4774758759621877024211675170518456366884502921505415491512637467314221915954853431757689726613032841249599156149038435317513116309445221664968991934479367736962368912070497862135887440758964938422498610719192114666493107120133053433933470080716434904854804591983841381870449665144170011709399012693158566138960223723364102555657731121349862591746773752353141675856300389702807704522952296232409058995e76"),
T("8.9822548979445237099762393639075561506833309483454509238768979587574644012197081949903511127689329087920328909235374785049128571553031890973238724279779592658729244759890277209350767466719784199679796679076195510817453034019585841414276969807276603422838152196159579020392165208404938697706742432405072185394955217454998873094186010667116964062108348411120353180844989880619261736047981860732797930644e153"),
T("8.5129104107012425752479825179539835555229492815662784863307311391672159207488925610548399363157976134510028424514441050609545913878842822386467301206413201029623476769026205205033685817764924800488232855250724008684495915251712280130842326233108250199883461186105839257510617980635806077595457588382413118792469142952313318664506759914894358735407111388609445312410411768354469087810933243701518863094e230"),
T("8.068090305164838604842549259891290171124821324687615632762765947633748868268417454336601924388552143324691924117594027902831510205350887969459808981202607973311868683121411298688279975061789109893607155133896078457388071886309741456291076644788440713510519219662121306330169119711707661687366546188062768141595534496102806873207221787877336040297603480708540379623897605936160066148763011880191621869e307"),
T("7.6465131232284163049316971133689488893295181895713899732751818669118734787914222264428338943260471340902326391726435840091710708695473968075461348860956049684669812738873320847453110965340325334947107583391780473997991426818290712114444252407495208024999404559898062464415917818325137468413597347923471238518514205589873079135934550659222795036544923795379322078022614498712288611880678752777952015152e384"),
T("7.2469643660625598538019258566517379445511821515071121090548187005319333633673122846436747032786828698818049511140660969044546275219845755939273078671198074959632409619498154244698031034440156360197935648334627868546857888857494388700626844388689389822377033582839158752694909185487984346545185318857120307481828458998400770240716997943805543726689069264680883497414036698656007667489582007899001829547e461"),
T("6.8682929953315519748061086577140456531398698780106027012062193513974157724673145902422782875956445003426789107235281687028397040131570497762100824722937078427155330107861397918035390454699657109557435638021678699307825502445861009401889929556587580492784546438388738373098175168819944606997023434060917962050793068854615280653706806955349426233710968944941108524201897185239272184650924550094159165184e538"),
T("6.5094081172294858524266967236074125271501239931616451822606100184551967070123942960365792762875516947968906251960679962384234952003522496976521459488146737312705400397630193900773373659538930712803305054506593414261773420168174852358519629345494258520616169148118576343286498482213483702930624725613384454163670114665649516148482263466492457979074135245336808430956247276655511233636218374141666023272e615"),
T("6.1692758397834896445466565257129421525132737513712327204187797947854551109008575685822530235797715953977744784785550340516715598557366923302859690730271083925820960776432604991610505575079802877181530212126674968757212631217826462154883556827312493006938669407561453082743084716913350560632423093917610154998589982600001382392313694022445670347030705319164552170150291848012351937100953890036300105871e692"),
T("5.8469162943704389675386957200432422884983339114040809517125791843529698266123366406953460141383587627250027572569096847362363831549584856898467181999391413025165420386358087621054569033111477610047027055333381725754117391518041977019653549862107958916803866421362184761931585219445620128589637254918343555371393128431807715170682738452071618887807426604132681626154765999537959315476068213542621180322e769"),
T("5.5414008128666064583537076240692868933072418197965454555020420111392626928160330156411498052861994284073777041588578343924444729815070056061660603933966757946018263861283152733720240516173400789600385493382166372543010812180148374708916504088803663809915284719654025586373106511403877362732360653577732630088912763232117614936657631128626622480330571961457177097015572841013819523862056676302123590835e846"),
T("5.251849252298052001849336634596605624932615050587242126709230836437099642948552827155317681622985673796485738044339684860221300378963566030058095552267153924938244515158005499605803770525751057401451830019036344558051163875818942505974131107483204115256933385945743955379487500587051829522367096042702717218823641765552373631712919055254215952997997242218608413439149796128454371169305737207513128807e923"),
T("4.9774274592844840922553532523399895707687997944019016434779659339099599495175571066749191102647610895707050400315564576144486939330191822264020831239376081750240177080224855259905972322795436336044718080591030837173922087243357258882189147341298494439853073189728114774501846930002388008365636203966891211742478022416179489779372415512232819505675629656011956781715868427072593283654666589611808073581e1000"),
T("4.7173448669720462237188351865970295455238511572394280863649015756105641752582788447957398889951756658763666977964561080316844537247511176975067430907677318411628894592131659609314519705065696036773840172243882880973707032036317239517638220758446197062685014773982890420289865519060688689357420655259758455221621133987780001331686741987234669397265361446155200793231408284664030082289902730362397848561e1077"),
T("4.4708522175321623603760234543012160551233097542464376709898701080016161641305114803775155211008103406608130900779618211357983931505100150872036597773168012401952663951774811462178950982356754934520420952750636967336804589186617110996219414674248378823188434472686833719446877071963169624353004701806734777657062069056499506562750389037932975870328903604743080312421901044848764763554120280608069622747e1154"),
T("4.2372394036653119830098671356758800877704381245840070556972166015743494177406662087025674510726553612407773483679793826805395046830522912774907458645315666657109679555711516123219895337097780310478450990346378570451984628571968728862717021688464671183102216087482134582783233462788612276436433844843113340117661068800967697425945952185565756591509948286825746552902121339188076398953061591657510445066e1231"),
T("4.0158334228914400539745590178164794975437536606699818222034254004811114067672490994749378759633661049912208598371211928081486311385567301424145253923797915452955822482631387668888916584389521441919397036718125302432512547147127924813280974253855801042782701987819292329831163944563371019697555352578545825707188652122309957602602328073674784142564935616256457537057261596233390671696504290741500824325e1308"),
T("3.8059964387336281390030628447736918731950638905889859981670562575013579651080893378643261418615597248563793905721216409752849171768325689975193281668646707475626612103018049529414972031338274254587787676115938524624210494070325582923806604462125023016462957768718261849099968552115528194693187665051765401859680442459296615169707213689087378346661673375123735787731940984618937841286808679717684045601e1385"),
T("3.6071239432095959207430930181651037268769528665018877695729199475196601891740487861223796136712863819929038760151135883635004445484745979300525669576636222972289788167180919942439736319800034914890005316195880400774555618160525047519091232763877112549157224779431406160698065686340819410841933246641650269061746492965033484737240772388735312991521074123198706383278511433856343165625103198269467277045e1462"),
T("3.4186430153374545706606299190728926303831987493039531531525792716113836020659611610272471306951869724846396516471297290706571995664799809535296646907832639466194597092728987006624017784246439039721439649240230770188576832674257817653601012003365792748252816491311084472983584896236685446078049796997495088275235014482876422624572733765422511563417424717976734285541485840205576333292292629705898026712e1539"),
T("3.2400106706387356945670320428646200776993383104555861757828941469924476740373605793183477572742076241032829759659681490962141240145141581865097423924646660398220529435794134651336421615115538294144878610322957162996489151882559706577258950380659727211777291935939480320782190247511227788798308670601955093205987496538797636913777784465756466432434857195432171054628069149765836567108796606518876161411e1616"),
T("3.0707122968838686808762365976116630656317083977116234783051460697759202764413714416029446981398815846396774097846142086219585484898425128945637835965609311626781498745013601665202311991073858493014761614369526954113562966924343632898676526247434944353812116870344357416617678601015459053297989079589299509864871767253387806087559388044642587983434307487581273247444950986227978405821984630380335522999e1693"),
T("2.9102601715737304709407721855237845605215030467786367061140857045899101530013173126178764480141553804302726818509771061464761826116800985901969508353958187973711321043157119127861178260598364278447637770099918746816176840436194047559028684276346030463240065993810821297209992114976352565659256401456824943396501998104720348581392556524094012469848383344186510494751840542956622168648051127134605419049e1770"),
T("2.7581920568863607870027917438011158114732314795167030242749419621017647849448607372158405505948973604056597946655107017870542301435918693041804847351891423642078041222831042196395295270728440674479791111077414832394734353235316069842707878669474381815671796103458710433178002392178092638286037259141627485462419803958568427330260813821541600701534519737633707025577914995456788692103051108422425375408e1847"),
T("2.6140698680411010453416773970464335103997599275990557963505882402750774237538007727638017837647068698785550358186768104621786728298395959017968646659450681758854495815775051287976515457472752962763600118692278131638936053170621574407487878235430394106909122081064770622396768825200987517033934258510550698555707917420074884651382528854596786633229647900291304513978131386770725311082555006911467864447e1924"),
T("2.4774784112439194545961900234630392526964078574399033336208722389562768176981620423625796094049751937688183037372271145640392552111592856112971332411543527668988982189213357069766999642690629174087636518790443153236463649626796203655474042490645756106046469120382604539074502111722789325269571247140534108791736500356851939956197404652273603941323630209215720013693452205022518765760329070842616941046e2001"),
T("2.3480241875781374631691380066790792771892564869650825534762414159728147468382334513664061092463982019282596608230957530311211307328143974085747420399537158037724095218243991423228023444859379580883072434670530040478491744472651118485401814194033214517221050352934587398275852096346826910101105240186236412184656659382535831384647508927079089332738325920621748164698159861195345140124576533260099531818e2078"),
T("2.2253342593947512482894343051033346460553514685284868064761586762995307539088982139722858486639592417618934607300618026000707839555068686077050219383701773511012374743383996188227317471958686041947524249098686209176989223885354176417280209218097978029585985115430634192732411379059159347252165834440501107479076728537702323035968171445551276815488702844227415317075032577967598705531043548190902240163e2155"),
T("2.1090551759365936315455394763107180892546255311406814474807735913225599344136347904154067215849740466098616361782897296314219278981058583564722586146448606213894635847184726562609032113220295749441955633109205157660265084141265451792574855174504712050982199997333601700242161381263233947649564996752502282300661121812212460958677667464307539559824119716390823776389116062024328503582458296404661030724e2232"),
T("1.9988519551012253626665391606414160629542055458014061990042537070247177860439177457869686789999953426516957430680890680964654190474258046504015466343786427551666546734635351226235742257396796694133189981279578839780058454761985247524191011603418127443226153000194710273722264940047399226885184129896957721196752811974521300721776877014427959949663663916026486491804231252409445050163051004298903230857e2309"),
T("1.8944071184091717327769157288694214491666404740796335627119828665408788464610207014827128441011823347031833774554689560285831180446909490973719926278454999562091766786964617295311248054209296251829365565657637585794799613184943543642149302253502921625588487967178044987717063245419475512579228948005151251220172269440562559442067650076109382783512605616677262078725150593936302571039602645533145833688e2386"),
T("1.795419776397396870883759116489769402541419469341753006054859662887039319928613872577712647027984056309170986725948997439220662114370977055801553872855064859465160778064610757538797519726695741862251510315436821959386698539808251950372887792620010350735505164024826909107013909479283953771859666151170337965452357673457347076929518296009792647791360547551255623795595827532506478122285622521680723198e2463"),
T("1.7016047618031754086134654579111810617120348758710143771069305417445489516040399750813776000705885685499141312138983442910516360247333185628492894202543743484367527766696250509432364995620305699351629185845681107616307847503246334638085810705895758535310625200703209004562084637734409371699916561240290054446464424202718339701400783109986719573562903857763873129540597357986671423745013710023231651329e2540"),
T("1.6126918080411979609715701452747988352165611850041775296367567768434358897691585163763723200113910842065988232661477200356230494761269971912897846125539659247231849257562594838887825972384334125491030803473533770400171029646043156961751894914511918427584075989532586054167207076781379343029365612771751032986978351517889027305091647604463730801257161289620542661422918279902166096709193161081148394122e2617"),
T("1.5284247706072296906699846404669034984154826955667742337840818347648901587881658504557814138346370867446936528153779291440974222875392035177334798180491517730019043230270100162475021422595011732593995371616778833697035670363475607783524853038032682034425785665657694174408203262209215616997795015596310706005669556487099297258112136814894205842056567712320200105413268352722573109566950626278687930372e2694"),
T("1.4485608891653060012262662362934733670202669964729350005811103752638169264554793857733858200215714810347904907192143845165275567906538821978702789157309454852049290295796799965552485868312721404394594588565776908022341972957647259592625133676589615774282958675900831935353271514314162851566868342929429856058517618472279436082944777949290121160320329701032110206134281440294897812652040954276090507017e2771"),
T("1.3728700881926523987377787943233319240491435703774938014541289523016635231812897840380838214278403055812374826352836064462692100642008102237346834361992329341687329019897351648991658099511836287726680508579879561481258870568846143059698287552784017902374151003189575311983375350280503953688511659632273800604956059446835976326153862663879531247057664632472283459374059559730646129713043045914280036191e2848"),
T("1.3011343141675944177179012805391104090720749087989014559756238032895645009279901485614947480934542467295834329661576448972096487118616044389963400689819864304760083535444189376011062378910379399366999838002995455575533727570818112349042088887223540611741471886797668792340331999553880029276216552340520965077802458183989229739403020238639120027067012696404307310649637683517662985846874429681252694077e2925"),
T("1.233146907390998223699634116604196321303527338063194018635704429203476960154098702362306563055636743760637784824497167438582308977860508068061535923688719183483752799354995864650650838160287374006896203951016533958052684442079538436867039485265319300786722392487965089753674979550869797200905652353584841188368624722200329909417714522575076225901000950862809939580119622301038231535752640718531560503e3002"),
T("1.1687120066315563646851448403936869404385185807787910322183199726441909641701499694514314549503826524393274595370652625335780618101237045988306992211747149512692179708353068119406926898226236555424247858876734064642321276408994327805695378682350680381138120637976561992552983027128491109399057399204806734536960608717759169335403208815710861794231703278779715979117164411304050798514670593787652928186e3079"),
T("1.1076439848797935780459011708913459693873418501614440121893411516856155264044888921508915048116297777621412439748701311029558308262037962091076982761455032906089728939898793892875302522325111709336468475276025046431105649997619822361542676063571655376547693673809133715806114929084161165591159275087382589295164718676930405790416367425834825705001722880024431488182592089567213871253363437453881724614e3156"),
T("1.0497669145852869831822072985740561681644437400018209440593094671016875295492661221847443008152631201881081765740915849038613188076178075126640018128968505236614758225634907922757204588825919348747289334952559508285340900441213069663101271469490908846474748126491486153897933707558113462272399019590825684419149149971088390644736001969102418531930304048460671867178170486969430030044866749941411652221e3233"),
T("9.9491406083653158286834756917422021600764727853686312719802358420566982531788421914469238540915616504216223401740335370367923898274605089490332650511788075886198714135795808528419557141582217964579360685402741569208063074313253490838482414281367060197950065504143914001338572155467333984661503453898847902871372714795379743025547542723839248318892138759596907306100969830936341255021634987471789706941e3309"),
T("9.42927401023380446961314339401657458785389811652244742482194123119943160577946366372207045050095290781679375214307398843926493195734487944624333413228893399732976728321980799677091653454804065271499274601941255651159823827574140068157063214410760869314717732028275496245648005191215048930881016330693755275282258597115402181603925122663256538590166426964332556533036059527784227962722441198371434037e3386"),
T("8.9365716959828116465632229827533775010309573979010794366666818430433566556286774474031057786888009871925254918684981245088107384317036889752292156920146379694165987770273470926340201197874812456173862271880689137375502421735431888891334269040972307308842443051934967463204037988999112477683156448819368015441070611711599827182978835927951062291039453298334013800388495719125476482150507255562932471987e3463"),
T("8.4696142662483591182651710363149061965529671414187214114508986504580419620532836415592194561692587545892671733647852519586965260182156246891106882514113059675737245160959965677478337885852837584798963994305283509311992268344932659689149044725278268851178262071743625689593833327527427790889142934871390124497847187559769333723286181059355730422352609633594972880679988434632727829633392971196615348162e3540"),
T("8.0270564887074008992929481581600294386090831745459505539216873340458312207422342705431057237884163498424349206319209533661302797554406960728685696384646157216820308811030692783501496335637205341645641865876987704911724172887422201095488046489024482854111274279939733922390803256997868575641148291588995771500671739181954270612789001072297006035844811068998273723866529350060897658557177391069889428138e3617"),
T("7.6076234226710136997076519198854581037482480050087592375273646746765716709802670790534160394910843369630438334623933329715061433126854176918572680591852491900095968421410826840041652944667732505393218836407650478812322026068521739096553158504199794298343738853325452463396386800405102937609865179610358195390467842398985491405704400439203254032406556044023342935195219037071893174834506422022272020608e3694"),
T("7.2101067461769422102719046864935900042020946053983858930538783546380741670622477730299778929732944630854151363803543748221329578582604770541719603126349873057195532110292846743563791049380608460124840094825775295226949060515234109528775156283010154878061758953690404860422160965162770534213586973008276804840802176466270909812402590547626695704877606695620372290113893333718784454195491413120278571381e3771"),
T("6.833361275000419432343650592319686694062674227594429857464606108305032877344799885305123090652406787997867592503236607009836687444829395552541403634550659710745653974928907350064693400553697943529341780925791186120102910163514753761188563821153759960369188532092163964559115206212975793696371318151500479047238166891574507004736959512033943570963451048752039151427991562182278434585245918970979972925e3848"),
}};
T pi = "3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273724587006606315588174881520920962829254091715364367892590360011330530548820466521384146951941511609";
unsigned max_err = 0;
for(unsigned k = 0; k < data.size(); k++)
{
T val = boost::multiprecision::exp(boost::multiprecision::sqrt((pi * (100 * k)) * (100 * k)));
T e = ceil(fabs((val - data[k]) / data[k]) / std::numeric_limits<T>::epsilon());
unsigned err = e.template convert_to<unsigned>();
if(err > max_err)
max_err = err;
}
std::cout << "Max error was: " << max_err << std::endl;
BOOST_TEST(max_err < 1200);
}
int main()
{
#ifdef TEST_BACKEND
test<boost::multiprecision::mp_number<boost::multiprecision::concepts::mp_number_backend_real_architype> >();
#endif
#ifdef TEST_MPF50
test<boost::multiprecision::mpf_real_50>();
test<boost::multiprecision::mpf_real_100>();
#endif
#ifdef TEST_E_FLOAT
test<boost::multiprecision::e_float>();
#endif
return boost::report_errors();
}