source: NonGTP/Boost/boost/numeric/interval/constants.hpp @ 857

Revision 857, 3.2 KB checked in by igarcia, 19 years ago (diff)
Line 
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
13namespace boost {
14namespace numeric {
15namespace interval_lib {
16namespace 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
22static const float pi_f_l = 13176794.0f/(1<<22);
23static const float pi_f_u = 13176795.0f/(1<<22);
24static const double pi_d_l = (3373259426.0 + 273688.0 / (1<<21)) / (1<<30);
25static const double pi_d_u = (3373259426.0 + 273689.0 / (1<<21)) / (1<<30);
26
27template<class T> inline T pi_lower() { return 3; }
28template<class T> inline T pi_upper() { return 4; }
29template<class T> inline T pi_half_lower() { return 1; }
30template<class T> inline T pi_half_upper() { return 2; }
31template<class T> inline T pi_twice_lower() { return 6; }
32template<class T> inline T pi_twice_upper() { return 7; }
33
34template<> inline float pi_lower<float>() { return pi_f_l; }
35template<> inline float pi_upper<float>() { return pi_f_u; }
36template<> inline float pi_half_lower<float>() { return pi_f_l / 2; }
37template<> inline float pi_half_upper<float>() { return pi_f_u / 2; }
38template<> inline float pi_twice_lower<float>() { return pi_f_l * 2; }
39template<> inline float pi_twice_upper<float>() { return pi_f_u * 2; }
40
41template<> inline double pi_lower<double>() { return pi_d_l; }
42template<> inline double pi_upper<double>() { return pi_d_u; }
43template<> inline double pi_half_lower<double>() { return pi_d_l / 2; }
44template<> inline double pi_half_upper<double>() { return pi_d_u / 2; }
45template<> inline double pi_twice_lower<double>() { return pi_d_l * 2; }
46template<> inline double pi_twice_upper<double>() { return pi_d_u * 2; }
47
48template<> inline long double pi_lower<long double>() { return pi_d_l; }
49template<> inline long double pi_upper<long double>() { return pi_d_u; }
50template<> inline long double pi_half_lower<long double>() { return pi_d_l / 2; }
51template<> inline long double pi_half_upper<long double>() { return pi_d_u / 2; }
52template<> inline long double pi_twice_lower<long double>() { return pi_d_l * 2; }
53template<> inline long double pi_twice_upper<long double>() { return pi_d_u * 2; }
54
55} // namespace constants
56
57template<class I> inline
58I pi()
59{
60  typedef typename I::base_type T;
61  return I(constants::pi_lower<T>(),
62           constants::pi_upper<T>(), true);
63}
64
65template<class I> inline
66I 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
73template<class I> inline
74I 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
Note: See TracBrowser for help on using the repository browser.