1 | /* Boost interval/constants.hpp template implementation file
|
---|
2 | *
|
---|
3 | * Copyright 2002 Hervé Brönnimann, Guillaume Melquiond, Sylvain Pion
|
---|
4 | *
|
---|
5 | * Distributed under the Boost Software License, Version 1.0.
|
---|
6 | * (See accompanying file LICENSE_1_0.txt or
|
---|
7 | * copy at http://www.boost.org/LICENSE_1_0.txt)
|
---|
8 | */
|
---|
9 |
|
---|
10 | #ifndef BOOST_NUMERIC_INTERVAL_CONSTANTS_HPP
|
---|
11 | #define BOOST_NUMERIC_INTERVAL_CONSTANTS_HPP
|
---|
12 |
|
---|
13 | namespace boost {
|
---|
14 | namespace numeric {
|
---|
15 | namespace interval_lib {
|
---|
16 | namespace constants {
|
---|
17 |
|
---|
18 | // These constants should be exactly computed.
|
---|
19 | // Decimal representations wouldn't do it since the standard doesn't
|
---|
20 | // specify the rounding (even nearest) that should be used.
|
---|
21 |
|
---|
22 | static const float pi_f_l = 13176794.0f/(1<<22);
|
---|
23 | static const float pi_f_u = 13176795.0f/(1<<22);
|
---|
24 | static const double pi_d_l = (3373259426.0 + 273688.0 / (1<<21)) / (1<<30);
|
---|
25 | static const double pi_d_u = (3373259426.0 + 273689.0 / (1<<21)) / (1<<30);
|
---|
26 |
|
---|
27 | template<class T> inline T pi_lower() { return 3; }
|
---|
28 | template<class T> inline T pi_upper() { return 4; }
|
---|
29 | template<class T> inline T pi_half_lower() { return 1; }
|
---|
30 | template<class T> inline T pi_half_upper() { return 2; }
|
---|
31 | template<class T> inline T pi_twice_lower() { return 6; }
|
---|
32 | template<class T> inline T pi_twice_upper() { return 7; }
|
---|
33 |
|
---|
34 | template<> inline float pi_lower<float>() { return pi_f_l; }
|
---|
35 | template<> inline float pi_upper<float>() { return pi_f_u; }
|
---|
36 | template<> inline float pi_half_lower<float>() { return pi_f_l / 2; }
|
---|
37 | template<> inline float pi_half_upper<float>() { return pi_f_u / 2; }
|
---|
38 | template<> inline float pi_twice_lower<float>() { return pi_f_l * 2; }
|
---|
39 | template<> inline float pi_twice_upper<float>() { return pi_f_u * 2; }
|
---|
40 |
|
---|
41 | template<> inline double pi_lower<double>() { return pi_d_l; }
|
---|
42 | template<> inline double pi_upper<double>() { return pi_d_u; }
|
---|
43 | template<> inline double pi_half_lower<double>() { return pi_d_l / 2; }
|
---|
44 | template<> inline double pi_half_upper<double>() { return pi_d_u / 2; }
|
---|
45 | template<> inline double pi_twice_lower<double>() { return pi_d_l * 2; }
|
---|
46 | template<> inline double pi_twice_upper<double>() { return pi_d_u * 2; }
|
---|
47 |
|
---|
48 | template<> inline long double pi_lower<long double>() { return pi_d_l; }
|
---|
49 | template<> inline long double pi_upper<long double>() { return pi_d_u; }
|
---|
50 | template<> inline long double pi_half_lower<long double>() { return pi_d_l / 2; }
|
---|
51 | template<> inline long double pi_half_upper<long double>() { return pi_d_u / 2; }
|
---|
52 | template<> inline long double pi_twice_lower<long double>() { return pi_d_l * 2; }
|
---|
53 | template<> inline long double pi_twice_upper<long double>() { return pi_d_u * 2; }
|
---|
54 |
|
---|
55 | } // namespace constants
|
---|
56 |
|
---|
57 | template<class I> inline
|
---|
58 | I pi()
|
---|
59 | {
|
---|
60 | typedef typename I::base_type T;
|
---|
61 | return I(constants::pi_lower<T>(),
|
---|
62 | constants::pi_upper<T>(), true);
|
---|
63 | }
|
---|
64 |
|
---|
65 | template<class I> inline
|
---|
66 | I pi_half()
|
---|
67 | {
|
---|
68 | typedef typename I::base_type T;
|
---|
69 | return I(constants::pi_half_lower<T>(),
|
---|
70 | constants::pi_half_upper<T>(), true);
|
---|
71 | }
|
---|
72 |
|
---|
73 | template<class I> inline
|
---|
74 | I pi_twice()
|
---|
75 | {
|
---|
76 | typedef typename I::base_type T;
|
---|
77 | return I(constants::pi_twice_lower<T>(),
|
---|
78 | constants::pi_twice_upper<T>(), true);
|
---|
79 | }
|
---|
80 |
|
---|
81 | } // namespace interval_lib
|
---|
82 | } // namespace numeric
|
---|
83 | } // namespace boost
|
---|
84 |
|
---|
85 | #endif // BOOST_NUMERIC_INTERVAL_CONSTANTS_HPP
|
---|