os/ossrv/ossrv_pub/boost_apis/boost/numeric/interval/rounding.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/rounding.hpp template implementation file
sl@0
     2
 *
sl@0
     3
 * Copyright 2002-2003 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_ROUNDING_HPP
sl@0
    11
#define BOOST_NUMERIC_INTERVAL_ROUNDING_HPP
sl@0
    12
sl@0
    13
namespace boost {
sl@0
    14
namespace numeric {
sl@0
    15
namespace interval_lib {
sl@0
    16
sl@0
    17
/*
sl@0
    18
 * Default rounding_control class (does nothing)
sl@0
    19
 */
sl@0
    20
sl@0
    21
template<class T>
sl@0
    22
struct rounding_control
sl@0
    23
{
sl@0
    24
  typedef int rounding_mode;
sl@0
    25
  static void get_rounding_mode(rounding_mode&) {}
sl@0
    26
  static void set_rounding_mode(rounding_mode)  {}
sl@0
    27
  static void upward()     {}
sl@0
    28
  static void downward()   {}
sl@0
    29
  static void to_nearest() {}
sl@0
    30
  static const T& to_int(const T& x)         { return x; }
sl@0
    31
  static const T& force_rounding(const T& x) { return x; }
sl@0
    32
};
sl@0
    33
sl@0
    34
/*
sl@0
    35
 * A few rounding control classes (exact/std/opp: see documentation)
sl@0
    36
 *   rounded_arith_* control the rounding of the arithmetic operators
sl@0
    37
 *   rounded_transc_* control the rounding of the transcendental functions
sl@0
    38
 */
sl@0
    39
sl@0
    40
template<class T, class Rounding = rounding_control<T> >
sl@0
    41
struct rounded_arith_exact;
sl@0
    42
sl@0
    43
template<class T, class Rounding = rounding_control<T> >
sl@0
    44
struct rounded_arith_std;
sl@0
    45
sl@0
    46
template<class T, class Rounding = rounding_control<T> >
sl@0
    47
struct rounded_arith_opp;
sl@0
    48
sl@0
    49
template<class T, class Rounding>
sl@0
    50
struct rounded_transc_dummy;
sl@0
    51
sl@0
    52
template<class T, class Rounding = rounded_arith_exact<T> > 
sl@0
    53
struct rounded_transc_exact;
sl@0
    54
sl@0
    55
template<class T, class Rounding = rounded_arith_std<T> > 
sl@0
    56
struct rounded_transc_std;
sl@0
    57
sl@0
    58
template<class T, class Rounding = rounded_arith_opp<T> > 
sl@0
    59
struct rounded_transc_opp;
sl@0
    60
sl@0
    61
/*
sl@0
    62
 * State-saving classes: allow to set and reset rounding control
sl@0
    63
 */
sl@0
    64
sl@0
    65
namespace detail {
sl@0
    66
sl@0
    67
template<class Rounding>
sl@0
    68
struct save_state_unprotected: Rounding
sl@0
    69
{
sl@0
    70
  typedef save_state_unprotected<Rounding> unprotected_rounding;
sl@0
    71
};
sl@0
    72
sl@0
    73
} // namespace detail
sl@0
    74
sl@0
    75
template<class Rounding>
sl@0
    76
struct save_state: Rounding
sl@0
    77
{
sl@0
    78
  typename Rounding::rounding_mode mode;
sl@0
    79
  save_state() {
sl@0
    80
    this->get_rounding_mode(mode);
sl@0
    81
    this->init();
sl@0
    82
  }
sl@0
    83
  ~save_state() { this->set_rounding_mode(mode); }
sl@0
    84
  typedef detail::save_state_unprotected<Rounding> unprotected_rounding;
sl@0
    85
};
sl@0
    86
  
sl@0
    87
template<class Rounding>
sl@0
    88
struct save_state_nothing: Rounding
sl@0
    89
{
sl@0
    90
  typedef save_state_nothing<Rounding> unprotected_rounding;
sl@0
    91
};
sl@0
    92
  
sl@0
    93
template<class T>
sl@0
    94
struct rounded_math: save_state_nothing<rounded_arith_exact<T> >
sl@0
    95
{};
sl@0
    96
sl@0
    97
} // namespace interval_lib
sl@0
    98
} // namespace numeric
sl@0
    99
} // namespace boost
sl@0
   100
sl@0
   101
#endif // BOOST_NUMERIC_INTERVAL_ROUNDING_HPP