]>
Commit | Line | Data |
---|---|---|
20effc67 TL |
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 | |
5 | // LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt | |
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 | |
12 | #define _SCL_SECURE_NO_WARNINGS | |
13 | #endif | |
14 | ||
15 | #include <boost/detail/lightweight_test.hpp> | |
16 | #include <boost/array.hpp> | |
17 | #include <boost/math/special_functions/relative_difference.hpp> | |
18 | #include "test.hpp" | |
19 | ||
1e59de90 | 20 | #if !defined(TEST_MPF_50) && !defined(TEST_MPF) && !defined(TEST_CPP_DEC_FLOAT) && !defined(TEST_FLOAT128) && !defined(TEST_CPP_BIN_FLOAT) && !defined(TEST_MPFR_50) |
20effc67 TL |
21 | #define TEST_MPF_50 |
22 | #define TEST_CPP_DEC_FLOAT | |
23 | #define TEST_FLOAT128 | |
24 | #define TEST_CPP_BIN_FLOAT | |
1e59de90 | 25 | #define TEST_MPFR_50 |
20effc67 TL |
26 | |
27 | #ifdef _MSC_VER | |
28 | #pragma message("CAUTION!!: No backend type specified so testing everything.... this will take some time!!") | |
29 | #endif | |
30 | #ifdef __GNUC__ | |
31 | #pragma warning "CAUTION!!: No backend type specified so testing everything.... this will take some time!!" | |
32 | #endif | |
33 | ||
34 | #endif | |
35 | ||
36 | #include <boost/multiprecision/mpfr.hpp> | |
37 | ||
38 | #if defined(TEST_MPF_50) | |
39 | #include <boost/multiprecision/gmp.hpp> | |
40 | #endif | |
41 | #ifdef TEST_CPP_DEC_FLOAT | |
42 | #include <boost/multiprecision/cpp_dec_float.hpp> | |
43 | #endif | |
44 | #ifdef TEST_FLOAT128 | |
45 | #include <boost/multiprecision/float128.hpp> | |
46 | #endif | |
47 | #ifdef TEST_CPP_BIN_FLOAT | |
48 | #include <boost/multiprecision/cpp_bin_float.hpp> | |
49 | #endif | |
50 | ||
51 | template <class T> | |
52 | void test() | |
53 | { | |
54 | typedef boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<1000> > mpfr_float_1000; | |
55 | ||
56 | for (int n = 0; n <= 20; ++n) | |
57 | { | |
58 | std::cout << "Testing n = " << n << std::endl; | |
59 | T boundary = boost::math::constants::half_pi<T>() * n; | |
60 | T val = boundary; | |
61 | if((n == 0) && ((std::numeric_limits<T>::min_exponent <= std::numeric_limits<mpfr_float_1000>::min_exponent) || (!std::numeric_limits<T>::is_specialized))) | |
62 | continue; | |
63 | for (unsigned i = 0; i < 200; ++i) | |
64 | { | |
65 | mpfr_float_1000 comparison(val); | |
66 | comparison = sin(comparison); | |
67 | T found = sin(val); | |
68 | T expected = T(comparison); | |
69 | BOOST_CHECK_LE(boost::math::epsilon_difference(found, expected), 20); | |
70 | val = boost::math::float_next(val); | |
71 | } | |
72 | val = boundary; | |
73 | for (unsigned i = 0; i < 200; ++i) | |
74 | { | |
75 | val = boost::math::float_prior(val); | |
76 | mpfr_float_1000 comparison(val); | |
77 | comparison = sin(comparison); | |
78 | T found = sin(val); | |
79 | T expected = T(comparison); | |
80 | BOOST_CHECK_LE(boost::math::epsilon_difference(found, expected), 20); | |
81 | } | |
82 | } | |
83 | } | |
84 | ||
85 | int main() | |
86 | { | |
87 | #ifdef TEST_MPF_50 | |
88 | test<boost::multiprecision::mpf_float_50>(); | |
89 | test<boost::multiprecision::mpf_float_100>(); | |
1e59de90 | 90 | boost::multiprecision::mpf_float::default_precision(50); |
20effc67 | 91 | test<boost::multiprecision::mpf_float>(); |
1e59de90 | 92 | boost::multiprecision::mpf_float::default_precision(100); |
20effc67 TL |
93 | test<boost::multiprecision::mpf_float>(); |
94 | #endif | |
1e59de90 TL |
95 | #ifdef TEST_MPFR_50 |
96 | boost::multiprecision::mpfr_float::default_precision(50); | |
97 | test<boost::multiprecision::mpfr_float>(); | |
98 | boost::multiprecision::mpfr_float::default_precision(100); | |
99 | test<boost::multiprecision::mpfr_float>(); | |
100 | #endif | |
20effc67 TL |
101 | #ifdef TEST_CPP_DEC_FLOAT |
102 | test<boost::multiprecision::cpp_dec_float_50>(); | |
103 | test<boost::multiprecision::cpp_dec_float_100>(); | |
104 | #ifndef SLOW_COMPLER | |
105 | // Some "peculiar" digit counts which stress our code: | |
106 | test<boost::multiprecision::number<boost::multiprecision::cpp_dec_float<65> > >(); | |
107 | test<boost::multiprecision::number<boost::multiprecision::cpp_dec_float<64> > >(); | |
108 | test<boost::multiprecision::number<boost::multiprecision::cpp_dec_float<63> > >(); | |
109 | test<boost::multiprecision::number<boost::multiprecision::cpp_dec_float<62> > >(); | |
110 | test<boost::multiprecision::number<boost::multiprecision::cpp_dec_float<61, long long> > >(); | |
111 | test<boost::multiprecision::number<boost::multiprecision::cpp_dec_float<60, long long> > >(); | |
112 | test<boost::multiprecision::number<boost::multiprecision::cpp_dec_float<59, long long, std::allocator<char> > > >(); | |
113 | test<boost::multiprecision::number<boost::multiprecision::cpp_dec_float<58, long long, std::allocator<char> > > >(); | |
114 | // Check low multiprecision digit counts. | |
115 | test<boost::multiprecision::number<boost::multiprecision::cpp_dec_float<9> > >(); | |
116 | test<boost::multiprecision::number<boost::multiprecision::cpp_dec_float<18> > >(); | |
117 | #endif | |
118 | #endif | |
119 | #ifdef TEST_FLOAT128 | |
120 | test<boost::multiprecision::float128>(); | |
121 | #endif | |
122 | #ifdef TEST_CPP_BIN_FLOAT | |
123 | test<boost::multiprecision::cpp_bin_float_50>(); | |
124 | test<boost::multiprecision::cpp_bin_float_quad>(); | |
1e59de90 | 125 | test<boost::multiprecision::number<boost::multiprecision::cpp_bin_float<35, boost::multiprecision::digit_base_10, std::allocator<char>, long long> > >(); |
20effc67 TL |
126 | #endif |
127 | return boost::report_errors(); | |
128 | } |