]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | /////////////////////////////////////////////////////////////// |
2 | // Copyright Christopher Kormanyos 2002 - 2011. | |
3 | // Copyright 2011 John Maddock. Distributed under the Boost | |
4 | // Software License, Version 1.0. (See accompanying file | |
92f5a8d4 | 5 | // LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt |
7c673cae FG |
6 | // |
7 | // This work is based on an earlier work: | |
8 | // "Algorithm 910: A Portable C++ Multiple-Precision System for Special-Function Calculations", | |
9 | // in ACM TOMS, {VOL 37, ISSUE 4, (February 2011)} (C) ACM, 2011. http://doi.acm.org/10.1145/1916461.1916469 | |
10 | ||
11 | #ifdef _MSC_VER | |
92f5a8d4 | 12 | #define _SCL_SECURE_NO_WARNINGS |
7c673cae FG |
13 | #endif |
14 | ||
15 | #include <boost/detail/lightweight_test.hpp> | |
16 | #include <boost/array.hpp> | |
17 | #include "test.hpp" | |
18 | ||
19 | #if !defined(TEST_MPF_50) && !defined(TEST_MPF) && !defined(TEST_BACKEND) && !defined(TEST_CPP_DEC_FLOAT) && !defined(TEST_MPFR) && !defined(TEST_MPFR_50) && !defined(TEST_MPFI_50) && !defined(TEST_FLOAT128) && !defined(TEST_CPP_BIN_FLOAT) | |
92f5a8d4 TL |
20 | #define TEST_MPF_50 |
21 | #define TEST_MPFR_50 | |
22 | #define TEST_MPFI_50 | |
23 | #define TEST_BACKEND | |
24 | #define TEST_CPP_DEC_FLOAT | |
25 | #define TEST_FLOAT128 | |
26 | #define TEST_CPP_BIN_FLOAT | |
7c673cae FG |
27 | |
28 | #ifdef _MSC_VER | |
29 | #pragma message("CAUTION!!: No backend type specified so testing everything.... this will take some time!!") | |
30 | #endif | |
31 | #ifdef __GNUC__ | |
32 | #pragma warning "CAUTION!!: No backend type specified so testing everything.... this will take some time!!" | |
33 | #endif | |
34 | ||
35 | #endif | |
36 | ||
37 | #if defined(TEST_MPF_50) | |
38 | #include <boost/multiprecision/gmp.hpp> | |
39 | #endif | |
40 | #if defined(TEST_MPFR_50) | |
41 | #include <boost/multiprecision/mpfr.hpp> | |
42 | #endif | |
43 | #if defined(TEST_MPFI_50) | |
44 | #include <boost/multiprecision/mpfi.hpp> | |
45 | #endif | |
46 | #ifdef TEST_BACKEND | |
47 | #include <boost/multiprecision/concepts/mp_number_archetypes.hpp> | |
48 | #endif | |
49 | #ifdef TEST_CPP_DEC_FLOAT | |
50 | #include <boost/multiprecision/cpp_dec_float.hpp> | |
51 | #endif | |
52 | #ifdef TEST_FLOAT128 | |
53 | #include <boost/multiprecision/float128.hpp> | |
54 | #endif | |
55 | #ifdef TEST_CPP_BIN_FLOAT | |
56 | #include <boost/multiprecision/cpp_bin_float.hpp> | |
57 | #endif | |
58 | ||
59 | template <class T> | |
60 | void test() | |
61 | { | |
62 | std::cout << "Testing type: " << typeid(T).name() << std::endl; | |
63 | static const boost::array<const char*, 51u> data = | |
92f5a8d4 TL |
64 | {{ |
65 | "0.32137338579537729992840434899278935725496267444911714908205287462634251052210833615032073534299473485492692600156322137421801432333125051088723502425037485776412801577568405892077585206768190530859883094571475323319480739773193974206966728764224286661945738178210577326172938196062277314761537881936346874075881338768208490193827960565412814349738654540520356903367084438822830345189856017860672463017", | |
66 | "0.98628073997374759901559180515206275902189609982907214282364143439537215491113710345866034807991101303183938339561499559327886956280789743287824488269072297413440935381715378233031399015496124706604318545539544610760151756970229801074280545428642122005982857974921606264103186878499260552388713716032507770319550435738767597150644370033277228635793175246197730488375240713357827246166262087899961098648", | |
67 | "0.99999659728082161113542951278514830809677661658635225532792520501703544628367875293677270218317428676793098034276042396396797568103263882451732810190507733063467333056356770774002596898762991629653041854653269824642873291146068535300466473399592751219449187768646625229500705182676930009096545254478199838990703077597971823456671241141900968900216742636822174010867343154474773040184900973368250708724", | |
68 | "0.9999999999846483268200051609594321550129159997920576480976206867496512752486590660437091205989616108531910897733432934135954788151766561209164605337537937873588006552145390152387235783207736999759875845070169747521389728857476525437483543080651125798739562649414879487621858466223255239845627205850217328574865852922872737234283038190096982410137471391847466112651349436875974689271288261759782261321", | |
69 | "0.9999999999999999987314527242099750648171958211319474558707792311593804963057878814487720997303512134007272111464990650500302215773762906820778949397525329109311974741708703536680512747226155618703318739024344621256722269608969415280035337052044425138281821760268269187377517243951584969175035549994883451471918693502477485385682884154959809285569290940740978684264145737164182111806308430952867505356", | |
70 | "0.9999999999999999999999999980800953069847308586840237590563929855339557065536765765234844240789584487443451033349994294426525006157530320529970966048109743850154174651033567146346966529198814047607015842020039899630884318521543225160212193994911746894335846264878066530266737005606770102869237101848445559941638381625615207320468184414917265299980278164193202897754476112968080358662232635784904263624", | |
71 | "0.9999999999999999999999999999999999999467800140220866754762922747687784133233134010432889959570821554455247528344437918197518545105332713456859236726383195243056599177018396579766073961540714510399202497404647103138524118065391185503678895059096790300665805648569647351935897874460587855127436472608470703384261586158923066272124216158518232588330799027603391275039552776308636189531809031683723259525", | |
72 | "0.9999999999999999999999999999999999999999999999999729795912960133359928587562229512337339217831178574875626619226954752643039860388090399659478676726654102118545764943682017611574275691203710439707807193180604656837503862242700430179591666329131728631752773789406064618682879167351725013888294859467540832310795515139677375807407622028485242969471516812171475098378942187864794497220152019202351747432", | |
73 | "0.9999999999999999999999999999999999999999999999999999999999999997487354938310440650220692519525261552411539996830587326435051159231522052011310872619940247463640019105467860778515384738650636054646551611609757125760437266415865214306396520500343113189907306851418957620080971645943305760132385139924583154317156560414548076370893360020924960120441059315311380109752919823616149973862196846266297710225", | |
74 | "0.9999999999999999999999999999999999999999999999999999999999999999999999999999999572050575304159358359221596743379014313563214857593401545331495211888415913558896516895286943572966865708195832339959764445194449615969154689769557903166971249521898883489362426386924297872088925852892350150865941427355319827260914834268754732102528105919811851193667193380541054520023003326858641189063542651960743457613", | |
75 | "0.9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999998665016733514821204959171836698281165918083005790816030823236096080522860514417075411055633676502699904415882389102672678124683084429720879962355892225321369091298491658349178472270952759208443767848312111069127329160464884932271685986610697222434145553035947750809388321614695213754318979469071722942883", | |
76 | "0.999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999992372516628147584832950728021842198359205201519966391076994594773600474674435473005118571751514446148292787696117866094991476340344341061706866751156257825144909115117822189019766805825304055482958970512463798453229341693148012213183553546720540880444569824125592343803193018989122964", | |
77 | "0.9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999920180539244323143459416025663362517256166793900312667214543096238752838226369161775531456005541374878274529461511286842988937830155704737448202558382612829022464635400289328916240002670783433827234852858267621807568393874737879853500598862298495727481132883728328", | |
78 | "0.9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999998470116425957155787153557938061034698436461173594805292722874130433614266475136267606498346730583487791266503943659174886554170377537630914770998114573340081594827150737005158607830579000912020838690230498119348251553312722575955142752845289", | |
79 | "0.9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999462931048083476382670449719737943481963930626760625326765703815392249622625483433043363664396638162612437367800102332819699131841317348173451308570776544874933173719394861336636728378134900422312720743996219523365098", | |
80 | "0.9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999996546783689748726752364896615532860288057097437452774779386074906915819380531729493071959232887620213723607155628959529584572083388979892309086717786559916703004365603135284141639480887703759", | |
81 | "0.9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999593332381019647939423999969519583099837564321056588766269967853479478603122899456262904869063959564274215899007623362296377022418464303752396325625838280378647335", | |
82 | "0.9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999122842714667567128203355585346559126606029196080721845292399104475997315344844970601651757832506169948906646054332493537761143729664", | |
83 | "0.9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999965347272050374435790597917065458623422102880662825928396981295898014081371503733411536311258910851858", | |
84 | "0.9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999974926240515037403282500845454464621558236030794140169313830052413917", | |
85 | "0.9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999667705192725716176070161727364499", | |
86 | "1.", | |
87 | "1.", | |
88 | "1.", | |
89 | "1.", | |
90 | "1.", | |
91 | "1.", | |
92 | "1.", | |
93 | "1.", | |
94 | "1.", | |
95 | "1.", | |
96 | "1.", | |
97 | "1.", | |
98 | "1.", | |
99 | "1.", | |
100 | "1.", | |
101 | "1.", | |
102 | "1.", | |
103 | "1.", | |
104 | "1.", | |
105 | "1.", | |
106 | "1.", | |
107 | "1.", | |
108 | "1.", | |
109 | "1.", | |
110 | "1.", | |
111 | "1.", | |
112 | "1.", | |
113 | "1.", | |
114 | "1.", | |
115 | "1.", | |
116 | }}; | |
7c673cae FG |
117 | |
118 | T eg = static_cast<T>("5.77215664901532860606512090082402431042159335939923598805767234884867726777664670936947063291746749514631447249807082480960504014486542836224173997644923536253500333742937337737673942792595258247094916008735203948165670853233151776611528621199501507984793745085705740029921354786146694029604325421519e-1"); | |
119 | ||
120 | unsigned max_err = 0; | |
92f5a8d4 | 121 | for (unsigned k = 0; k < data.size(); k++) |
7c673cae | 122 | { |
92f5a8d4 TL |
123 | const T x = eg + k; |
124 | T val = boost::multiprecision::tanh(x * x); | |
125 | T e = relative_error(val, T(data[k])); | |
7c673cae | 126 | unsigned err = e.template convert_to<unsigned>(); |
92f5a8d4 | 127 | if (err > max_err) |
7c673cae FG |
128 | max_err = err; |
129 | } | |
130 | std::cout << "Max error was: " << max_err << std::endl; | |
131 | BOOST_TEST(max_err < 100); | |
132 | } | |
133 | ||
7c673cae FG |
134 | int main() |
135 | { | |
136 | #ifdef TEST_BACKEND | |
137 | test<boost::multiprecision::number<boost::multiprecision::concepts::number_backend_float_architype> >(); | |
138 | #endif | |
139 | #ifdef TEST_MPF_50 | |
140 | test<boost::multiprecision::mpf_float_50>(); | |
141 | test<boost::multiprecision::mpf_float_100>(); | |
142 | #endif | |
143 | #ifdef TEST_MPFR_50 | |
144 | test<boost::multiprecision::mpfr_float_50>(); | |
145 | test<boost::multiprecision::mpfr_float_100>(); | |
146 | #endif | |
147 | #ifdef TEST_MPFI_50 | |
148 | test<boost::multiprecision::mpfi_float_50>(); | |
149 | test<boost::multiprecision::mpfi_float_100>(); | |
150 | #endif | |
151 | #ifdef TEST_CPP_DEC_FLOAT | |
152 | test<boost::multiprecision::cpp_dec_float_50>(); | |
153 | test<boost::multiprecision::cpp_dec_float_100>(); | |
154 | #ifndef SLOW_COMPLER | |
155 | // Some "peculiar" digit counts which stress our code: | |
156 | test<boost::multiprecision::number<boost::multiprecision::cpp_dec_float<65> > >(); | |
157 | test<boost::multiprecision::number<boost::multiprecision::cpp_dec_float<64> > >(); | |
158 | test<boost::multiprecision::number<boost::multiprecision::cpp_dec_float<63> > >(); | |
159 | test<boost::multiprecision::number<boost::multiprecision::cpp_dec_float<62> > >(); | |
160 | test<boost::multiprecision::number<boost::multiprecision::cpp_dec_float<61, long long> > >(); | |
161 | test<boost::multiprecision::number<boost::multiprecision::cpp_dec_float<60, long long> > >(); | |
11fdf7f2 TL |
162 | test<boost::multiprecision::number<boost::multiprecision::cpp_dec_float<59, long long, std::allocator<char> > > >(); |
163 | test<boost::multiprecision::number<boost::multiprecision::cpp_dec_float<58, long long, std::allocator<char> > > >(); | |
7c673cae FG |
164 | #endif |
165 | #endif | |
166 | #ifdef TEST_FLOAT128 | |
167 | test<boost::multiprecision::float128>(); | |
168 | #endif | |
169 | #ifdef TEST_CPP_BIN_FLOAT | |
170 | test<boost::multiprecision::cpp_bin_float_50>(); | |
1e59de90 | 171 | test<boost::multiprecision::number<boost::multiprecision::cpp_bin_float<35, boost::multiprecision::digit_base_10, std::allocator<char>, long long> > >(); |
7c673cae FG |
172 | #endif |
173 | return boost::report_errors(); | |
174 | } |