示例#1
0
文件: agm.c 项目: BigEd/wp34s
decNumber *decNumberAGM(decNumber *res, const decNumber *x, const decNumber *y) {
	int n;
	decNumber a, g, t, u;

	if (decNumberIsNegative(x) || decNumberIsNegative(y))
		goto nan;
	if (decNumberIsSpecial(x) || decNumberIsSpecial(y)) {
		if (decNumberIsNaN(x) || decNumberIsNaN(y))
			goto nan;
		if (dn_eq0(x) || dn_eq0(y))
			goto nan;
		return set_inf(res);
	}
	decNumberCopy(&a, x);
	decNumberCopy(&g, y);
	for (n=0; n<1000; n++) {
		if (relative_error(&a, &g, &const_1e_32))
			return decNumberCopy(res, &a);

		dn_add(&t, &a, &g);
		dn_div2(&u, &t);

		dn_multiply(&t, &a, &g);
		if (dn_eq0(&t))
			return decNumberZero(res);
		dn_sqrt(&g, &t);
		decNumberCopy(&a, &u);
	}
nan:	return set_NaN(res);
}
示例#2
0
void test()
{
    std::cout << "Testing type: " << typeid(T).name() << std::endl;
    //
    // Test with some exact binary values as input - this tests our code
    // rather than the test data:
    //
    static const boost::array<boost::array<T, 2>, 6> exact_data =
    {{
            {{ 0.5, static_cast<T>("0.523598775598298873077107230546583814032861566562517636829157432051302734381034833104672470890352844663691347752213717775") }},
            {{ 0.25, static_cast<T>("0.252680255142078653485657436993710972252193733096838193633923778740575060481021222411748742228014601605092602909414066566") }},
            {{0.75, static_cast<T>("0.848062078981481008052944338998418080073366213263112642860718163570200821228474234349189801731957230300995227265307531834") }},
            {{std::ldexp(1.0, -20), static_cast<T>("9.53674316406394560289664793089102218648031077292419572854816420395098616062014311172490017625353237219958438022056661501e-7") }},
            {{ 1 - std::ldexp(1.0, -20), static_cast<T>("1.56941525875313420204921285316218397515809899320201864334535204504240776023375739189119474528488143494473216475057072728") }},
            {{ 1, static_cast<T>("1.57079632679489661923132169163975144209858469968755291048747229615390820314310449931401741267105853399107404325664115332354692230477529111586267970406424055872514205135096926055277982231147447746519098221440548783296672306423782411689339158263560095457282428346173017430522716332410669680363012457064") }},
        }
    };
    unsigned max_err = 0;
    for(unsigned k = 0; k < exact_data.size(); k++)
    {
        T val = asin(exact_data[k][0]);
        T e = relative_error(val, exact_data[k][1]);
        unsigned err = e.template convert_to<unsigned>();
        if(err > max_err)
            max_err = err;
        val = asin(-exact_data[k][0]);
        e = relative_error(val, T(-exact_data[k][1]));
        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 < 20);
    BOOST_TEST(asin(T(0)) == 0);
}
示例#3
0
文件: line.c 项目: AlexSteel/wine
static inline BOOL compare_matrix(const D3DXMATRIX *m1, const D3DXMATRIX *m2)
{
    int i, j;

    for (i = 0; i < 4; ++i)
    {
        for (j = 0; j < 4; ++j)
        {
            if (relative_error(U(*m1).m[i][j], U(*m2).m[i][j]) > admitted_error)
                return FALSE;
        }
    }

    return TRUE;
}
示例#4
0
void test()
{
   std::cout << "Testing type: " << typeid(T).name() << std::endl;
   //
   // Test with some exact binary values as input - this tests our code
   // rather than the test data:
   //
   static const boost::array<boost::array<T, 2>, 13> exact_data =
   {{
      {{ 0.5, static_cast<T>("1.04719755119659774615421446109316762806572313312503527365831486410260546876206966620934494178070568932738269550442743555") }},
      {{ 0.25, static_cast<T>("1.31811607165281796574566425464604046984639096659071471685354851741333314266208327690226867044304393238598144034722708676") }},
      {{0.75, static_cast<T>("0.722734247813415611178377352641333362025218486424440267626754132583707381914630264964827610939101303690078815991333621490") }},
      {{1 - std::ldexp(1.0, -20), static_cast<T>("0.00138106804176241718210883847756746694048570648553426714212025111150044290934710742282266738617709904634187850607042604204") }},
      {{std::ldexp(1.0, -20), static_cast<T>("1.57079537312058021283676140197495835299636605165647561806789944133748780804448843729970624018104090863783682329820313127") }},
      {{1, static_cast<T>("0") }},

      {{0, static_cast<T>("1.57079632679489661923132169163975144209858469968755291048747229615390820314310449931401741267105853399107404325664115332") }},

      {{ -0.5, static_cast<T>("2.09439510239319549230842892218633525613144626625007054731662972820521093752413933241868988356141137865476539100885487110") }},
      {{ -0.25, static_cast<T>("1.82347658193697527271697912863346241435077843278439110412139607489448326362412572172576615489907313559616664616605521989") }},
      {{-0.75, static_cast<T>("2.41885840577637762728426603063816952217195091295066555334819045972410902437157873366320721440301576429206927052194868516") }},
      {{-1 + std::ldexp(1.0, -20), static_cast<T>("3.14021158554803082128053454480193541725668369288957155383282434119631596337686189120521215795593996893580620800721188061") }},
      {{-std::ldexp(1.0, -20), static_cast<T>("1.57079728046921302562588198130454453120080334771863020290704515097032859824172056132832858516107615934431126321507917538") }},
      {{-1, static_cast<T>("3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230665") }},
   }};
   unsigned max_err = 0;
   for(unsigned k = 0; k < exact_data.size(); k++)
   {
      T val = acos(exact_data[k][0]);
      T e = relative_error(val, exact_data[k][1]);
      unsigned err = e.template convert_to<unsigned>();
      if(err > max_err)
      {
         max_err = err;
      }
   }
   std::cout << "Max error was: " << max_err << std::endl;
#ifdef TEST_CPP_BIN_FLOAT
   BOOST_TEST(max_err < 120);
#else
   BOOST_TEST(max_err < 60);
#endif
   BOOST_TEST(asin(T(0)) == 0);
}
示例#5
0
void test()
{
   std::cout << "Testing type " << typeid(T).name() << std::endl;
   static const boost::array<const char*, 101u> data =
   {{
         "-2.37609908807915949996042688873953402912174184373388399043229539427530802169622688886435380890546981798452174137747437590e-1",
         "8.03406366226813589517543567844755380935198206635917017883860879215939165740799963435747185200486086864198723786516760875e-1",
         "8.60219386510802105228997694366289682807721120146423711696179175800635220710279361583231346318224971127450760223168489952e-1",
         "-1.36768951513839774357595871594675554406872039078811749027554673949684004409484639336417431285061889554892096426752261915e-1",
         "-9.66210139195431691033548069227792927999642647449593184440815029076272297050360196975341458076547426373476590671462150981e-1",
         "-6.12007278553856790723803948280976098970972124581361775428331444376106018942231526074915731012122426588769327127413045994e-1",
         "4.91927698740873688392439262912409276430264703350691359723802294639643655296838880236042651349290074585311025856549893171e-1",
         "9.93232596718899824059271235487971663771012607519717340071654721877802691370866768064059943491135925674950430467047724563e-1",
         "2.77789911520199551017947550534057049374212876971194676010301098598339529915403722848373365985645657342475739669568931563e-1",
         "-7.77955945956221239101360662190442739163791527953499629555756394261998892874934847131138921705713935365505245406994428077e-1",
         "-8.80676278306736581575818642341143682410874043182925227659938804267878718513212454821032629378618345485453587099696563832e-1",
         "9.54652155963865007116798560589970996367213754762169439269792747771200843006278637115722685610960738675814993576019945344e-2",
         "9.54658201427917718824191302196929158303422390793460018465335986921801519149657723689322277773550748806000948225466432438e-1",
         "6.44358700620889799575033272322899136331490664925359198096632560532437137894857803619177106562399406351419810452110265174e-1",
         "-4.55304635273050571206400777159475409897339683148730716647371922365967582339285347105376503917296765204188604297021364549e-1",
         "-9.97202532932553753622481171186283382950122646390227670693679248197349800205205290898290539070732778341271049474946533154e-1",
         "-3.17489525058325500707686194437148362752290391406825231198381521862930317513649081353670386166519524315810546189268634469e-1",
         "7.51160186640147504067744846462384089742696250681200524524912647858645140367792164416711871535116761744380912486921554617e-1",
         "8.99610194168373157174515848193119670768490559799348397680196213249921436405001710937402190319584272526657508442591319630e-1",
         "-5.39963892484342940823660554048696208293700871414984387094529796385334086703752106515008832585578915389731907422242902573e-2",
         "-9.41455348900839346761557896365239742769987576963330061702397697388879776230596944312519157729410022380228287314835345969e-1",
         "-6.75595816763857390859268297670835380459024839344154743310231115864242050771191159334664874097564054770066166961642073448e-1",
         "4.17894201894880415042381733708896725748531223743344790054523182948440843948904650988733732381978194392219295696279423635e-1",
         "9.99447981389824371458566861195586395552622718284098766856978062347139060489410032781030191080200904443096549587568037683e-1",
         "3.56640095868759075150409032448421838265699043643228482503057299699740924345262819242042067863780263400092250418388628640e-1",
         "-7.23065426868134142613141384486526262450487633432466529798821958977732347646832059032382447792655111641456570392189752211e-1",
         "-9.16988391192434436877664999042786024703848714036221388727578305299843547352325574309860356272561772723624753484063972217e-1",
         "1.24341855683226931265962750806821531283439413068694552738675989282017066737438591268502070364982899342633928417210588531e-2",
         "9.26624413643579136646620112107410908114766812511471130116341925013001661546817531064974089666536893346764523464250445838e-1",
         "7.05664607841658050248613256866289182754229289446384595719719495272020558391145537620968819401219414243210529013148958366e-1",
         "-3.79761093422301890838671114556341706055562482358183402807224298533060188038450560241345615647754569347252101282386222173e-1",
         "-9.99965058979463689113370264378210962384824970050865061898892508056811665771886385589295806419278045318841717598003331419e-1",
         "-3.95173919871548266286836251448043149039940610894391718791244019288314418437411707835924620250473697245151743147215758686e-1",
         "6.93720251624319621941983929806434090162802383400620564454074825718151625795576680427510026452063593762417421561201654156e-1",
         "9.32780816819880202610269817418700102084277332259524791943833699964920012022753227823298655560837271746316929623378078695e-1",
         "2.91495208658083070508005579692813621670878962971611104453227900103973434149303469066898102622556226584993895360896300290e-2",
         "-9.10191043170480685360743788297835112117551819731152897291272407935139876953384666161532187572493791297095784055525159185e-1",
         "-7.34513075127503122343910106816656237074878218180284276449954797048122379869002663646507706411949095015624141821039453971e-1",
         "3.40971254411713599427147477626159847871020791931107106418841144080445813896332252160005593096670674809345703079384115052e-1",
         "9.98752871506016936810666998588493462933191829230756181478046320353377054175122206889047094521687205093218701141334147081e-1",
         "4.33024359542714849537532946954507232835434973891665238942502273464321666207117525270650546741831354943253652514490075246e-1",
         "-6.63175408268187738636594884921931867786416057472876635147295424128144233911929585327601381618059327766986981109409782838e-1",
         "-9.46960160806563725719808910991708075372282242401645009270517113290439792088443109178772446465191984149998211903724560065e-1",
         "-7.06828182905581345108929510344440443421290640066613022421187316650733628538705972455891575947230299102119854983197703150e-2",
         "8.92183656127948379886438402777950080111433733329436790239129260607557296960582455582584117031260710927499215646838011844e-1",
         "7.62091330231640362984555508176991632755732840163230620595759320390970951235395195394649584713540498911356433919369698423e-1",
         "-3.01591765120371930643555588643712101466544136366607065361801475091335195383846047491935017919396438040414024941341524187e-1",
         "-9.95813515236177554177387795413035497724212540625760091518605741283184405719984044075159457509720410668598540884613985023e-1",
         "-4.70125959152223022135690700550251564040118601846181392455764893020377582359429013073566263451488554529709131439092909247e-1",
         "6.31483718775865440843182928017874708719203714677143270278178885379757350754752477512514449375355491054871712891789652146e-1",
         "1.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
         "3.87481045630097871028201331640164477694000480353342897357083794605539506785023570062767753819472037935010414476627195076e-1",
         "-6.99716878554812023132822640034166338740077082416915046841339368979161296335086955803240899441098534898926193252558848693e-1",
         "-9.29735101124991407032113033015438177585645722877060262785796302722011806301680288369763295777635760805579255008366302180e-1",
         "-2.07925797310208845709174899248298159909010721767168338004516304026594885686024530923209628704670627250569637267490913462e-2",
         "9.13621640053945104047985280883096238900189007462190433514805702721127019097915088259906184736442916334750420359005079959e-1",
         "7.28814716527795995795780587639833705107995825167970668466246348938821997240383021826681253777014938636567626203524137506e-1",
         "-3.48817863192357573536083313907744269588018702862402502601699983054718835012048372083235768555953613790431700360695537918e-1",
         "-9.99135337256258278958854200595331742602280601557283993231562055717063052179292021052372510863057206152466386086657442382e-1",
         "-4.25474147219713305654097901385832164424798803616095278869643928816776198489330071073326518019520590535564717523756486665e-1",
         "6.69409002349720857726983952566596052122726437391092096671257338244059819036586172017092390651026654050631669646310910927e-1",
         "9.44240747589054266930136705015787520728797286842746645573763175559132491628984502333043316023599487896169049499868916865e-1",
         "6.23417820549832676844933182722733277887833220127638406914080428946880981800946578131712749910941183940944526141109771339e-2",
         "-8.95928229794837090592434136137683839101829890460754766346170956577979909285084363961363023377587044303560652568203578379e-1",
         "-7.56652196635835430995109388017590459596111729342964992503572530290981857981790620732129221157071082788019187787999930361e-1",
         "3.09551461133309219674309651201007026752336319933918953736299690287371505733386433918863300129026763968979930342098019300e-1",
         "9.96542844308353945757715814452637400116215448012622700698887257177706625278927018059066920597035660000571997275705962011e-1",
         "4.62731465522276407764000677957978862104808823938378826581864482071733508960062598574638347814740748458034065235894523010e-1",
         "-6.37943500095315456672541800050589670140910744260281868746767523730582697622604545933849801882909439609368258115114388202e-1",
         "-9.57113494461990955768932962010819183910065445494138937651443249061391692258872250121438832853873660881630205561168895590e-1",
         "-1.03783175146302830356973378710923690121182237844646430783773333188328606275124873219756415071202025673009660963930966273e-1",
         "8.76685468012988943166112725030293740012198666616661362437433807594683780986916439696374569274720383546275206733493672834e-1",
         "7.83181178815072182812568575402104911406191663934571600092749188502783771503475038116599065276589122015600004250624262132e-1",
         "-2.69749743842835294071354429049113807280228918034124159074991560056663623624511602063409428877143567459307323934051784210e-1",
         "-9.92227004420417932443416371636723983768124774541445787394585828303853075015733744933294181104002649816119116502663362907e-1",
         "-4.99188570507651271652464431008309802023236218596632956064119419694573621896525872847587264755853127438644874992889777436e-1",
         "6.05374785886620830935500306718810628353011877048386199574451402773468315797082901705593423724389976967865835641164117478e-1",
         "9.68331080574540181354402420018944004334504868848934676984951546671476956051983469715128604348963016773169794077158289730e-1",
         "1.45045093347669933436797325432376656017480150281100519869038554695618054318368975927557872948037203212941966706926758604e-1",
         "-8.55926631706799584065153976496431313099942493164544290051315786450857575707615522517293656706329757352795226750189755758e-1",
         "-8.08355785820466703104647317116964786017731181599256098405978700298563758509572188640629418770593008092680980412866065299e-1",
         "2.29481541445091823694157468006983283649885473964756916206813927875661041834620526229807744443043682778028709792615798955e-1",
         "9.86195281084368344446227722442335005500018635181693920385626820970119467136148305491035657795704047666385553672680209923e-1",
         "5.34782415974986828906369231191245075731384342252264783019973387059318216570499447505623911253042567598873910043381675873e-1",
         "-5.71759181631212640256161075896307515511612057247572886814941945052483422285718810088660759708176904381865453799197101481e-1",
         "-9.77874107069129472007009478090869879295520839405452365411822873037906082086100232576241983901051327761231156641104065497e-1",
         "-1.86056181372276495846711248156316208757691570931906856005697361080864028851991674077024223201008430626166447144444086146e-1",
         "8.33687619660983803179149188531271900120055171980951416163724579833511897001564116810390933587615557717585362295882429826e-1",
         "8.32132482562487183916482822112362004641509381783438374175226355792137053285527706239574867923387554339582561002247202518e-1",
         "-1.88816490768820368180947188938258919466912959009058295775702554895970560887437777994365295452696990115940651570073217522e-1",
         "-9.78458105113103660973458641126689066610890753079836635611789969774219913050456840122278188955139015473252491612410972950e-1",
         "-5.69451448580118869157805059117807250106203230622762838051154208713065707949727035884250775206017528612930773233017928006e-1",
         "5.37154819650306918873973169624898539483418364490295996462663218848771864764982600193558748568095521886456306061269765631e-1",
         "9.85726070946814004698231423834505649751779161578718404221294527194525251740198034173542003704080544827976936213857653517e-1",
         "2.26745517700332138489400566746499809209783385009289423848083137846668382711005704387134606000570923556980021574851618566e-1",
         "-8.10006890365888881023982873786181048364505748637138923322482323010218991062084191379116946709356002103893071903481540337e-1",
         "-8.54470151393449484710948210543666267680196067632693416660536443330720708402601669617638569732848938319544250428600991723e-1",
         "1.47824914922605209542648603104533928946885824995208478684499907657728115943168395067575842431291755277452367320596435067e-1",
         "9.69028856602232134498324179654622883463820270279077886397861028881882684131282848087869087883519707948141915733221980948e-1",
         "6.03135714281336943093251136556365407562473924416812270469171432809743173719168209727199952532489544254928975940518615351e-1",
         "-5.01621542149055350065079347615664213658089623368745676779267390227688581807037821041573344917735076902116221444127518632e-1",
   }};

   boost::uintmax_t max_err = 0;
   for(unsigned k = 0; k < data.size(); k++)
   {
      static const T euler_gamma = static_cast<T>("5.77215664901532860606512090082402431042159335939923598805767234884867726777664670936947063291746749514631447249807082480960504014486542836224173997644923536253500333742937337737673942792595258247094916008735203948165670853233151776611528621199501507984793745085705740029921354786146694029604325421519e-1");
      T val = cos(euler_gamma * ((100 * k) - 5000));
      T e = relative_error(val, T(data[k]));
      unsigned err = e.template convert_to<unsigned>();
      if(err > max_err)
         max_err = err;
      val = cos(-euler_gamma * ((100 * k) - 5000));
      e = relative_error(val, T(data[k]));
      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 < 5000000000ULL);

   static const boost::array<const char*, 51u> near_one =
   {{
      "0.001103662615143147017601393734232421549156847219973314118949247990939859507971857976111288683988415478257878902917354105871236439563170045857810738102729287303674642020538722348587741395785016549139854168605590336633274890874911975139498047488076101124170425114828336211817830671418321600962996502656221412102902998671173649312277667706874059520046508702908872747388744526457997404065469953155187340837",
         "0.0030157041572432190019717764776322147049224887913331212054173669461673516770769148735558540290915754514269097799280330158745508542936966046640795712691698490758472574837678659161855207596563250546269614348515005196657786359646020537231301121492728577410212550350070502426482802490452572415879214994201864402901595309726458026672888041860289772080407882673424767232857435141510615538430445535588448032261",
         "0.0049277346741750694119109616231402901360500185022482787362616412856233338679208830974124749830793778323997684640684587346403570647040211088376986993615001420565608501262335822815041623056442245053684626079448221530207757672939048030945164948521320401574074802966260975904478775314730002799895049652983052125151436511589335123254582883803928373794668948878049089088843407672795237410750365571990834236348",
         "0.0068397471757112108044544339281399968563253858411528016363900245610068161564091499398024110635089866212789583403491711476788985949178019078796740862827299289838108117219486357027460681238178010067475221327133396780718266880540272936860185783976937569903778160170225166328920201699827472893824363838439627437187765159770262282930293057633886299749088561182830982345936603553661004526800797082995898813903",
         "0.008751734671690018552720976028788304981263251327799787402847843531098338033456389098956160956160597460869666211569183483587979772678557230743050583975270977754518475970489741156524119378847305446845331098526962579804361960647344836744631465315238254178161716870409320747176674142306881908614436607977326507761331050644035013756409444911127742401762647885817361924274132830920030936589562922803846509607",
         "0.010663690172041286306192948782895990881227033104763005629047563262531418373465237876680529005058533981010793759446966868628480908709812402179047774888094761104238131843239037167212206469894485599085717216855637620318723457013401360290343196462723174177342294339229792213396006286331141933952648238459364417067676760977202812721209681621184724443514062993874571816382775241753902032787099435678672474841",
         "0.012575606686811781116778815864446643746718166744927923785139233710240017201737625088406861185781739628293213436323314376708933534933748436720721568462267317026688561438144113855290140925120435317506169856461386623828941531577425811393721991195661429557079268566156800689149725770186985872449679872155877537432897653904213375816262709009448220490217917537801655330411526526290708967440087145630462068976",
         "0.014487477226190798137230457835664944872810802211308342685055637400305474021552028493778559102552025380880477103065187688337931713540557562373991431880251553620947836940726544553647739994157300967262941976933375115946629204615918888689039777423610894099269527633757403818072000860056651445780074486612843419789636984117740884711882675016016919064788076097669389652323393864660933705259163296837955978748",
         "0.016399294800535714798489384358524900105286836154421890562438917862501411947245037986455919696365301666112414890097246479762149456962809638588245466988584093380263545543023411087203351948681559905336010066900667101787138862856447778428938265451537422367650992162004154495705878092019403922006152498705687706013973674800621422751806347308220226407830977673540994341535381202679482907460136241543505771361",
         "0.018311052420397544372537858201001145083914223029622271478159852925692124442640247100336262041440360412392318902558295108452513123454103504516607498763863728284797202978975409264141138861738184468257576157204552383675442780049333490201800526935793000727771598103735596829143729912656158790924063286176336412427525710457367751437348230246446466833498557166002214984255422115833828533909144072330080184872",
         "0.020222743096546488827333191237246591760639730704704148795009602627175281013458865557238240830203973690492882935553111519759474835556686812553430134442713057622274348510526931333124437928482001301214776111358848026164688447150395879262705323533149853785508106018564787140458587165768350143018847840661371060583295055600185059031740386698369796694993301139380463919242175430688496936048982929502368583755",
         "0.022134359839997490880406060727014362125793630864951833270601574861700025448109186301755833862830343973100181180995751924514611578149687732808840212399134735559355116816700346196685057916461444889179117142807858883574426062415931319905031345377305247124198345242221848293630112578508459623098934259229893301963120289071135120089672338617200639338087265986570094025605269870532431816151660553037324591448",
         "0.024045895662035785157706623778569329505432699504171659064296747761761946910295074291838826981712792368282349553905175996858645967280135417577488810651594776626562252686758463813820791031580579721782251705600570838044158357396828391251385978824608388341556751951593319015721256942139947235672567093309227673005475237474351604086627391812539914665025071874865132198040631867741985556198082915821590691115",
         "0.025957343574242448364285479040344211549214421772336408904791690210449825580868841229728937909141136116652894475476991471494524501035809956288247010861464302066154254736425460468024350571584780489213056428098560686376999562953811729945811217829999284678155635497607933780499844559793793320393174691097636750027421158473345884329284455326733063073401001936304522649050748641723222539485352644237494855455",
         "0.027868696588519948373400137317728007608587427701668964330844960393232962659347088604492706251530487148805683505883152882204177723404307465324383408418716579280515871949790204586171885981761699066301009410176801635003961167315448162116236938093263170474354430610732127054993766008385425707409224417795873645410443727472246508894027549288331903202127478347028519320691939639175445464091747341289465807076",
         "0.029779947717117692140641616959423088975059158964671307393654571763491553590582559015283533532986018614029995854278748039155177088839414450454409571267110720713374288363670804692289394770804051182510495900322915294613479146430103948686457060129295537542317247965142780968717375277053102667416124807987527429828758851341378395347636356414345553353015296944031211364374602764176767114282660874356057979248",
         "0.03169108997265757234968007548831539092664261419258315028339932724609641378752993073240305448323210275610250474048387518003293691429670190316839718892647475151605557113852966925288722557261748981001717642661075734993748510506277165730472207647763678204813714194082852502621623007244214605646094787730992510318924772328958129857640953691466395972638014259980360897599169526022683004620965496473543834477",
         "0.033602116368159512696233026049065446239504816931754722314316906991719894135599777826750609185018647633748023602662568553364455253741994701511752478506175671449029859193583332380924298164350627023797218098539441228986492601142199774579432202424360114528105854714450548265654769162069979862894518829365029262734944196495563243510942310738160350648115273816371164862001848102516957052031698646996790510953",
         "0.035513019917067011716864665791693591701266221069066142988726516832036728613300457006403299601385922973285573124147669717618486570986860008564309641657943172757912451506572783449830586163814477502720341010870119231030511664725149033496023356743601581035789746158436049009960920433265660001864258067191594425969638702851317416487965304378219676062220223886417078628342731900948906319081697480745936074075",
         "0.037423793633272685069230163289099410548201460485083250584815890545695501760634737348027106921155349564805321222282824709072582234185849564440670000847571561359324629877368620222775856068569278590582843550096096627510109210574429458414697641703261368397349100700647508781941466979105505468662952228018391181441110331804231754679360190526351574820397399161022517352576803713854137820941977691824804918229",
         "0.039334430531143806170384413477273936914540782490679532559795199052084263353981243128408259086619593938946158294175465792633584421592350011455198124846778194417281005620258982615227234871780679327289232072858751285307955384102986030326321993554199425677956531006546270705693578070953933490084008156062047268010604414954653769711129551190023978078265436680151306319349753427763894284339669614362603225399",
         "0.041244923625547845099780771389235760645292527949481044094490883777921290140650504322516472637184803214130714431279474404434513167088543202171922178874118967991301744186858054508473413647148744260057423931033177973119110921967581379650616945061418716237102199971097086754171168500651650526166023618723542873290120298640370217463634503988257867984189842393302366909916756244585593509804376197012137137735",
         "0.043155265931878005673591620105503250213648422568500347993529171942176855000247082147052189275394127432389966427668413127665366489709229602926384588361071126297040547180622989395253518259197742053810419372452372506534313264090033740095357809571640645325965973975968081307185286025492280541542290934505383760407808393490207181258819590768103829347539943429968533891105456889889207923129412409325200337396",
         "0.045065450466078760596989313842010956972889269629840996618541471076456145341576346037140737554087089598232657340541865108389258265511462307708855932308284610805209084413460614598570062354088931179587984702006847566162492414964136182928014974554852612762940578089297583097434972291633301329615187665009664697057933900728259220674217919826618275818024987757805509580781060051826778978395144370327934582031",
         "0.046975470244671384601033063916347240271496301008030038885300525267985292259051299166038486168462131096926077920611254966322965395673221324506213593415263189667393727124978454125104192236004303056348320706091018781990803164595039969574510002737990997634364247271320535459089400357647302806652831431190979518269432197656547265417669309719787317687585776029758282182901563328846367691507505917911626458378",
         "0.048885318284779485470814703449342779874157141188272539012461507790598796169844054420701400747288103863351008593834375336008952419161297787680355981672505884405645257094616683497040471721980241679616912483788844007649447969703512155758482444019770785766752697959554691538291379700303132353876869628124563105576278585509058450081192711918856522653293896204836307264696289474219755720645459588331890558889",
         "0.050794987604154532871523976044438688478988546522275702591135165295075684834775069782087540212155311599924632216878717363279038406203747968637573994688146329296755023729170505930935028107359530042909822369245609091696704070694133386183688825674952803613566914142157159664703170379754943610785780639205752343103591085978554489192416588288410803225066825839880971435465232206429722600557780654218330146221",
         "0.052704471221201384879102044313723519214541830844294339002006150295000261803629777930668202713875629368914012613840180174156598399096984605842000917709330893871365961242812860633022132663435078869433262371062200555333508565564704972551921154864927879748108180002977668648111714062992755985320189721615088748697314805428967770533095416911693326757965362169171309026356339280576158225848771071227224373815",
         "0.054613762155003812122160305957618147686113745063989650607179163157398820817715079449268802189362998719256947035541552524839497119721884536865240705017403409053301625152685151644761334409897199810093505097528650897729279062117617766845257388412635800174656504897022571125534403010151970450307624961920347280823962725005822339087173498538012712497715370388872960900453285934131578336748483622553313648565",
         "0.056522853425350019441850338124226420404372628229474954730316461224029279793449121148941830155705856364290655296696008865349058650396297667951745639266344993911111272076019522476315254920931469406381088740392436352997178777214659473302034620137440843681809428909274912969436139312159105442160243076856936138443854294531618433726198293972487505166088883354213979143973990964298454127970039847456893860203",
         "0.058431738052758164976379864942430396555977098734986011309321413104802080798824039565461521608355122102022725461220269967251619843394860641070621951433765763369761658916816880868188275032453137184211673934079277285593935159478757148621410070196500221526968060556586710920750728824112282461003224923995158937905479480579208549847478185757177039153501786271361921802927586114942206193581554801605680183774",
         "0.060340409058501876576879058406717550375449897922866349024612531373677724965692896763451690034750214807393086060232183962741893455630800282528706094634312497867863194252914455062127544671909424505367559503649890477570116767021509485710626043408265846213906257952113003324887350087083283630715857354116849013376841533857321740197047217435805280085872071354373524395263864933170034771001607559366437835689",
         "0.06224885946463576546133123915706193746686049729742751789281333411875145041642253752249398319274836506892916659694331849766284472811963607782488993959669913942440995816339529777656740297867471191540909520680122909159182411803441391065468297111274482089347737322313334144161837035757661055283810143238846811496286086926075008068489724098160672664550444107807861952850135669761489736449089327971794824585",
         "0.064157082294020937013292141108273585068933185681722806586173136512969086561151000586083228827704474922133659368208499428517560937267711287558275856325851735527047525549135602809953924346232393575354505341516408877034795144989051337120442048812961016500803766780090428411925756071299228254760633032932651170483895163866111455935100454818941073761804284777739005007991141161823471943803047351369535073521",
         "0.066065070570350498632132342303164932774411476452581548988386145454309844170784631219900687545375669726062411278210148833761887075889382631711319762066717518842787273543143969874177059386003262516941215168234997245420735913778365997498382320917159517052861653706668051150014889560865161606396037665048820655743861710636504450723955435275019348223982732095398949832565423361714391500479155224225613768011",
         "0.067972817318175064541548243754498015429928588516517183822313264446879635682093113384264993280408482780193047687370305892309106748875519486540879020142902362307237689684697063792225838111742241714789823601251998299331254097504567214769822096812914869886418586879378868131071702869283011709161582762527864014863950459121468893761825841337802563429112718615110803469902519051203360473993644451463303576859",
         "0.069880315562928257463098098362562671709183706398122146969098129179472379455539984270317889382725678551314678030902515782188203802362460214070192378666311369730755912670660970378408284876465192356340335277225457776091515934608751710356445501169982098020701963512215973413220903547301855847279762573955110834619967590588317288171580291576756417265600792610005176888567344924086299458709493921684370833814",
         "0.071787558330952207061531053207739391124226218288071373402959685303573894071937999096931283415397385296306228484128726125223568292760110763075739612174182840148193517540379302896938375357744754831885570482299802985278525692833941172622048860945698352794727105726197891701070706523197225463566498764869186174536278875440544967870368440256565084805804998877012238900798874720340885805165811704445925369809",
         "0.07369453864952304506868897057861922170414313661538863465614770246556638808351254050794164760581857499175318127117745597595046399453737415234966090460819383278338184265518294393589316067434296307320873514873375534499000895507092920123162793722742278902956263178675873980121089525814840115300730124457959632013360479776554262210801798434607194598511786777350540581826836696200671400628870250659962729555",
         "0.075601249546876396992772935963040077834759122887264324876826746597298507042570795315940378957369646666545616927930046677179646722187557860442506025110541968257406052679604681892086517951648112201767029044637142334937786145563391280677987040697732028896674786378870229133792190093646530752257521390201161387698590619925316803401938362974478273195688740273778224688121208296858072701246429755713258468481",
         "0.077507684052232870319778844857360483087988665809157375994805235390695227945273826842335916971262245322463861698987988491433092759415620685754813456247989287157909601376742141647886684380473379403067343977633347655683745871434202230624968375294472571053679501320680048739346844244553807193670436672857163839591129928936603341033670518982144557944158002407590669543043048232580344768659176122645763500513",
         "0.079413835195823539113919284592789131508074280056913456617148863190077260584186476150168101766032692499585019572300009477107342325731806003539645749720998260074894005503243715777788187754550286488316966320623707403846973934258796072434720381188302956748572794547906591019552569722211941807674118070825610462581312695693650893380241875873254675082431417454526920871842555422162216221640850141209989864308",
         "0.081319696008915424923862092389736899811819511475112310887916890436246797704730704673729056088324784096921353721791055102563812592375189346816348952621603248827528923433998597558478366712658235656924601774921095079356565867874041683517103417362062033545480747089630436317004907748679995334911923789802669273406449877710501792905734235548100216242648355048174292232350538531258791292074224222773259366265",
         "0.083225259523836973901629476483826882570495097409722948211156651871411915926347698443317606324912095013846386144848076019334983060323996364575622231284156371311209803383868297666027142776492604713451401116304951916037351315288808149328656282592946622481248077426878390562084748274992526750980236994304445617883874613002677387890383751048690275480465558930319669630406765794141303531112767626885032234711",
         "0.085130518774003530041015433371012162123590338565297712899451572274044870858132401685294989726432756808251618198809497117031428754224182463768189333992610411750324249283786647605964593556580841488686189374310703328490638378071341189999989736919850819640255203388192531225871093915262442913255553964348789674386732423763999398384843950222967487918049677831350991752153610543052586794779289758903475438463",
         "0.087035466793942804442393380943589773874807384137701777807755858606555806090045313793349743667697666495784828540247587627381581545620918795107877715086227932192756144780086856515641298195558204484728115519445514732755572178929839231921546119143469647706999890259163924570037168105911942268212237224359201159897493303064534985539474450028748960081579369980283792804593122976296597796047722827878891322393",
         "0.088940096619320340510800454481897179643787714504988904779549430422905882044782054375828906100456879992313640144934242418129400679706865644316664458061953684856607341811667576418163339843372041295322709797007871604740491453013916791024918954258557372755707588171502529270934617054742841996068375532958173787119651672031238405892943090742861150287144368470297356054911834742041692715934237148148936307154",
         "0.090844401286964974994199780075024285173534240616972938308566124002318176156233343333797652771250228033597767340846476094210813299723066344955542455246897302945908336756464582189829335315055318509171623072382573656172991307091055717376996812421994002305994837615827430425975713541786272473174908117299253875064746541808768776888139494200307162476704515967971265236163183394620211890252072718610942571965",
         "0.092748373834894294768837248013614869545920040757666771889792264347367335922283987944081370356939214799510822558638935486112190359701790662792925773186897671244831971450474952036618937833706899006048469791213129922302798462311426294239282200248625552430083292818594731518350634587677158329361662244008606299358410273467156168469937529868888478684257396004386633746334360279683178784117372066095688934486",
         "0.094652007302340089278624856973167138217258137565762699413364163993950641989798336903224059425798872308451866930780842878435503832366316245159154044350517727312654980455290163514021860802028251981954724580292247887851185639950862672925642859475325430465650514258094310141033116303195908372018392349011340787373492402788283020594141795669947097771918542864972570255253465754192708165241608041715996375567",
         "0.09655529472977379853549858833033074225823562054271495313739665642376685099661084023094270272485976247900824483810911634635819558334630910267353320029261330296977292720266655308513559530586843550229208517388789783011887450865488554143475302590353915732321663418057567573042594801866258948380684000769091353165879953111046260532796891917772727185993569684246844052518121013717183610828519193371796413317",
   }};

   T half_pi = static_cast<T>("1.57079632679489661923132169163975144209858469968755291048747229615390820314310449931401741267105853399107404325664115332354692230477529111586267970406424055872514205135096926055277982231147447746519098221440548783296672306423782411689339158263560095457282428346173017430522716332410669680363012457064");

   max_err = 0;
   for(unsigned k = 0; k < near_one.size(); k++)
   {
      static const T euler_gamma = static_cast<T>("5.77215664901532860606512090082402431042159335939923598805767234884867726777664670936947063291746749514631447249807082480960504014486542836224173997644923536253500333742937337737673942792595258247094916008735203948165670853233151776611528621199501507984793745085705740029921354786146694029604325421519e-1");
      T val = cos(half_pi - (euler_gamma + k) / 523);
      T e = relative_error(val, T(near_one[k]));
      unsigned err = e.template convert_to<unsigned>();
      if(err > max_err)
         max_err = err;
      val = cos(-half_pi + (euler_gamma + k) / 523);
      e = relative_error(val, T(near_one[k]));
      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 < 750);

   //
   // Test with some exact binary values as input - this tests our code
   // rather than the test data:
   //
   static const boost::array<boost::array<T, 2>, 8> exact_data =
   {{
      {{ 0.5, static_cast<T>("0.877582561890372716116281582603829651991645197109744052997610868315950763274213947405794184084682258355478400593109053993") }},
      {{ 0.25, static_cast<T>("0.968912421710644784144595449494189199804134190287442831148128124288942561184523327264655202799685025510352709626116202617") }},
      {{0.75, static_cast<T>("0.731688868873820886311838753000084543840541276050772482507683220220750082501569499540967562610201174960122884908227300721") }},
      {{std::ldexp(1.0, -20), static_cast<T>("0.99999999999954525264911357034690133684385823577463126432241468890539365027135494672267164697779879113636143901797362388") }},
      {{ 2, static_cast<T>("-0.416146836547142386997568229500762189766000771075544890755149973781964936124079169074531777860169140367366791365215728559") }},
      {{ 5, static_cast<T>("0.283662185463226264466639171513557308334422592252215944930359066586151456767382702286176981668344573238827368717546699737") }},
      {{ 10, static_cast<T>("-0.839071529076452452258863947824064834519930165133168546835953731048792586866270768400933712760422138927451054405350243624") }},
      {{ 8.5, static_cast<T>("-0.60201190268482361534842652295699870029606776360435523539636606145572515876770619546025351418378467287262574566665150299") }}
   }};
   max_err = 0;
   for(unsigned k = 0; k < exact_data.size(); k++)
   {
      T val = cos(exact_data[k][0]);
      T e = relative_error(val, exact_data[k][1]);
      unsigned err = e.template convert_to<unsigned>();
      if(err > max_err)
         max_err = err;
      val = cos(-exact_data[k][0]);
      e = relative_error(val, exact_data[k][1]);
      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 < 20);

   BOOST_TEST(cos(T(0)) == 1);
   BOOST_TEST(fabs(cos(half_pi)) < std::numeric_limits<T>::epsilon());
}
示例#6
0
void TwostepTimeSolver::solve()
{
  libmesh_assert(core_time_solver.get());

  // The core_time_solver will handle any first_solve actions
  first_solve = false;

  // We may have to repeat timesteps entirely if our error is bad
  // enough
  bool max_tolerance_met = false;

  // Calculating error values each time
  Real single_norm(0.), double_norm(0.), error_norm(0.),
    relative_error(0.);

  while (!max_tolerance_met)
    {
      // If we've been asked to reduce deltat if necessary, make sure
      // the core timesolver does so
      core_time_solver->reduce_deltat_on_diffsolver_failure =
        this->reduce_deltat_on_diffsolver_failure;

      if (!quiet)
        {
          libMesh::out << "\n === Computing adaptive timestep === "
                       << std::endl;
        }

      // Use the double-length timestep first (so the
      // old_nonlinear_solution won't have to change)
      core_time_solver->solve();

      // Save a copy of the double-length nonlinear solution
      // and the old nonlinear solution
      std::unique_ptr<NumericVector<Number>> double_solution =
        _system.solution->clone();
      std::unique_ptr<NumericVector<Number>> old_solution =
        _system.get_vector("_old_nonlinear_solution").clone();

      double_norm = calculate_norm(_system, *double_solution);
      if (!quiet)
        {
          libMesh::out << "Double norm = " << double_norm << std::endl;
        }

      // Then reset the initial guess for our single-length calcs
      *(_system.solution) = _system.get_vector("_old_nonlinear_solution");

      // Call two single-length timesteps
      // Be sure that the core_time_solver does not change the
      // timestep here.  (This is unlikely because it just succeeded
      // with a timestep twice as large!)
      // FIXME: even if diffsolver failure is unlikely, we ought to
      // do *something* if it happens
      core_time_solver->reduce_deltat_on_diffsolver_failure = 0;

      Real old_time = _system.time;
      Real old_deltat = _system.deltat;
      _system.deltat *= 0.5;
      core_time_solver->solve();
      core_time_solver->advance_timestep();
      core_time_solver->solve();

      single_norm = calculate_norm(_system, *_system.solution);
      if (!quiet)
        {
          libMesh::out << "Single norm = " << single_norm << std::endl;
        }

      // Reset the core_time_solver's reduce_deltat... value.
      core_time_solver->reduce_deltat_on_diffsolver_failure =
        this->reduce_deltat_on_diffsolver_failure;

      // But then back off just in case our advance_timestep() isn't
      // called.
      // FIXME: this probably doesn't work with multistep methods
      _system.get_vector("_old_nonlinear_solution") = *old_solution;
      _system.time = old_time;
      _system.deltat = old_deltat;

      // Find the relative error
      *double_solution -= *(_system.solution);
      error_norm  = calculate_norm(_system, *double_solution);
      relative_error = error_norm / _system.deltat /
        std::max(double_norm, single_norm);

      // If the relative error makes no sense, we're done
      if (!double_norm && !single_norm)
        return;

      if (!quiet)
        {
          libMesh::out << "Error norm = " << error_norm << std::endl;
          libMesh::out << "Local relative error = "
                       << (error_norm /
                           std::max(double_norm, single_norm))
                       << std::endl;
          libMesh::out << "Global relative error = "
                       << (error_norm / _system.deltat /
                           std::max(double_norm, single_norm))
                       << std::endl;
          libMesh::out << "old delta t = " << _system.deltat << std::endl;
        }

      // If our upper tolerance is negative, that means we want to set
      // it based on the first successful time step
      if (this->upper_tolerance < 0)
        this->upper_tolerance = -this->upper_tolerance * relative_error;

      // If we haven't met our upper error tolerance, we'll have to
      // repeat this timestep entirely
      if (this->upper_tolerance && relative_error > this->upper_tolerance)
        {
          // Reset the initial guess for our next try
          *(_system.solution) =
            _system.get_vector("_old_nonlinear_solution");

          // Chop delta t in half
          _system.deltat /= 2.;

          if (!quiet)
            {
              libMesh::out << "Failed to meet upper error tolerance"
                           << std::endl;
              libMesh::out << "Retrying with delta t = "
                           << _system.deltat << std::endl;
            }
        }
      else
        max_tolerance_met = true;
    }


  // Otherwise, compare the relative error to the tolerance
  // and adjust deltat
  last_deltat = _system.deltat;

  // If our target tolerance is negative, that means we want to set
  // it based on the first successful time step
  if (this->target_tolerance < 0)
    this->target_tolerance = -this->target_tolerance * relative_error;

  const Real global_shrink_or_growth_factor =
    std::pow(this->target_tolerance / relative_error,
             static_cast<Real>(1. / core_time_solver->error_order()));

  const Real local_shrink_or_growth_factor =
    std::pow(this->target_tolerance /
             (error_norm/std::max(double_norm, single_norm)),
             static_cast<Real>(1. / (core_time_solver->error_order()+1.)));

  if (!quiet)
    {
      libMesh::out << "The global growth/shrink factor is: "
                   << global_shrink_or_growth_factor << std::endl;
      libMesh::out << "The local growth/shrink factor is: "
                   << local_shrink_or_growth_factor << std::endl;
    }

  // The local s.o.g. factor is based on the expected **local**
  // truncation error for the timestepping method, the global
  // s.o.g. factor is based on the method's **global** truncation
  // error.  You can shrink/grow the timestep to attempt to satisfy
  // either a global or local time-discretization error tolerance.

  Real shrink_or_growth_factor =
    this->global_tolerance ? global_shrink_or_growth_factor :
    local_shrink_or_growth_factor;

  if (this->max_growth && this->max_growth < shrink_or_growth_factor)
    {
      if (!quiet && this->global_tolerance)
        {
          libMesh::out << "delta t is constrained by max_growth" << std::endl;
        }
      shrink_or_growth_factor = this->max_growth;
    }

  _system.deltat *= shrink_or_growth_factor;

  // Restrict deltat to max-allowable value if necessary
  if ((this->max_deltat != 0.0) && (_system.deltat > this->max_deltat))
    {
      if (!quiet)
        {
          libMesh::out << "delta t is constrained by maximum-allowable delta t."
                       << std::endl;
        }
      _system.deltat = this->max_deltat;
    }

  // Restrict deltat to min-allowable value if necessary
  if ((this->min_deltat != 0.0) && (_system.deltat < this->min_deltat))
    {
      if (!quiet)
        {
          libMesh::out << "delta t is constrained by minimum-allowable delta t."
                       << std::endl;
        }
      _system.deltat = this->min_deltat;
    }

  if (!quiet)
    {
      libMesh::out << "new delta t = " << _system.deltat << std::endl;
    }
}
示例#7
0
void test()
{
   std::cout << "Testing type: " << typeid(T).name() << std::endl;
   static const boost::array<const char*, 51u> data =
   {{
         "0.32137338579537729992840434899278935725496267444911714908205287462634251052210833615032073534299473485492692600156322137421801432333125051088723502425037485776412801577568405892077585206768190530859883094571475323319480739773193974206966728764224286661945738178210577326172938196062277314761537881936346874075881338768208490193827960565412814349738654540520356903367084438822830345189856017860672463017",
         "0.98628073997374759901559180515206275902189609982907214282364143439537215491113710345866034807991101303183938339561499559327886956280789743287824488269072297413440935381715378233031399015496124706604318545539544610760151756970229801074280545428642122005982857974921606264103186878499260552388713716032507770319550435738767597150644370033277228635793175246197730488375240713357827246166262087899961098648",
         "0.99999659728082161113542951278514830809677661658635225532792520501703544628367875293677270218317428676793098034276042396396797568103263882451732810190507733063467333056356770774002596898762991629653041854653269824642873291146068535300466473399592751219449187768646625229500705182676930009096545254478199838990703077597971823456671241141900968900216742636822174010867343154474773040184900973368250708724",
         "0.9999999999846483268200051609594321550129159997920576480976206867496512752486590660437091205989616108531910897733432934135954788151766561209164605337537937873588006552145390152387235783207736999759875845070169747521389728857476525437483543080651125798739562649414879487621858466223255239845627205850217328574865852922872737234283038190096982410137471391847466112651349436875974689271288261759782261321",
         "0.9999999999999999987314527242099750648171958211319474558707792311593804963057878814487720997303512134007272111464990650500302215773762906820778949397525329109311974741708703536680512747226155618703318739024344621256722269608969415280035337052044425138281821760268269187377517243951584969175035549994883451471918693502477485385682884154959809285569290940740978684264145737164182111806308430952867505356",
         "0.9999999999999999999999999980800953069847308586840237590563929855339557065536765765234844240789584487443451033349994294426525006157530320529970966048109743850154174651033567146346966529198814047607015842020039899630884318521543225160212193994911746894335846264878066530266737005606770102869237101848445559941638381625615207320468184414917265299980278164193202897754476112968080358662232635784904263624",
         "0.9999999999999999999999999999999999999467800140220866754762922747687784133233134010432889959570821554455247528344437918197518545105332713456859236726383195243056599177018396579766073961540714510399202497404647103138524118065391185503678895059096790300665805648569647351935897874460587855127436472608470703384261586158923066272124216158518232588330799027603391275039552776308636189531809031683723259525",
         "0.9999999999999999999999999999999999999999999999999729795912960133359928587562229512337339217831178574875626619226954752643039860388090399659478676726654102118545764943682017611574275691203710439707807193180604656837503862242700430179591666329131728631752773789406064618682879167351725013888294859467540832310795515139677375807407622028485242969471516812171475098378942187864794497220152019202351747432",
         "0.9999999999999999999999999999999999999999999999999999999999999997487354938310440650220692519525261552411539996830587326435051159231522052011310872619940247463640019105467860778515384738650636054646551611609757125760437266415865214306396520500343113189907306851418957620080971645943305760132385139924583154317156560414548076370893360020924960120441059315311380109752919823616149973862196846266297710225",
         "0.9999999999999999999999999999999999999999999999999999999999999999999999999999999572050575304159358359221596743379014313563214857593401545331495211888415913558896516895286943572966865708195832339959764445194449615969154689769557903166971249521898883489362426386924297872088925852892350150865941427355319827260914834268754732102528105919811851193667193380541054520023003326858641189063542651960743457613",
         "0.9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999998665016733514821204959171836698281165918083005790816030823236096080522860514417075411055633676502699904415882389102672678124683084429720879962355892225321369091298491658349178472270952759208443767848312111069127329160464884932271685986610697222434145553035947750809388321614695213754318979469071722942883",
         "0.999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999992372516628147584832950728021842198359205201519966391076994594773600474674435473005118571751514446148292787696117866094991476340344341061706866751156257825144909115117822189019766805825304055482958970512463798453229341693148012213183553546720540880444569824125592343803193018989122964",
         "0.9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999920180539244323143459416025663362517256166793900312667214543096238752838226369161775531456005541374878274529461511286842988937830155704737448202558382612829022464635400289328916240002670783433827234852858267621807568393874737879853500598862298495727481132883728328",
         "0.9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999998470116425957155787153557938061034698436461173594805292722874130433614266475136267606498346730583487791266503943659174886554170377537630914770998114573340081594827150737005158607830579000912020838690230498119348251553312722575955142752845289",
         "0.9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999462931048083476382670449719737943481963930626760625326765703815392249622625483433043363664396638162612437367800102332819699131841317348173451308570776544874933173719394861336636728378134900422312720743996219523365098",
         "0.9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999996546783689748726752364896615532860288057097437452774779386074906915819380531729493071959232887620213723607155628959529584572083388979892309086717786559916703004365603135284141639480887703759",
         "0.9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999593332381019647939423999969519583099837564321056588766269967853479478603122899456262904869063959564274215899007623362296377022418464303752396325625838280378647335",
         "0.9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999122842714667567128203355585346559126606029196080721845292399104475997315344844970601651757832506169948906646054332493537761143729664",
         "0.9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999965347272050374435790597917065458623422102880662825928396981295898014081371503733411536311258910851858",
         "0.9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999974926240515037403282500845454464621558236030794140169313830052413917",
         "0.9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999667705192725716176070161727364499",
         "1.",
         "1.",
         "1.",
         "1.",
         "1.",
         "1.",
         "1.",
         "1.",
         "1.",
         "1.",
         "1.",
         "1.",
         "1.",
         "1.",
         "1.",
         "1.",
         "1.",
         "1.",
         "1.",
         "1.",
         "1.",
         "1.",
         "1.",
         "1.",
         "1.",
         "1.",
         "1.",
         "1.",
         "1.",
         "1.",
   }};

   T eg = static_cast<T>("5.77215664901532860606512090082402431042159335939923598805767234884867726777664670936947063291746749514631447249807082480960504014486542836224173997644923536253500333742937337737673942792595258247094916008735203948165670853233151776611528621199501507984793745085705740029921354786146694029604325421519e-1");

   unsigned max_err = 0;
   for(unsigned k = 0; k < data.size(); k++)
   {
      const T x = eg + k;
      T val = boost::multiprecision::tanh(x * x);
      T e = relative_error(val, T(data[k]));
      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 < 100);
}
 bool Miniball<CoordAccessor>::is_valid (NT tol) const
 {
   NT suboptimality;
   return ( (relative_error (suboptimality) <= tol) && (suboptimality == 0) );
 }
