Chris@16: /* Boost interval/constants.hpp template implementation file Chris@16: * Chris@16: * Copyright 2002 Hervé Brönnimann, Guillaume Melquiond, Sylvain Pion Chris@16: * Chris@16: * Distributed under the Boost Software License, Version 1.0. Chris@16: * (See accompanying file LICENSE_1_0.txt or Chris@16: * copy at http://www.boost.org/LICENSE_1_0.txt) Chris@16: */ Chris@16: Chris@16: #ifndef BOOST_NUMERIC_INTERVAL_CONSTANTS_HPP Chris@16: #define BOOST_NUMERIC_INTERVAL_CONSTANTS_HPP Chris@16: Chris@16: namespace boost { Chris@16: namespace numeric { Chris@16: namespace interval_lib { Chris@16: namespace constants { Chris@16: Chris@16: // These constants should be exactly computed. Chris@16: // Decimal representations wouldn't do it since the standard doesn't Chris@16: // specify the rounding (even nearest) that should be used. Chris@16: Chris@16: static const float pi_f_l = 13176794.0f/(1<<22); Chris@16: static const float pi_f_u = 13176795.0f/(1<<22); Chris@16: static const double pi_d_l = (3373259426.0 + 273688.0 / (1<<21)) / (1<<30); Chris@16: static const double pi_d_u = (3373259426.0 + 273689.0 / (1<<21)) / (1<<30); Chris@16: Chris@16: template inline T pi_lower() { return 3; } Chris@16: template inline T pi_upper() { return 4; } Chris@16: template inline T pi_half_lower() { return 1; } Chris@16: template inline T pi_half_upper() { return 2; } Chris@16: template inline T pi_twice_lower() { return 6; } Chris@16: template inline T pi_twice_upper() { return 7; } Chris@16: Chris@16: template<> inline float pi_lower() { return pi_f_l; } Chris@16: template<> inline float pi_upper() { return pi_f_u; } Chris@16: template<> inline float pi_half_lower() { return pi_f_l / 2; } Chris@16: template<> inline float pi_half_upper() { return pi_f_u / 2; } Chris@16: template<> inline float pi_twice_lower() { return pi_f_l * 2; } Chris@16: template<> inline float pi_twice_upper() { return pi_f_u * 2; } Chris@16: Chris@16: template<> inline double pi_lower() { return pi_d_l; } Chris@16: template<> inline double pi_upper() { return pi_d_u; } Chris@16: template<> inline double pi_half_lower() { return pi_d_l / 2; } Chris@16: template<> inline double pi_half_upper() { return pi_d_u / 2; } Chris@16: template<> inline double pi_twice_lower() { return pi_d_l * 2; } Chris@16: template<> inline double pi_twice_upper() { return pi_d_u * 2; } Chris@16: Chris@16: template<> inline long double pi_lower() { return pi_d_l; } Chris@16: template<> inline long double pi_upper() { return pi_d_u; } Chris@16: template<> inline long double pi_half_lower() { return pi_d_l / 2; } Chris@16: template<> inline long double pi_half_upper() { return pi_d_u / 2; } Chris@16: template<> inline long double pi_twice_lower() { return pi_d_l * 2; } Chris@16: template<> inline long double pi_twice_upper() { return pi_d_u * 2; } Chris@16: Chris@16: } // namespace constants Chris@16: Chris@16: template inline Chris@16: I pi() Chris@16: { Chris@16: typedef typename I::base_type T; Chris@16: return I(constants::pi_lower(), Chris@16: constants::pi_upper(), true); Chris@16: } Chris@16: Chris@16: template inline Chris@16: I pi_half() Chris@16: { Chris@16: typedef typename I::base_type T; Chris@16: return I(constants::pi_half_lower(), Chris@16: constants::pi_half_upper(), true); Chris@16: } Chris@16: Chris@16: template inline Chris@16: I pi_twice() Chris@16: { Chris@16: typedef typename I::base_type T; Chris@16: return I(constants::pi_twice_lower(), Chris@16: constants::pi_twice_upper(), true); Chris@16: } Chris@16: Chris@16: } // namespace interval_lib Chris@16: } // namespace numeric Chris@16: } // namespace boost Chris@16: Chris@16: #endif // BOOST_NUMERIC_INTERVAL_CONSTANTS_HPP