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