示例#9
0
void test()
{
   std::cout << "Testing type: " << typeid(T).name() << std::endl;
   static const boost::array<const char*, 51u> data =
   {{
      "0.33937643772780730649735035088117439284797964277099188367427256402032493952288848579083622213428182842627923924487560393743204013166230906610274533504451302298480596207257724471359936027198954417317381228420986152562253196896619001418292769103034561794393400788635610424360775622370491149170501475453034747306600304507650361914904138327962144190354572359428689767990353722392457982930942617983634601752",
      "5.9746833446871871874685235810964396457491766537010251792063372398172074828151074989468673672535421045923659313715467371148678693662985453590831122722616951299822923837410906027605763677066945998696776562438704017846907508677186762421899376364636371743116519071733413775650991880222096045615827530741679305666041641331859757012015389431793705875600863391408448065773828563483223117178640044499399723744",
      "383.32826140718915582837967448860824902040431804683461630967288341613741467095168380744762629948507973653220772087887989292128183196493611623766470283358542341824134250511562240487252437079958429586344329111208041197054162309164204144237855212391474938076935722386012246677813568519769393617755607372817372398764101401294149353978426057544810680225593132066193858006901125069663362991172745649465725272",
      "180470.88334757918167934673473709881208559849920820465419382707969109187448281704429118605409224039018180517847684905660962429505828088398660499158213746722168139372781263849989865384042531846290813274318773753295025006473736660333640052386121946183935053629928496714560749082485275242374067168149435272169334475060524974384307351757201698786200303374802146857634893509516262245925287553380389076772488",
      "6.2781497954189513207977998975338639259302378413658035459603622432839117790845430762753614618299222131433987986511235061633658516824123179660244932375967566163895461895213509376427850290780942550513918615228886566287592461085762554208269169000672149592375451149457664991726947185145469263932975075681560662428417041932848357447220175607720561540370653825438750168143857523868718856189519864027430308779e8",
      "1.6137831147508521132232267071463247985636947830692243664921522457394294988129666666745854084767325882717254318322908201512400243137564101564235450151960593110176457803621675408660678871179456625850704076654060872094257085919134755925910859520026379969099492921728083639989029675808598278170215911879751320574053132699172028082102336989338403081942130794464992491330850160862146024982135931859868176809e13",
      "3.065121004865094886953119667134247741359538615435533822684602797608029400610449009335078883525336625519599034934744634528257351124420564267197918749480389135525897886434344884370577475363556341414615470556433033106705280531443046669163916446454890662947185057748542735928453570069226294801221403438864013368364219717148075652123561545773399076318560221173734215703610924057158101731263882232550297741e18",
      "4.3016893602106215864771434464025735547192956887049374680649926707919814241961779812200280749930256501997849507695395125441756421661413154730888574483309057229943886742437071251707738990393977398403536175642762242808350076543018009682725019125106175929448866428526984370017465117236484653179596869643117790492866002064306593104169410537341890174831622159415936125041593936992634719906123727028419057537e24",
      "4.4608685929681360001024935791890661655506049487122331222491789265929503651540405036031990380918459104583255735620288691363060079360758406339887417913286769718423759522832754263499878135869223253358698774066131403822428286318351390574838877307934317251880890827523325360658275060099119902102399714992704146743744108968362755624325107486994088414126705458507082103811086372240878942983212662081104875997e31",
      "3.4181315955816806472569357441100390029536003312981931954091744304974491527743599822230006760631204302243855667216955365986192324833652299336285826148922073950348547795494738267861098328516497599288314822606511466743212319770180141969147554023326883651348621187276823849839283609071336923316655316828855943689100621619083822127788284160652232283630351386798636794979234576432977468152969056493038423561e39",
      "1.9352946282727908101414530212785249763640776919052480158881659190625166733449770912626442628329346416132299268886589920690636914906717492301836773331460154604580407945460359957380672599434023197425489039882987443681919056322268437224184910074985583829184831034293865504101338027818555871946080687710035062238789949143319550108801094190098446234092310048150477274502060870736716324117412815209633124145e48",
      "8.0964449511890098565841496436016431651692307764702784234901741408135381374668439020986470675941110923614446905696410406066640351065195237123718468440597743167713019447544827353458477844468727834630038609140168354634397475741840053079910210908251252223665806813131724262334693137656218010287981601097259534068903471812189212459231851835393208367369054618963204727992168556204168791513644815218096463093e57",
      "2.5028257092625174549175008952222569141816383637904981644379473858250736896174216539673733521627607209322019413420937570273676341726636306931304501320694017061891400181233108050930610234076339285157392030024769366663118692571469493256243952018705693924919037621083041696227375589264811876761430035546270312014570431860268644276406457398485042029556392894799022733858611415899182421526634018060028309384e68",
      "5.7168370213792649967466315312864179662895170192695050789061362839510836418124645968032989149068311018994324517420345278843446068634292140996241291031113395887824145000873531937856827299256489358571593850210528248202703396455363364446996158929674989959483681393263782486430231288067231095140919741928337466492665857902913114664767450432510739209971738097074002526312039248809036478310948111740897528204e79",
      "9.6487261169670031207955841899729386502708125098394777808615183927342163909284025992243201020435915122698808649711566042372911206942311277943247994427354130507790526857797833309691667375441761513692598664419973302444660838882173718713387158013802112502169254860961105745895124415352002289485483908952674562396552790441656755711709645516914188860464353624992313010889765422981069429049436524222321550149e91",
      "1.2032977660238608232537005158851668311089986235965463249220377778638489972355974848209035082333822309902237165042868213438627625544096344578102199846440476859557339736747791529782018329078191477783605471526120462726353510147373798347292650122930289404816748193194907382572774906323766342758092979989633448828636445074016110331338699464788279882402189027828261039788079556739180915346692779065476431369e105",
      "1.1088306081278288754492401130897590262404571813281460605683836139669281218442501421935533170636990866165181664561596333701204545493730707210930818738817252706131805203538144119244917164949716209095542194899833868499263375700313934257155600824601418042452138211549248837967344874095248283887929145923103153332810091693393888809653081365270947112297406471162377655179657693898463736926911943490619163092e119",
      "7.5499880591625965663868042832675300901799245732418501707646792135512053284835138294796976048691668315442427834949618514094329533376442442492757936744857569785450769927581802961191319878260712808001736830227501518832554201816224207300614310712430470538022948957433004823102746037654096845266998518623332118892916505020627868405618942429551700207476696585635930562973459491424179233918050890206232214765e133",
      "3.798536358006797624025033016530070695826982685154937173246022092345982280900791849578041210970037835270398289956157015064696375146357207576854029748413680946201805214954504282866534528711715039215051307866373994662368105368505465037259587291440042344663580680646178313958620437868058550744621854406871361710599007951099013146571208384054250556080476992977623024059268095813712424244902009427293468485e149",
      "1.4121319341572581270215359848706630542776633675711529687593487346259283960708095601494823112486631023721124235640943167173029348028743563902367757599140008654691320430919753414890689949599421028277624880392344132646738394546195638261279687543208503932172926275294218429086816560213399180179494004109164546844899632385177835442946174653663068675983237955855108059376913611877439522917217336109804190399e166",
      "3.8790307719997974510664339744260233373881096199933152202662556556779783775106563986911859526413282055258612522499767709123313205863879946518297779104337686883587019222829967005608205535314284003183828513113021722123872387036435113517356676447376715595408179555267871947671679098986651665719279348025058713817796876795915844151719103197410787508530261619841035613531487094949084263218956635085585632719e183",
      "7.8733605373835840397434523264038598405672829925651165847065668324385430746087633348848905637835428739401439679896923081980364912472282573695612463537585283007941057172128277340402716645674443632827653710173742423648839359547777694778576675604645880219833375227941998426325886558435214355022240854563558864080627758653439429917072753785194675103766900514602432580639079224631229479607396935864512990879e201",
      "1.1808262995038900942517891457926200063018079695348469762725520377876370005771518954251015338402886097689762895044056273430051256244413916763438966705458118354189107806216991150264176024521937328179762640422127608560103802431672144866013216405157197709788484197720057702118788168789816074560208078260433548283881535909071116553897893659656781376448427981358955547508806938614921874867135186509274509121e221",
      "1.3085817499987842655130548827168955655838432140245228169691892267707778790498773914833199368916114043966197329562444577848635313938483757629541576533880917215885485474416704968999200090496252044959849927443732134176975867869986011315975625868009065373046224716063168977788103866885720471095547385342868632018951910603936835789387464412366605713487321530237148912677199033012777178113821791621549557963e241",
      "1.0715308148006899161903881353829644069217121138682658034413051575604561649576261428568888094218620444635013220705511245290719605273316790249367622122178650529000528086055415007045458486410501636380119413632657994999412652188430063128470336817401482172580366374079331295129200936246446347832380606353293858222758687479612927181530236387227215663399410099251455256898414199913458340065553949424990477448e262",
      "6.483319651006309502237640505955012384293570932602353784849377890534620180296272226076424490097577093511886503973590409376477611667988893542117173598716788837179265384921201772013611631892729250835822804494742316330406688475091973437669111728949960922002370308207819760146543720499389938855072810566961589413895110830251224194598788696990065693705615156654866578134664648091752361824241438921952031149e283",
      "2.8985391304542768293172709775230767981477721528885408305355619530690119426207269563049756824939397157221877775531212262059946098575425050827283362457005503261796116156917077778477251551070762614233325253060283603452216492681531839154649232080928787066338399915850327381614672456102374248950210248266796072457623370079195574322846594267768883120374288952014885152055438195794090975578878933873824774214e306",
      "9.57524433627083921372674145950563946532138741951042299439035158875449060589509856903496678820625880407684156184675763001790613289835869844325821965070261880894138207436003366195024403902162467929095155787852409710735775347490909311196315332711680552044467458169615366116872469435840608534489425322247278926672059747911266981024366989976214521515026692183039600169984107883592297128416659318858313127e329",
      "2.3372734503362369375381009524197350830316472034721759761797536237738670471009423543542251572488229045699598160834162677357730620072441755506075897500940629883044875771104686291523502165266242030847074909362622098365719455332359938746138629161304717385265309980898079489959955157644566232440805137701071311495653330606071611331941246434767948905863368638163788562679785940566685500460815077065003612487e354",
      "4.2155879126937199240969909448599186868484717887298729605150033299123534992857332918168135230843738695925698383815575417820480732378749635394939513838137876524333991937836847074991505476867647762082587225838063325020413513077128321581439429001485977751765798011101092072613053687422983352140468569171564773941232256057064161142341661775359191159220450305300322654184921617310753474842253496677498824723e379",
      "5.6181811613375701248970224378256740494692066242437602652469740512738297599235414593999616891945156186827736326184687322137498447792007445397397290336810468925670064733464757082986791232916898141597610692740388799796632396708149027243436859752526805112778790645096555770227809873695589969805678601106157556386974221647669590827712353133603091803570183764883405340587430017053183637835511899658145649708e405",
      "5.532511069282205350923830187073466127274584467195468607886763750877294392993663821432158885753563495238131394373865428654052604326264330104646257659760161386620716716703631608643312613245804625511813964275109451513736558514977338129201153666764317441936156609643185133981728847167450887861106642311329612564652645663234240748195490808151911497393974690166034839217817023634217121406163178148652748479e432",
      "4.0256666306761331240653217136731531623017017695713942917027851762705346357330788586411431378972009980532310757689380174461664677676028378924382554201434975574729861177781849023768222381429947872325368088023224591306630434887529215459580760863075907686248521168590309636468448648513752893851767315693469638980874648457114335557202115472595647478331668869318302753802858726588719006447471192697846325955e460",
      "2.1644237346681663424601781769159797919834245365230735589058796985974745594485988855971413936820871935714602237643458356241187573307428309041919648027960168541647193436225977495680484218384107820095589356463058222584008532497069179993678533431131233629312850771528970443634604290143149079209513868130585713006080733488491160321145735562062411305931183571279530201672366980412430529846635995189699318073e489",
      "8.5987580981195983662047247216936066485731760315371506386077056691409579856014763032619539539935299716110411688793466397984311640631361934500807639285587334983206556915704635831992012926186843826981296831658998834850783404713050829093753126189556625095994621605300047199962332098857236359801681157419606676412198783092816364336047306243999363335004760439115355072350465422891365411868472688286678516314e518",
      "2.5241673163187127276134610716954724162270290228773641734420864618245211926017624829840685860130579257772126398622324109858115624706486522844752512951837805396709793171502497523431473021570806024043139443284538862368635312799539108264084028032731295487282188616820261689634926427135060887942797635147693849950058672753458576476491733064455826768562371858057444914175251596852571637211466017938478085247e549",
      "5.475067911823387661325942057081957044927796274441278042805014835144678321092623034147031518807063234976073102574257079170283458172046752719724152941316842521196069804425876507927418423409523739261726681120662097159943049401039490818332686968135012747332468921142470970507219403290422458185430415836291605355383658657658638112408092789126678938878667507151950931633694006471359998448912249374833586727e580",
      "8.7750549689950256776639468724574158629603320014390275681028674550826357080136422399476213432791376656222763800628593282303459051561266270006921840049305819767639184391149913915312831894296821356222752594264134130151457242713539248421883837353442181724530706933220158507240760325182068001553294949268596178418634164323874971937997072367419479635154591248667559627811893588163238012665671798461211917208e612",
      "1.0392000158337773273751156576416024664653679689973856373456304843339302977923254238376497044027728158058903302390909588333829463843362779584402914847447592731182614369968957680281500946805571235013941407979569788567794900810257154433592958167545186687137810101848000107335074486050959387974516414654638879740966175786016492797845169374594168995878543584318334800124941205910589727264397237600733483158e646",
      "9.0936326753636727240574546678839170665019169110943878894933093211555976995701468041449327370073681898690638466136204694745206283652338526673125958055131610409923286526192661778126811265116493171283319361595267283588121098349703951929669281966675596890266483864217591555707552765565756842701056144290075867893520379419521775913047964393758374891516340929062076304350159966063972713118995033247759001609e679",
      "5.8798281636930489964162009429009257867906792508058801627042121953599912951265315933723440185825519080102988056836911095299854840387008575164090793635997912930561430335216151607097220208013034399895832350235280120270626904356196935166701773768680311063264380891331021514518757839220818506905997847228783439015252768055166165941582030353226255576433910936297965207260585437762430381969160714956727596198e714",
      "2.8091881292911108404345975896815558958477835260737794579417284512413473388968057587088555041266297486841923628702282019643659456724373332519583025947015025975126598748630623031951723754960589046233996595466021913942587558326660593063197905288573353559106884645285531497626940379800500474282446929237914568534665868703742731713632349090897884403966643055728471509474896855575286123275564417626861566706e750",
      "9.917129372597671132067673866739246238179742417231064062960232866725337575281938597212073697168000155027158148165861617400080837699968785505107579831803685516054837447325150388867488754170677228096524224392410232206238263933144338637103531441623303187445874039234973380151391274490746625993568552049954630793219419614845431626975962881182662815760423226111647056071831411664335144052772436215105801395e786",
      "2.5869027163543111121878679987081647715187872826677398475096738640583659800068967379551376322170347537454918190603891312949716382621902484616361664158953484778255247083652726854621059785392022847887382779010079407502679229021085320675903109573769331277413372272363218896397965662581357886739691376204316908974081821980432178065394228926767529685562155837452626029223937027004015040825450642409597700449e824",
      "4.9861251931207080923785686798881789193813879610842675205361210155894774686328710893906543682447029206928934967525495260314937837003448878215156341411477636831113484416124080974502217578408248150338565305116223944900839866528622960352723938548713319425798453345402992146078868053263606234074443024155243450623634720912438841022969909473424559262711669905282193529250216454066716533180418518228387188393e862",
      "7.1012569014339068241101751233953234216522840280342406520909288232012799547871960723719836516359548198842749536961644100550279020276709043358260853581760590386456213180291689322352732545965831405519844109680619067101311180959399339922706596098526969148981173519865139508665631317310424178378833370605922449094745510812618563813537347841030916512147874232760564378443782164868016244561788356251308121716e901",
      "7.4730215360486642135431754747074885377840195683583018254892502245011973712084221116813364423492802080799768174534590613188275471080608467087354983850284805514875889145266688973752185071777341375422809910165581997555433091939959406569831183459872344778707098094941193489061532160249775856426569696127193453339548371679229676272663084782830276508737129506676031759345288056484158647796152349867328841634e941",
      "5.8109375364209112227579654658730977030869454388607076903639465992296616832002964138000947668837140543325908222688655359602408511410663722770167244801973012245657865182739637159804595049180263175014778215232564251739259624759589953677661356104554831551073263668188283861123521688445132164147762321111597028523130093864153999974376790494383016372210442340324038686843345053322425194077414241243050491297e982",
      "3.33875955701899627718146291382268063073604182131575843695486667154496711979350813988644889979275310892951143249901398447859083674739840084454465850475774696325142148671937407108540250845900941142800157345665761403930889797424808979569550325271558518404559007551625637761142662107757913763221912282957681784053564387104062317729788737215450574233690655931888608424916152893688106181220341997128198692e1024",
      "1.4174672877823334709610117319768830739080734407353905145632612088824955720198734996604261250019291955883620333545750761619015467840567122066622229379056280064206319780047687015558007624774062399477328822231085767309831266032616053065858739373818651687128093335640388513396191118537181280334430292439188737524362269789272308905723812818882228503013875816702686587035844437102478263525616196832018321602e1067",
      "4.4466189016791091516801723880812533528438597080549410911235655611382010503145789286158745555771483577943662768773465284793798720178177605712848440200402906836390133865748188969184005230383247111166918721449908133920663776952786683837038180436264738937354101153867171804315769471050303182129269442292354388037298125177941217926845803005587166270803697433886463469168814941555804311717400657004050157245e1110",
   }};

   T eg = static_cast<T>("5.77215664901532860606512090082402431042159335939923598805767234884867726777664670936947063291746749514631447249807082480960504014486542836224173997644923536253500333742937337737673942792595258247094916008735203948165670853233151776611528621199501507984793745085705740029921354786146694029604325421519e-1");

   unsigned max_err = 0;
   for(unsigned k = 0; k < data.size(); k++)
   {
      const T x = eg + k;
      T val = boost::multiprecision::sinh(x * x);
      T e = relative_error(val, T(data[k]));
      unsigned err = e.template convert_to<unsigned>();
      if(err > max_err)
         max_err = err;
      val = boost::multiprecision::sinh(-x * x);
      e = relative_error(val, T(-T(data[k])));
      err = e.template convert_to<unsigned>();
      if(err > max_err)
         max_err = err;
   }

   boost::array<const char*, 50> small_values =
   {{
      "8.223167319358299807036616344469138485821440027829633696917375433348917938654659351596020080036406671343718039863220496616e-01",
      "2.526123168081683079141251505420579055197542874276608074880949653019810769068593790606537020961198741487692473633089323967e-01",
      "8.342981744595282037256218647969712476322487890550784823763249893556153270975172951404094950587944959561849750490537201329e-02",
      "2.778135016068299789938671680845480653984976507019542653788637161116587306168290886761259072846829249121589698206609261524e-02",
      "9.259391565199916442789400306996794489540862711193761818262415211084389468754315525525896238827358889826875006042447587516e-03",
      "3.086424653287772358219607529932097884435043040527155440187640095572710676452654803730003577747633690318001961509535020849e-03",
      "1.028806765851002064810061084014826478832745077469708149635730407866217436751337520417458090265791086156438275231514030381e-03",
      "3.429355348425226988441198390119109217716503769838753365112550442738406326637684639052252898314646892490045395290022292013e-04",
      "1.143118429558603374406653541544292690548937361618336125287018361332072426474632105217297150810234138626767253281422813482e-04",
      "3.810394757818873406266877296641684693312194735341898368873067089928172619067423751257049691985638480762032673977695116880e-05",
      "1.270131585666421832817527834137477593266387525701388601975733237436369505733715799310429349744168792375082834509467436523e-05",
      "4.233771952120219947940459634636576539101577724347428305072378100562649548884420218224692461748739725090626754420296122389e-06",
      "1.411257317369659013704209000288436132710449162963127340562961271337242582661013580874165903770246169179192268836124421074e-06",
      "4.704191057897475365825409916786898392364235667906752767514580467152163619657508910797742266406961516358439252434955007668e-07",
      "1.568063685965773714045928492719360014894368531987759414833778466374819836545157375950693756664550256136222396871173634254e-07",
      "5.226878953219226673524993193392503058475862017726848548717100658392470633650387274004511940515056405069137033934323251644e-08",
      "1.742292984406408185991240874995689487745140228031202510923711784729440494088066989430128101759261047316736074663327672115e-08",
      "5.807643281354693692124967044009687283114597355717062156493618245876910131607338183944830908381903728560328284173507220743e-09",
      "1.935881093784897887701686451485601671131342930785061493703969418728524594573922282309665275558709040519461560600768780392e-09",
      "6.452936979282992955422916851920785543106383715381924626175995859924351552325880931187614903984801793287071578640505194508e-10",
      "2.150978993094330985008279519046512957825521218238790792201835497215534851989750722105234826300738623838446309250309905466e-10",
      "7.169929976981103283311786261663531258230547972690500493476881079295129579131280734024784107219045379345460886663104148486e-11",
      "2.389976658993701094435441884684454421835327948893136184573938864819002944442339456827931472237274353903634036758669394620e-11",
      "7.966588863312336981450798799860506345287566898810744342680146925029151178981033890759916168189916177504592939240995619757e-12",
      "2.655529621104112327150241298135440075805848488054800577703768668100658036999584228451100239039042920681377381394421710121e-12",
      "8.851765403680374423834128412864530361591097252230621965426275532533242581680245794741067906285298655116802944992368126680e-13",
      "2.950588467893458141278042461784956914687338675140497707333871358819185395356569206661450997145748756956497959702280685427e-13",
      "9.835294892978193804260141412430145318398649753331401112621871794012928366988233744354238387090649589382104704221708773516e-14",
      "3.278431630992731268086713799445120869198593899364655036314007566906378666339665297288092596796135684816883503781385164489e-14",
      "1.092810543664243756028904599641030626636532928735904320784337625844108091213506619051042206148385975354700234586478575025e-14",
      "3.642701812214145853429681998738987398752764686754626492252324567456938623579239392678142797020213493844816454129960310753e-15",
      "1.214233937404715284476560666243942169089106312534317920490462975351305354471020532764015606315872085933262687299655265697e-15",
      "4.047446458015717614921868887478923169619805517194433471908835726595116905187672132801369948377551282604828733616045843751e-16",
      "1.349148819338572538307289629159608313551890152969010184597042496758528297346351553643241208769191557898925543369605617734e-16",
      "4.497162731128575127690965430532015584807024576774799020494128293451281927637267192489558050090835454302448780391749096414e-17",
      "1.499054243709525042563655143510671412452985626833998379862387948592418229228808284088934491020852037924756758483008288052e-17",
      "4.996847479031750141878850478368904541825005460277179305602161748681654262243578435201096986093377131577325573917436618470e-18",
      "1.665615826343916713959616826122968174447164290616980189746184851537351248309665330601503343215376981550822569162631313560e-18",
      "5.552052754479722379865389420409893912541965834349657578615232567585047309856390957625702896178052275806406957076143469634e-19",
      "1.850684251493240793288463140136631304096139902769381795814754672989850701401641374814254071564872119933498619234778448524e-19",
      "6.168947504977469310961543800455437680289164351695283493312025632359317744715643192414807145394613572397590534364339391526e-20",
      "2.056315834992489770320514600151812560095228784236601072113743484455321300338926430301421880927367590178440922006775473367e-20",
      "6.854386116641632567735048667172708533650333231531203539518552950777817440179277823487619201513258000884052637516041835420e-21",
      "2.284795372213877522578349555724236177883428507451482660054557452824460619777642844796449091646418601791047308814504431261e-21",
      "7.615984574046258408594498519080787259611422468149787192854095139994568043598766360557598146279482678180281335390895949036e-22",
      "2.538661524682086136198166173026929086537140604567639372655275057673980680372673609490963070062819520295998328327889923353e-22",
      "8.462205082273620453993887243423096955123801934429554813185698344472203995997708879527322555715697860578416576045982358004e-23",
      "2.820735027424540151331295747807698985041267308484077168753311108116374235508697904826049959781116012127075951788533527897e-23",
      "9.402450091415133837770985826025663283470891027171945709804152456669015193736201020401750153196590359525341207466344738924e-24",
      "3.134150030471711279256995275341887761156963675682933328476437810109959425395050019306074135780459168092270327572635795510e-24",
   }};

   max_err = 0;
   T v = 0.75;
   for(unsigned k = 0; k < small_values.size(); ++k)
   {
      T val = boost::multiprecision::sinh(v);
      T e = relative_error(val, T(small_values[k]));
      unsigned err = e.template convert_to<unsigned>();
      if(err > max_err)
      {
         max_err = err;
      }
      val = boost::multiprecision::sinh(-v);
      e = relative_error(val, T(-T(small_values[k])));
      err = e.template convert_to<unsigned>();
      if(err > max_err)
      {
         max_err = err;
      }
      v /= 3;
   }

   std::cout << "Max error was: " << max_err << std::endl;
   BOOST_TEST(max_err < 2000);
}
示例#10
0
void test()
{
   std::cout << "Testing type " << typeid(T).name() << std::endl;
   static const boost::array<const char*, 51u> data =
   {{
      "1.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
      "9.47747587596218770242116751705184563668845029215054154915126374673142219159548534317576897266130328412495991561490384353e76",
      "8.98225489794452370997623936390755615068333094834545092387689795875746440121970819499035111276893290879203289092353747850e153",
      "8.51291041070124257524798251795398355552294928156627848633073113916721592074889256105483993631579761345100284245144410506e230",
      "8.06809030516483860484254925989129017112482132468761563276276594763374886826841745433660192438855214332469192411759402790e307",
      "7.64651312322841630493169711336894888932951818957138997327518186691187347879142222644283389432604713409023263917264358401e384",
      "7.24696436606255985380192585665173794455118215150711210905481870053193336336731228464367470327868286988180495111406609690e461",
      "6.86829299533155197480610865771404565313986987801060270120621935139741577246731459024227828759564450034267891072352816870e538",
      "6.50940811722948585242669672360741252715012399316164518226061001845519670701239429603657927628755169479689062519606799624e615",
      "6.16927583978348964454665652571294215251327375137123272041877979478545511090085756858225302357977159539777447847855503405e692",
      "5.84691629437043896753869572004324228849833391140408095171257918435296982661233664069534601413835876272500275725690968474e769",
      "5.54140081286660645835370762406928689330724181979654545550204201113926269281603301564114980528619942840737770415885783439e846",
      "5.25184925229805200184933663459660562493261505058724212670923083643709964294855282715531768162298567379648573804433968486e923",
      "4.97742745928448409225535325233998957076879979440190164347796593390995994951755710667491911026476108957070504003155645761e1000",
      "4.71734486697204622371883518659702954552385115723942808636490157561056417525827884479573988899517566587636669779645610803e1077",
      "4.47085221753216236037602345430121605512330975424643767098987010800161616413051148037751552110081034066081309007796182114e1154",
      "4.23723940366531198300986713567588008777043812458400705569721660157434941774066620870256745107265536124077734836797938268e1231",
      "4.01583342289144005397455901781647949754375366066998182220342540048111140676724909947493787596336610499122085983712119281e1308",
      "3.80599643873362813900306284477369187319506389058898599816705625750135796510808933786432614186155972485637939057212164098e1385",
      "3.60712394320959592074309301816510372687695286650188776957291994751966018917404878612237961367128638199290387601511358836e1462",
      "3.41864301533745457066062991907289263038319874930395315315257927161138360206596116102724713069518697248463965164712972907e1539",
      "3.24001067063873569456703204286462007769933831045558617578289414699244767403736057931834775727420762410328297596596814910e1616",
      "3.07071229688386868087623659761166306563170839771162347830514606977592027644137144160294469813988158463967740978461420862e1693",
      "2.91026017157373047094077218552378456052150304677863670611408570458991015300131731261787644801415538043027268185097710615e1770",
      "2.75819205688636078700279174380111581147323147951670302427494196210176478494486073721584055059489736040565979466551070179e1847",
      "2.61406986804110104534167739704643351039975992759905579635058824027507742375380077276380178376470686987855503581867681046e1924",
      "2.47747841124391945459619002346303925269640785743990333362087223895627681769816204236257960940497519376881830373722711456e2001",
      "2.34802418757813746316913800667907927718925648696508255347624141597281474683823345136640610924639820192825966082309575303e2078",
      "2.22533425939475124828943430510333464605535146852848680647615867629953075390889821397228584866395924176189346073006180260e2155",
      "2.10905517593659363154553947631071808925462553114068144748077359132255993441363479041540672158497404660986163617828972963e2232",
      "1.99885195510122536266653916064141606295420554580140619900425370702471778604391774578696867899999534265169574306808906810e2309",
      "1.89440711840917173277691572886942144916664047407963356271198286654087884646102070148271284410118233470318337745546895603e2386",
      "1.79541977639739687088375911648976940254141946934175300605485966288703931992861387257771264702798405630917098672594899744e2463",
      "1.70160476180317540861346545791118106171203487587101437710693054174454895160403997508137760007058856854991413121389834429e2540",
      "1.61269180804119796097157014527479883521656118500417752963675677684343588976915851637637232001139108420659882326614772004e2617",
      "1.52842477060722969066998464046690349841548269556677423378408183476489015878816585045578141383463708674469365281537792914e2694",
      "1.44856088916530600122626623629347336702026699647293500058111037526381692645547938577338582002157148103479049071921438452e2771",
      "1.37287008819265239873777879432333192404914357037749380145412895230166352318128978403808382142784030558123748263528360645e2848",
      "1.30113431416759441771790128053911040907207490879890145597562380328956450092799014856149474809345424672958343296615764490e2925",
      "1.23314690739099822369963411660419632130352733806319401863570442920347696015409870236230656305563674376063778482449716744e3002",
      "1.16871200663155636468514484039368694043851858077879103221831997264419096417014996945143145495038265243932745953706526253e3079",
      "1.10764398487979357804590117089134596938734185016144401218934115168561552640448889215089150481162977776214124397487013110e3156",
      "1.04976691458528698318220729857405616816444374000182094405930946710168752954926612218474430081526312018810817657409158490e3233",
      "9.94914060836531582868347569174220216007647278536863127198023584205669825317884219144692385409156165042162234017403353704e3309",
      "9.42927401023380446961314339401657458785389811652244742482194123119943160577946366372207045050095290781679375214307398844e3386",
      "8.93657169598281164656322298275337750103095739790107943666668184304335665562867744740310577868880098719252549186849812451e3463",
      "8.46961426624835911826517103631490619655296714141872141145089865045804196205328364155921945616925875458926717336478525196e3540",
      "8.02705648870740089929294815816002943860908317454595055392168733404583122074223427054310572378841634984243492063192095337e3617",
      "7.60762342267101369970765191988545810374824800500875923752736467467657167098026707905341603949108433696304383346239333297e3694",
      "7.21010674617694221027190468649359000420209460539838589305387835463807416706224777302997789297329446308541513638035437482e3771",
      "6.83336127500041943234365059231968669406267422759442985746460610830503287734479988530512309065240678799786759250323660701e3848",
   }};

   T pi = static_cast<T>("3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273724587006606315588174881520920962829254091715364367892590360011330530548820466521384146951941511609");

   unsigned max_err = 0;
   for(unsigned k = 0; k < data.size(); k++)
   {
      T val = exp(sqrt((pi * (100 * k)) * (100 * k)));
      T e = relative_error(val, T(data[k]));
      unsigned err = e.template convert_to<unsigned>();
      if(err > max_err)
      {
         max_err = err;
      }
      val = exp(-sqrt((pi * (100 * k)) * (100 * k)));
      e = relative_error(val, T(1/T(data[k])));
      err = e.template convert_to<unsigned>();
      if(err > max_err)
      {
         max_err = err;
      }
   }
   std::cout << "Max error was: " << max_err << std::endl;
#if defined(BOOST_INTEL) && defined(TEST_FLOAT128)
   BOOST_TEST(max_err < 40000);
#elif defined(TEST_CPP_BIN_FLOAT)
   BOOST_TEST(max_err < 6000);
#else
   BOOST_TEST(max_err < 5000);
#endif

   static const boost::array<boost::array<T, 2>, 10> exact_data =
   {{
      {{ std::ldexp(1.0, -50), static_cast<T>("1.00000000000000088817841970012562676935794497867573073630970950828771105957980924149923657574337470594698012676100224953") }},
      {{ std::ldexp(1.0, -20), static_cast<T>("1.00000095367477115374544678824955687428365188553281789775169686343569285229334215539516690752571791280462887427635269562") }},
      {{ std::ldexp(1.0, -10), static_cast<T>("1.00097703949241653524284529261160650646585162918174419940186408264916250428896869173656853690882467186075613761065459261") }},
      {{ 0.25, static_cast<T>("1.28402541668774148407342056806243645833628086528146308921750729687220776586723800275330641943955356890166283174967968731") }},
      {{ 0.5, static_cast<T>("1.64872127070012814684865078781416357165377610071014801157507931164066102119421560863277652005636664300286663775630779700") }},
      {{ 0.75, static_cast<T>("2.11700001661267466854536981983709561013449158470240342177913303081098453336401282000279156026661579821888590471901551426") }},
      {{ 10, static_cast<T>("22026.4657948067165169579006452842443663535126185567810742354263552252028185707925751991209681645258954515555010924578367") }},
      {{ 10.5, static_cast<T>("36315.5026742466377389120269013166179689315579671275857607480190550842856628099187749764427758174866310742771977376827512") }},
      {{ 25, static_cast<T>("7.20048993373858725241613514661261579152235338133952787362213864472320593107782569745000325654258093194727871848859163684e10") }},
      {{ 31.25, static_cast<T>("3.72994612957188849046766396046821396700589012875701157893019118883826370993674081486706667149871508642909416337810227575e13") }},
   }};

   max_err = 0;
   for(unsigned k = 0; k < exact_data.size(); k++)
   {
      T val = exp(exact_data[k][0]);
      T e = relative_error(val, exact_data[k][1]);
      unsigned err = e.template convert_to<unsigned>();
      if(err > max_err)
      {
         max_err = err;
      }
      val = exp(-exact_data[k][0]);
      e = relative_error(val, T(1/exact_data[k][1]));
      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 < 20);

   BOOST_TEST(exp(T(0)) == 1);
}
示例#11
0
void test()
{
   std::cout << "Testing type: " << typeid(T).name() << std::endl;
   static const boost::array<const char*, 51u> data =
   {{
      "9.999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999966666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666667e-101",
         "9.999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999996666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666668666666666666667e-97",
         "9.999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666686666666666666666666666666666667e-93",
         "9.999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999966666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666866666666666666666666666666666666666666666666667e-89",
         "9.999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999996666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666668666666666666666666666666666666666666666666666666666666666666667e-85",
         "9.999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666686666666666666666666666666666666666666666666666666666666666666666666666666666667e-81",
         "9.999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999966666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666866666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666667e-77",
         "9.999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999996666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666668666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666667e-73",
         "9.999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666686666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666667e-69",
         "9.999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999966666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666866666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666665238095238095238e-65",
         "9.999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999996666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666668666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666665238095238095238095238095238095238095238e-61",
         "9.999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666686666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666665238095238095238095238095238095238095238095238095238095238095238e-57",
         "9.999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999966666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666866666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666665238095238095238095238095238095238095238095238095238095238095238095238095238095238095238e-53",
         "9.999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999996666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666668666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666665238095238095238095238095238095238095238095238095238095238095238095238095238095238095238095238096349206349206349e-49",
         "9.999999999999999999999999999999999999999999999999999999999999999999999999999999999999999666666666666666666666666666666666666666666666666666666666666666666666666666666666666666686666666666666666666666666666666666666666666666666666666666666666666666666666666666666665238095238095238095238095238095238095238095238095238095238095238095238095238095238095238206349206349206349206349206349206349206349206349e-45",
         "9.999999999999999999999999999999999999999999999999999999999999999999999999999999966666666666666666666666666666666666666666666666666666666666666666666666666666666866666666666666666666666666666666666666666666666666666666666666666666666666666665238095238095238095238095238095238095238095238095238095238095238095238095238095249206349206349206349206349206349206349206349206349206349206349206349206349206349e-41",
         "9.99999999999999999999999999999999999999999999999999999999999999999999999666666666666666666666666666666666666666666666666666666666666666666666666866666666666666666666666666666666666666666666666666666666666666666666666523809523809523809523809523809523809523809523809523809523809523809523809634920634920634920634920634920634920634920634920634920634920634920634920544011544011544011544011544011544011544e-37",
         "9.999999999999999999999999999999999999999999999999999999999999999666666666666666666666666666666666666666666666666666666666666666686666666666666666666666666666666666666666666666666666666666666665238095238095238095238095238095238095238095238095238095238095238206349206349206349206349206349206349206349206349206349206349206340115440115440115440115440115440115440115440115440115440115440116209346209346209e-33",
         "9.999999999999999999999999999999999999999999999999999999966666666666666666666666666666666666666666666666666666666866666666666666666666666666666666666666666666666666666665238095238095238095238095238095238095238095238095238095249206349206349206349206349206349206349206349206349206349115440115440115440115440115440115440115440115440115440116209346209346209346209346209346209346209346209346209346202679543e-29",
         "9.99999999999999999999999999999999999999999999999666666666666666666666666666666666666666666666666866666666666666666666666666666666666666666666666523809523809523809523809523809523809523809523809634920634920634920634920634920634920634920634920544011544011544011544011544011544011544011544011620934620934620934620934620934620934620934620934554267954267954267954267954267954267954267954268013091483679719e-25",
         "9.999999999999999999999999999999999999999666666666666666666666666666666666666666686666666666666666666666666666666666666665238095238095238095238095238095238095238206349206349206349206349206349206349206340115440115440115440115440115440115440116209346209346209346209346209346209346209279542679542679542679542679542679542679548561895620719150130914836797189738366208428128459088211410192834341441152586663e-21",
         "9.999999999999999999999999999999966666666666666666666666666666666866666666666666666666666666666665238095238095238095238095238095249206349206349206349206349206349115440115440115440115440115440116209346209346209346209346209346202679542679542679542679542679542738366208954444248561895620719149604599047323505527839893164970569113274066834438351466215243304983108499463325146458811824271509689681318218133e-17",
         "9.999999999999999999999996666666666666666666666668666666666666666666666665238095238095238095238096349206349206349206349205440115440115440115440116209346209346209346209345542679542679542679542680130914836797189738366208428128459088211410192834817631628777139613052925311641589740930163598087002528653948764327011735444703713649735994600714288656350334489593033695272837185114343249547095046272603174268e-13",
         "9.999999999999999666666666666666686666666666666665238095238095238206349206349206340115440115440116209346209346209279542679542679548561895620719149604599047323505575458940784018179051162265592202726621494746410579611835097095566286199717626418813764642659343446728207455753397291482030056516178836684094391777365260695851470017381944166954115569576329193296454393446430574957840819236721213626802085619e-9",
         "0.00009999999966666666866666665238095249206349115440116209346202679542738366208428128463850116128619335776637836253560167434464812879197215298894881707269927081030999737549925482008672363799937606915962379247584324159094536421375755997513179578610677454920512897850953612762990732913046921088456079984429888220262137400213929962691532176198436788640624698990926490105259050461938357510947570244880435664081",
         "0.78539816339744830961566084581987572104929234984377645524373614807695410157155224965700870633552926699553702162832057666177346115238764555793133985203212027936257102567548463027638991115573723873259549110720274391648336153211891205844669579131780047728641214173086508715261358166205334840181506228531843114675165157889704372038023024070731352292884109197314759000283263263720511663034603673798537790236",
         "1.5706963267952299525626550249873704896065212085331517483940102693584808194810202180293789115097723406333076648941055516492022741759833189628737308869915412879148320539754700057326930986734751013960313584219296445913757777000240665569182597868494941800236191544832206381775972559949762275927455637707925634113006817837919481411335451596526426779712759369563859151046126747697908496855825977735219514481",
         "1.5707963167948966192313220249730847754318980330208862438222342009158129649367552929648110725556184185509578339104318071142673796252326115673007840833450909541260947278453938016119958041324233151995987794877839930865561434524027270213271053829179745357590596408023867275770197075707094053216000680544580256094089113804288267449089904640326828789035666143699659867092108718279796583028512542392495421779",
         "1.5707963267938966192313216916397514424319180330208862438208054294872415364764378326474936031472490101815502336217205184029120016698547471043186681600526965471042074304163483259318452680435202095109230279463923963492870040904012032740805456738144599352893425202988524603439218707929425378295371082108281620406379082813613862672159901100496534463976107550806601465567059619048829495421806391510160463001",
         "1.5707963267948965192313216916397514420985846996878862438208056294872415364764378306473507460043918673244073765899887723711659699238229101634817272120007484952330785592874771970616254211570733230640365810600043257395046296021443620234312981206088055277773974880349347475097997796620171523611445056144296707974573126845590321623615288317089359131170138395627805178532322154433252386274406088878525130896",
         "1.5707963267948966192213216916397514420985846996875529104874726294872415364764378326473507460043918673044073765899744866568802556381086244491974416088261453206299039561128740224575416159622681282588417758651991386266175167241223840014532761425201608391327088433455208280958809539778973505942839152244275827508237604782514078980809178018719474972957865632271450490908284680846718670522639450168825443945",
         "1.5707963267948966192313206916397514420985846996875529104874722961539082034764378326473507460043918673244073765899744866566802556381086244491960130373975738920584753846844454510289702985019506679413814584048816783091570881436029034819727566620006803196521893628268096302936831517800951527920861130266253182819592915368594665061395258604800061112367475630116742454513973110064559653064241192080164878504",
         "1.5707963267948966192313216915397514420985846996875529104874722961539082031431044993143507460043918673244073765899744866568802556381086244491940130373975738920584753846843025938861131556448078107985386012620245354520143421118568717359410106302546485736203322199696666822417350998320432047401380610785733702300121487566396862863593060802602258914565277827918940256045031718123167711672299800138772937113",
         "1.5707963267948966192313216916397414420985846996875529104874722961539082031431044993140174126710588673244073765899744866568802556381086244491960130373975738920584553846843025938861131556448078107985243155477388211663000563975725860216552963445403628593347290453664920790671319252288686015654237753642876559442969539514448810915541112750654206966513329776061797398902251498342947931452519580358553156893",
         "1.5707963267948966192313216916397514410985846996875529104874722961539082031431044993140174126710585339910740435899744866568802556381086244491960130373975738920584753846843025938861129556448078107985243155477388211663000563975711574502267249159689342879063004739379206504957033538002971729941063150468273384839794936339845636311255398464939921252227615490256602593707446303537753126257714385553358352607",
         "1.5707963267948966192313216916397514420984846996875529104874722961539082031431044993140174126710585339910740432566411533238802556381086244491960130373975738920584753846843025938861131556448078107985243135477388211663000563975711574502267249159689342879061576167950635076385604966574543158512491721896844813411223507768417064883795081004622460934767298029939142275136017732109181697686285814124786923127",
         "1.5707963267948966192313216916397514420985846896875529104874722961539082031431044993140174126710585339910740432566411533235469223047756244491960130373975738920584753846843025938861131556448078107985243155477388211663000563775711574502267249159689342879061576167950635076385604966574400301369634579039701956268380650625559922026652223861765318077624440887081999419104271700363149951654539782378755175984",
         "1.5707963267948966192313216916397514420985846996865529104874722961539082031431044993140174126710585339910740432566411533235469223047752911158626800373975738920584753846843025938861131556448078107985243155477388211663000563975711574502267249157689342879061576167950635076385604966574400301369634579039701956268366364911274207740937938147481032363338726601367713704818557414648864237368825496664469462809",
         "1.5707963267948966192313216916397514420985846996875528104874722961539082031431044993140174126710585339910740432566411533235469223047752911158626797040642405590584753846843025938861131556448078107985243155477388211663000563975711574502267249159689342879061576167930635076385604966574400301369634579039701956268366364911274207740937938147479603791910155172796285133390128843220292808797396925235898034238",
         "1.5707963267948966192313216916397514420985846996875529104774722961539082031431044993140174126710585339910740432566411533235469223047752911158626797040642405587251420513513025938861131556448078107985243155477388211663000563975711574502267249159689342879061576167950635076385604966574200301369634579039701956268366364911274207740937938147479603791910155172796285133389985986077435665940254068093055177095",
         "1.570796326794896619231321691639751442098584699687552910487471296153908203143104499314017412671058533991074043256641153323546922304775291115862679704064240558725142051350969260552780155644807810798524315547738821166300056397571157450226724915968934287906157616795063507638560496657440030136963457903969995626836636491127420774093793814747960379191015517279628513338998598607743566594025406809304089138",
         "1.570796326794896619231321691639751442098584699687552910487472296053908203143104499314017412671058533991074043256641153323546922304775291115862679704064240558725142051350969260552779822311474477798524315547738821166300056397571157450226724915968934287906157616795063507638560496657440030136963457903970195626836636491127418774093793814747960379191015517279628513338998598607743566594025406809304089138",
         "1.570796326794896619231321691639751442098584699687552910487472296153898203143104499314017412671058533991074043256641153323546922304775291115862679704064240558725142051350969260552779822311474477465190982214738821166300056397571157450226724915968934287906157616795063507638560496657440030136963457903970195626836636491127420774093793814747960359191015517279628513338998598607743566594025406809304089138",
         "1.570796326794896619231321691639751442098584699687552910487472296153908202143104499314017412671058533991074043256641153323546922304775291115862679704064240558725142051350969260552779822311474477465190982214405487832967056397571157450226724915968934287906157616795063507638560496657440030136963457903970195626836636491127420774093793814747960379191015517279628513138998598607743566594025406809304089138",
         "1.570796326794896619231321691639751442098584699687552910487472296153908203143004499314017412671058533991074043256641153323546922304775291115862679704064240558725142051350969260552779822311474477465190982214405487832966723064237824450226724915968934287906157616795063507638560496657440030136963457903970195626836636491127420774093793814747960379191015517279628513338998598607743566592025406809304089138",
         "1.570796326794896619231321691639751442098584699687552910487472296153908203143104489314017412671058533991074043256641153323546922304775291115862679704064240558725142051350969260552779822311474477465190982214405487832966723064237824116893391582968934287906157616795063507638560496657440030136963457903970195626836636491127420774093793814747960379191015517279628513338998598607743566594025406809304089138",
         "1.570796326794896619231321691639751442098584699687552910487472296153908203143104499313017412671058533991074043256641153323546922304775291115862679704064240558725142051350969260552779822311474477465190982214405487832966723064237824116893391582635600954573157616795063507638560496657440030136963457903970195626836636491127420774093793814747960379191015517279628513338998598607743566594025406809304089138",
         "1.570796326794896619231321691639751442098584699687552910487472296153908203143104499314017312671058533991074043256641153323546922304775291115862679704064240558725142051350969260552779822311474477465190982214405487832966723064237824116893391582635600954572824283461730507638560496657440030136963457903970195626836636491127420774093793814747960379191015517279628513338998598607743566594025406809304089138",
         "1.570796326794896619231321691639751442098584699687552910487472296153908203143104499314017412661058533991074043256641153323546922304775291115862679704064240558725142051350969260552779822311474477465190982214405487832966723064237824116893391582635600954572824283461730174305227163657440030136963457903970195626836636491127420774093793814747960379191015517279628513338998598607743566594025406809304089138",
         "1.570796326794896619231321691639751442098584699687552910487472296153908203143104499314017412671057533991074043256641153323546922304775291115862679704064240558725142051350969260552779822311474477465190982214405487832966723064237824116893391582635600954572824283461730174305227163324106696803963457903970195626836636491127420774093793814747960379191015517279628513338998598607743566594025406809304089138",
         "1.570796326794896619231321691639751442098584699687552910487472296153908203143104499314017412671058533891074043256641153323546922304775291115862679704064240558725142051350969260552779822311474477465190982214405487832966723064237824116893391582635600954572824283461730174305227163324106696803630124570637195626836636491127420774093793814747960379191015517279628513338998598607743566594025406809304089138",
   }};

   T arg = static_cast<T>("1e-100");

   unsigned max_err = 0;
   for(unsigned k = 0; k < data.size(); k++)
   {
      T val = atan(arg);
      T e = relative_error(val, T(data[k]));
      unsigned err = e.template convert_to<unsigned>();
      if(err > max_err)
         max_err = err;
      val = atan(-arg);
      e = relative_error(val, T(-T(data[k])));
      err = e.template convert_to<unsigned>();
      if(err > max_err)
      {
         max_err = err;
      }
      arg *= 10000;
   }
   std::cout << "Max error was: " << max_err << std::endl;
   BOOST_TEST(max_err < 10);
   BOOST_TEST(atan(T(0)) == 0);

   //
   // And again, but test all the phases of atan2:
   //
   arg = static_cast<T>("1e-100");
   unsigned err;
   for(unsigned k = 0; k < data.size(); k++)
   {
      T val = atan2(arg, 1);
      T e = relative_error(val, atan2_def(arg, T(1)));
      err = e.template convert_to<unsigned>();
      if(err > max_err)
      {
         max_err = err;
      }
      val = atan2(-arg, 1);
      e = relative_error(val, atan2_def(T(-arg), T(1)));
      err = e.template convert_to<unsigned>();
      if(err > max_err)
      {
         max_err = err;
      }
      val = atan2(arg, -1);
      e = relative_error(val, atan2_def(arg, T(-1)));
      err = e.template convert_to<unsigned>();
      if(err > max_err)
      {
         max_err = err;
      }
      val = atan2(-arg, -1);
      e = relative_error(val, atan2_def(T(-arg), T(-1)));
      err = e.template convert_to<unsigned>();
      if(err > max_err)
      {
         max_err = err;
      }
      arg *= 10000;
   }
   //
   // special cases:
   //
   err = relative_error(T(atan2(T(0), T(1))), atan2_def(T(0), T(1))).template convert_to<unsigned>();
   if(err > max_err)
      max_err = err;
   if(!boost::multiprecision::is_interval_number<T>::value)
   {
      // We don't test this with intervals as [-0,0] leads to strange behaviour in atan2...
      err = relative_error(T(atan2(T(0), T(-1))), atan2_def(T(0), T(-1))).template convert_to<unsigned>();
      if(err > max_err)
         max_err = err;
   }

   T pi;
   pi.backend() = boost::multiprecision::default_ops::get_constant_pi<typename T::backend_type>();

   err = relative_error(T(atan2(T(1), T(0))), T(pi / 2)).template convert_to<unsigned>();
   if(err > max_err)
      max_err = err;

   err = relative_error(T(atan2(T(-1), T(0))), T(pi / -2)).template convert_to<unsigned>();
   if(err > max_err)
      max_err = err;

   T mv = (std::numeric_limits<T>::max)();
   err = relative_error(T(atan2(mv, T(1))), T(pi / 2)).template convert_to<unsigned>();
   if(err > max_err)
      max_err = err;
   err = relative_error(T(atan2(-mv, T(1))), T(pi / -2)).template convert_to<unsigned>();
   if(err > max_err)
      max_err = err;

   if(std::numeric_limits<T>::has_infinity)
   {
      mv = (std::numeric_limits<T>::infinity)();
      err = relative_error(T(atan2(mv, T(1))), T(pi / 2)).template convert_to<unsigned>();
      if(err > max_err)
         max_err = err;
      err = relative_error(T(atan2(-mv, T(1))), T(pi / -2)).template convert_to<unsigned>();
      if(err > max_err)
         max_err = err;
   }

   std::cout << "Max error was: " << max_err << std::endl;
   BOOST_TEST(max_err < 2000);
}
示例#12
0
int main(int argc, char *argv[]) {
    benchmark_t benchmarks[] = {
        (benchmark_t){"sht", setup_sht, execute_sht, finish_sht, 1, 0.0},
#if HAS_PSHT
        (benchmark_t){"psht", setup_psht, execute_psht, finish_psht, 1, 0.0},
#endif
        {NULL, NULL, NULL, NULL, 0, 0.0}
    };

    benchmark_t *sht_benchmark = &benchmarks[0];
    benchmark_t *psht_benchmark = &benchmarks[1];

    double t0, t1, dtmin, tit0, tit1, dt;
    int n, i, j, should_run;
    benchmark_t *pbench;
#ifdef HAS_PPROF
    char profilefile[MAXPATH];
#endif
    char *resourcename;
    char timestr1[MAXTIME], timestr2[MAXTIME];

    char *stats_filename = NULL;
    char *stats_mode;

    int c;
    int got_threads, miniter;
    double mintime;
    char *resource_path;

    /* Parse options */
    sht_resourcefile = NULL;
    Nside = -1;
    miniter = 1;
    mintime = 0;
    opterr = 0;
    sht_nmaps = 1;
    do_ffts = -1;
    sht_flags = WAVEMOTH_MEASURE;

    while ((c = getopt (argc, argv, "r:N:j:n:t:S:k:a:o:FEC")) != -1) {
        switch (c) {
        case 'r':
            sht_resourcefile = optarg;
            break;
        case 'N':
            Nside = atoi(optarg);
            break;
        case 'j':
            N_threads = atoi(optarg);
            break;
        case 'n':
            miniter = atoi(optarg);
            break;
        case 't':
            mintime = atof(optarg);
            break;
        case 'E':
            sht_flags &= ~WAVEMOTH_MEASURE;
            break;
        case 'C':
            sht_flags |= WAVEMOTH_NO_RESOURCE_COPY;
            break;
        case 'a':
            stats_filename = optarg;
            stats_mode = "a";
            break;
        case 'o':
            stats_filename = optarg;
            stats_mode = "w";
            break;
        case 'S':
            sht_m_stride = atoi(optarg);
            do_ffts = 0;
            break;
        case 'F':
            do_ffts = 0;
            break;
        case 'k':
            sht_nmaps = atoi(optarg);
            break;
        }
    }
    argv += optind;
    argc -= optind;

    for (pbench = benchmarks; pbench->execute; ++pbench) {
        pbench->should_run = (argc == 0);
    }
    for (j = 0; j != argc; ++j) {
        for (pbench = benchmarks; pbench->execute; ++pbench) {
            if (strcmp(argv[j], pbench->name) == 0) {
                pbench->should_run = 1;
            }
        }
    }

    if (do_ffts == -1) do_ffts = 1;

    /* Resource configuration */
    resource_path = getenv("SHTRESOURCES");
    if (sht_resourcefile != NULL) {
        wavemoth_configure("");
        wavemoth_query_resourcefile(sht_resourcefile, &Nside, &lmax);
    } else {
        check(resource_path != NULL, "Please define SHTRESOURCES or use -r switch");
        wavemoth_configure(resource_path);
        lmax = 2 * Nside;
    }

    fprintf(stderr, "Using %d threads, %d maps, %s, m-thinning %d\n", N_threads, sht_nmaps,
            do_ffts ? "with FFTs" : "without FFTs", sht_m_stride);


    /* Set up input and output */
    size_t npix = 12 * Nside * Nside;
    sht_input = gauss_array(((lmax + 1) * (lmax + 2)) / 2 * 2 * sht_nmaps);
    sht_output = zeros(npix * sht_nmaps);
    psht_output = zeros(npix * sht_nmaps);

    /* Wavemoth benchmark */
    for (pbench = benchmarks; pbench->execute; ++pbench) {
        if (!pbench->should_run) continue;

        printf("%s:\n", pbench->name);
        pbench->setup();
        printf("  Warming up\n");
        pbench->execute(NULL);
        printf("  Executing\n");

#ifdef HAS_PPROF
        snprintf(profilefile, MAXPATH, "profiles/%s.prof", pbench->name);
        profilefile[MAXPATH - 1] = '\0';
        ProfilerStart(profilefile);
#endif

        printf("  ");
        pbench->min_time = benchmark(pbench->name, pbench->execute, NULL,
                                     miniter, mintime);

#ifdef HAS_PPROF
        ProfilerStop();
#endif

        pbench->finish();
    }

    printf("Runtime sht/psht: %f\n", sht_benchmark->min_time / psht_benchmark->min_time);
    printf("Speedup psht/sht: %f\n", psht_benchmark->min_time / sht_benchmark->min_time);

    double rho = 0;
    for (j = 0; j != sht_nmaps; ++j) {
        double z = relative_error(npix, psht_output + j * npix, 1, sht_output + j, sht_nmaps);
        rho = fmax(z, rho);
    }
    printf("Relative error: %e\n", rho);

    if (stats_filename != NULL) {
        /* Write result to file as a line in the format
           nside lmax nmaps nthreads wavemoth_full_time wavemoth_legendre_time psht_time relative_error
        */
        FILE *f = fopen(stats_filename, stats_mode);
        if (!f) {
            fprintf(stderr, "Could not open %s in mode %s\n", stats_filename, stats_mode);
        } else {
            fprintf(f, "%d %d %d %d %.15e %.15e %.15e %.15e\n",
                    Nside, lmax, sht_nmaps, N_threads,
                    sht_benchmark->min_time, min_legendre_dt, psht_benchmark->min_time,
                    rho);
            fclose(f);
        }
    }


    free(psht_output);
    free(sht_output);
    free(sht_input);
}
示例#13
0
test_result<Real> test_hetero(const A& a, F1 test_func, F2 expect_func)
{
   typedef typename A::value_type         row_type;
   typedef Real                          value_type;

   test_result<value_type> result;

   for(unsigned i = 0; i < a.size(); ++i)
   {
      const row_type& row = a[i];
      value_type point;
      try
      {
         point = test_func(row);
      }
      catch(const std::underflow_error&)
      {
         point = 0;
      }
      catch(const std::overflow_error&)
      {
         point = std::numeric_limits<value_type>::has_infinity ? 
            std::numeric_limits<value_type>::infinity()
            : tools::max_value<value_type>();
      }
      catch(const std::exception& e)
      {
         std::cerr << e.what() << std::endl;
         print_row(row);
         BOOST_ERROR("Unexpected exception.");
         // so we don't get further errors:
         point = expect_func(row);
      }
      value_type expected = expect_func(row);
      value_type err = relative_error(point, expected);
#ifdef BOOST_INSTRUMENT
      if(err != 0)
      {
         std::cout << row[0] << " " << err;
         if(std::numeric_limits<value_type>::is_specialized)
         {
            std::cout << " (" << err / std::numeric_limits<value_type>::epsilon() << "eps)";
         }
         std::cout << std::endl;
      }
#endif
      if(!(lslboost::math::isfinite)(point) && (lslboost::math::isfinite)(expected))
      {
         std::cout << "CAUTION: Found non-finite result, when a finite value was expected at entry " << i << "\n";
         std::cout << "Found: " << point << " Expected " << expected << " Error: " << err << std::endl;
         print_row(row);
         BOOST_ERROR("Unexpected non-finite result");
      }
      if(err > 0.5)
      {
         std::cout << "CAUTION: Gross error found at entry " << i << ".\n";
         std::cout << "Found: " << point << " Expected " << expected << " Error: " << err << std::endl;
         print_row(row);
         BOOST_ERROR("Gross error");
      }
      result.add(err);
      if((result.max)() == err)
         result.set_worst(i);
   }
   return result;
}