os/ossrv/ossrv_pub/boost_apis/boost/numeric/interval/arith3.hpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
/* Boost interval/arith3.hpp template implementation file
sl@0
     2
 *
sl@0
     3
 * This headers provides arithmetical functions
sl@0
     4
 * which compute an interval given some base
sl@0
     5
 * numbers. The resulting interval encloses the
sl@0
     6
 * real result of the arithmetic operation.
sl@0
     7
 *
sl@0
     8
 * Copyright 2003 Guillaume Melquiond
sl@0
     9
 *
sl@0
    10
 * Distributed under the Boost Software License, Version 1.0.
sl@0
    11
 * (See accompanying file LICENSE_1_0.txt or
sl@0
    12
 * copy at http://www.boost.org/LICENSE_1_0.txt)
sl@0
    13
 */
sl@0
    14
sl@0
    15
#ifndef BOOST_NUMERIC_INTERVAL_ARITH3_HPP
sl@0
    16
#define BOOST_NUMERIC_INTERVAL_ARITH3_HPP
sl@0
    17
sl@0
    18
#include <boost/numeric/interval/detail/interval_prototype.hpp>
sl@0
    19
#include <boost/numeric/interval/detail/test_input.hpp>
sl@0
    20
sl@0
    21
namespace boost {
sl@0
    22
namespace numeric {
sl@0
    23
namespace interval_lib {
sl@0
    24
sl@0
    25
template<class I> inline
sl@0
    26
I add(const typename I::base_type& x, const typename I::base_type& y)
sl@0
    27
{
sl@0
    28
  typedef typename I::traits_type Policies;
sl@0
    29
  if (detail::test_input<typename I::base_type, Policies>(x, y))
sl@0
    30
    return I::empty();
sl@0
    31
  typename Policies::rounding rnd;
sl@0
    32
  return I(rnd.add_down(x, y), rnd.add_up(x, y), true);
sl@0
    33
}
sl@0
    34
sl@0
    35
template<class I> inline
sl@0
    36
I sub(const typename I::base_type& x, const typename I::base_type& y)
sl@0
    37
{
sl@0
    38
  typedef typename I::traits_type Policies;
sl@0
    39
  if (detail::test_input<typename I::base_type, Policies>(x, y))
sl@0
    40
    return I::empty();
sl@0
    41
  typename Policies::rounding rnd;
sl@0
    42
  return I(rnd.sub_down(x, y), rnd.sub_up(x, y), true);
sl@0
    43
}
sl@0
    44
sl@0
    45
template<class I> inline
sl@0
    46
I mul(const typename I::base_type& x, const typename I::base_type& y)
sl@0
    47
{
sl@0
    48
  typedef typename I::traits_type Policies;
sl@0
    49
  if (detail::test_input<typename I::base_type, Policies>(x, y))
sl@0
    50
    return I::empty();
sl@0
    51
  typename Policies::rounding rnd;
sl@0
    52
  return I(rnd.mul_down(x, y), rnd.mul_up(x, y), true);
sl@0
    53
}
sl@0
    54
sl@0
    55
template<class I> inline
sl@0
    56
I div(const typename I::base_type& x, const typename I::base_type& y)
sl@0
    57
{
sl@0
    58
  typedef typename I::traits_type Policies;
sl@0
    59
  if (detail::test_input<typename I::base_type, Policies>(x, y) || user::is_zero(y))
sl@0
    60
    return I::empty();
sl@0
    61
  typename Policies::rounding rnd;
sl@0
    62
  return I(rnd.div_down(x, y), rnd.div_up(x, y), true);
sl@0
    63
}
sl@0
    64
sl@0
    65
} // namespace interval_lib
sl@0
    66
} // namespace numeric
sl@0
    67
} // namespace boost
sl@0
    68
sl@0
    69
#endif // BOOST_NUMERIC_INTERVAL_ARITH3_HPP