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 pi_lower()27template<class T> inline T pi_lower() { return 3; } pi_upper()28template<class T> inline T pi_upper() { return 4; } pi_half_lower()29template<class T> inline T pi_half_lower() { return 1; } pi_half_upper()30template<class T> inline T pi_half_upper() { return 2; } pi_twice_lower()31template<class T> inline T pi_twice_lower() { return 6; } pi_twice_upper()32template<class T> inline T pi_twice_upper() { return 7; } 33 pi_lower()34template<> inline float pi_lower<float>() { return pi_f_l; } pi_upper()35template<> inline float pi_upper<float>() { return pi_f_u; } pi_half_lower()36template<> inline float pi_half_lower<float>() { return pi_f_l / 2; } pi_half_upper()37template<> inline float pi_half_upper<float>() { return pi_f_u / 2; } pi_twice_lower()38template<> inline float pi_twice_lower<float>() { return pi_f_l * 2; } pi_twice_upper()39template<> inline float pi_twice_upper<float>() { return pi_f_u * 2; } 40 pi_lower()41template<> inline double pi_lower<double>() { return pi_d_l; } pi_upper()42template<> inline double pi_upper<double>() { return pi_d_u; } pi_half_lower()43template<> inline double pi_half_lower<double>() { return pi_d_l / 2; } pi_half_upper()44template<> inline double pi_half_upper<double>() { return pi_d_u / 2; } pi_twice_lower()45template<> inline double pi_twice_lower<double>() { return pi_d_l * 2; } pi_twice_upper()46template<> inline double pi_twice_upper<double>() { return pi_d_u * 2; } 47 pi_lower()48template<> inline long double pi_lower<long double>() { return pi_d_l; } pi_upper()49template<> inline long double pi_upper<long double>() { return pi_d_u; } pi_half_lower()50template<> inline long double pi_half_lower<long double>() { return pi_d_l / 2; } pi_half_upper()51template<> inline long double pi_half_upper<long double>() { return pi_d_u / 2; } pi_twice_lower()52template<> inline long double pi_twice_lower<long double>() { return pi_d_l * 2; } pi_twice_upper()53template<> inline long double pi_twice_upper<long double>() { return pi_d_u * 2; } 54 55 } // namespace constants 56 57 template<class I> inline pi()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 65 template<class I> inline pi_half()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 73 template<class I> inline pi_twice()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 86