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