Imported Upstream version 1.72.0
[platform/upstream/boost.git] / libs / multiprecision / test / concepts / number_concept_check.cpp
1 //  Copyright John Maddock 2011.
2 //  Use, modification and distribution are subject to the
3 //  Boost Software License, Version 1.0. (See accompanying file
4 //  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5
6 //
7 // This tests that cpp_dec_float_50 meets our
8 // conceptual requirements.
9 //
10 #ifdef _MSC_VER
11 #define _SCL_SECURE_NO_WARNINGS
12 #pragma warning(disable : 4800)
13 #pragma warning(disable : 4512)
14 #pragma warning(disable : 4127)
15 #pragma warning(disable : 4512)
16 #pragma warning(disable : 4503) // decorated name length exceeded, name was truncated
17 #endif
18
19 #include <boost/container_hash/hash.hpp>
20 #include <libs/math/test/compile_test/poison.hpp>
21
22 #if !defined(TEST_MPF_50) && !defined(TEST_BACKEND) && !defined(TEST_MPZ) && !defined(TEST_CPP_DEC_FLOAT) && !defined(TEST_MPFR_50) && !defined(TEST_MPFR_6) && !defined(TEST_MPFR_15) && !defined(TEST_MPFR_17) && !defined(TEST_MPFR_30) && !defined(TEST_CPP_DEC_FLOAT_NO_ET) && !defined(TEST_LOGGED_ADAPTER) && !defined(TEST_CPP_BIN_FLOAT)
23 #define TEST_MPF_50
24 #define TEST_BACKEND
25 #define TEST_MPZ
26 #define TEST_MPFR_50
27 #define TEST_MPFR_6
28 #define TEST_MPFR_15
29 #define TEST_MPFR_17
30 #define TEST_MPFR_30
31 #define TEST_CPP_DEC_FLOAT
32 #define TEST_CPP_DEC_FLOAT_NO_ET
33 #define TEST_LOGGED_ADAPTER
34 #define TEST_CPP_BIN_FLOAT
35
36 #ifdef _MSC_VER
37 #pragma message("CAUTION!!: No backend type specified so testing everything.... this will take some time!!")
38 #endif
39 #ifdef __GNUC__
40 #pragma warning "CAUTION!!: No backend type specified so testing everything.... this will take some time!!"
41 #endif
42
43 #endif
44
45 #if defined(TEST_MPF_50) || defined(TEST_MPZ)
46 #include <boost/multiprecision/gmp.hpp>
47 #endif
48 #ifdef TEST_BACKEND
49 #include <boost/multiprecision/concepts/mp_number_archetypes.hpp>
50 #endif
51 #if defined(TEST_CPP_DEC_FLOAT) || defined(TEST_CPP_DEC_FLOAT_NO_ET) || defined(TEST_LOGGED_ADAPTER)
52 #include <boost/multiprecision/cpp_dec_float.hpp>
53 #endif
54 #if defined(TEST_CPP_BIN_FLOAT)
55 #include <boost/multiprecision/cpp_bin_float.hpp>
56 #endif
57 #if defined(TEST_MPFR_50) || defined(TEST_MPFR_6) || defined(TEST_MPFR_15) || defined(TEST_MPFR_17) || defined(TEST_MPFR_30)
58 #include <boost/multiprecision/mpfr.hpp>
59 #endif
60 #ifdef TEST_LOGGED_ADAPTER
61 #include <boost/multiprecision/logged_adaptor.hpp>
62 #endif
63
64 #include <boost/math/concepts/real_type_concept.hpp>
65
66 template <class T>
67 void test_extra(T)
68 {
69    T t = 1;
70    t   = abs(t);
71    t   = abs(t * t);
72
73    t = fabs(t);
74    t = fabs(t * t);
75
76    t = sqrt(t);
77    t = sqrt(t * t);
78
79    t = floor(t);
80    t = floor(t * t);
81
82    t = ceil(t);
83    t = ceil(t * t);
84
85    t = trunc(t);
86    t = trunc(t * t);
87
88    t = round(t);
89    t = round(t * t);
90
91    t = exp(t);
92    t = exp(t * t);
93
94    t = log(t);
95    t = log(t * t);
96
97    t = log10(t);
98    t = log10(t * t);
99
100    t = cos(t);
101    t = cos(t * t);
102
103    t = sin(t);
104    t = sin(t * t);
105
106    t = tan(t);
107    t = tan(t * t);
108
109    t = asin(t);
110    t = asin(t * t);
111
112    t = atan(t);
113    t = atan(t * t);
114
115    t = acos(t);
116    t = acos(t * t);
117
118    t = cosh(t);
119    t = cosh(t * t);
120
121    t = sinh(t);
122    t = sinh(t * t);
123
124    t = tanh(t);
125    t = tanh(t * t);
126
127    double dval = 2;
128    t           = pow(t, t);
129    t           = pow(t, t * t);
130    t           = pow(t, dval);
131    t           = pow(t * t, t);
132    t           = pow(t * t, t * t);
133    t           = pow(t * t, dval);
134    t           = pow(dval, t);
135    t           = pow(dval, t * t);
136
137    t = atan2(t, t);
138    t = atan2(t, t * t);
139    t = atan2(t, dval);
140    t = atan2(t * t, t);
141    t = atan2(t * t, t * t);
142    t = atan2(t * t, dval);
143    t = atan2(dval, t);
144    t = atan2(dval, t * t);
145
146    t = fmod(t, t);
147    t = fmod(t, t * t);
148    t = fmod(t, dval);
149    t = fmod(t * t, t);
150    t = fmod(t * t, t * t);
151    t = fmod(t * t, dval);
152    t = fmod(dval, t);
153    t = fmod(dval, t * t);
154
155    typedef typename T::backend_type             backend_type;
156    typedef typename backend_type::exponent_type exp_type;
157    exp_type                                     e = 0;
158    int                                          i = 0;
159
160    t = ldexp(t, i);
161    t = ldexp(t * t, i);
162    t = ldexp(t, e);
163    t = ldexp(t * t, e);
164
165    t = frexp(t, &i);
166    t = frexp(t * t, &i);
167    t = frexp(t, &e);
168    t = frexp(t * t, &e);
169
170    t = scalbn(t, i);
171    t = scalbn(t * t, i);
172    t = scalbn(t, e);
173    t = scalbn(t * t, e);
174
175    t = logb(t);
176    t = logb(t * t);
177    e = ilogb(t);
178    e = ilogb(t * t);
179 }
180
181 void foo()
182 {
183 #ifdef TEST_BACKEND
184    test_extra(boost::multiprecision::concepts::mp_number_float_architype());
185 #endif
186 #ifdef TEST_MPF_50
187    test_extra(boost::multiprecision::mpf_float_50());
188 #endif
189 #ifdef TEST_MPFR_50
190    test_extra(boost::multiprecision::mpfr_float_50());
191 #endif
192 #ifdef TEST_MPFR_6
193    test_extra(boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<6> >());
194 #endif
195 #ifdef TEST_MPFR_15
196    test_extra(boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<15> >());
197 #endif
198 #ifdef TEST_MPFR_17
199    test_extra(boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<17> >());
200 #endif
201 #ifdef TEST_MPFR_30
202    test_extra(boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<30> >());
203 #endif
204 #ifdef TEST_CPP_DEC_FLOAT
205    test_extra(boost::multiprecision::cpp_dec_float_50());
206 #endif
207 #ifdef TEST_CPP_BIN_FLOAT
208    test_extra(boost::multiprecision::cpp_bin_float_50());
209 #endif
210 #ifdef TEST_CPP_DEC_FLOAT_NO_ET
211    test_extra(boost::multiprecision::number<boost::multiprecision::cpp_dec_float<100>, boost::multiprecision::et_off>());
212 #endif
213 }
214
215 int main()
216 {
217 #ifdef TEST_BACKEND
218    BOOST_CONCEPT_ASSERT((boost::math::concepts::RealTypeConcept<boost::multiprecision::concepts::mp_number_float_architype>));
219 #endif
220 #ifdef TEST_MPF_50
221    BOOST_CONCEPT_ASSERT((boost::math::concepts::RealTypeConcept<boost::multiprecision::mpf_float_50>));
222 #endif
223 #ifdef TEST_MPFR_50
224    BOOST_CONCEPT_ASSERT((boost::math::concepts::RealTypeConcept<boost::multiprecision::mpfr_float_50>));
225 #endif
226 #ifdef TEST_MPFR_6
227    BOOST_CONCEPT_ASSERT((boost::math::concepts::RealTypeConcept<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<6> > >));
228 #endif
229 #ifdef TEST_MPFR_15
230    BOOST_CONCEPT_ASSERT((boost::math::concepts::RealTypeConcept<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<15> > >));
231 #endif
232 #ifdef TEST_MPFR_17
233    BOOST_CONCEPT_ASSERT((boost::math::concepts::RealTypeConcept<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<17> > >));
234 #endif
235 #ifdef TEST_MPFR_30
236    BOOST_CONCEPT_ASSERT((boost::math::concepts::RealTypeConcept<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<30> > >));
237 #endif
238 #ifdef TEST_MPFR_50
239    BOOST_CONCEPT_ASSERT((boost::math::concepts::RealTypeConcept<boost::multiprecision::mpfr_float_50>));
240 #endif
241 #ifdef TEST_CPP_DEC_FLOAT
242    BOOST_CONCEPT_ASSERT((boost::math::concepts::RealTypeConcept<boost::multiprecision::cpp_dec_float_50>));
243 #endif
244 #ifdef TEST_CPP_BIN_FLOAT
245    BOOST_CONCEPT_ASSERT((boost::math::concepts::RealTypeConcept<boost::multiprecision::cpp_bin_float_50>));
246 #endif
247 #ifdef TEST_LOGGED_ADAPTER
248    typedef boost::multiprecision::number<boost::multiprecision::logged_adaptor<boost::multiprecision::cpp_dec_float<50> > > num_t;
249    test_extra(num_t());
250 #endif
251 }