source: NonGTP/Boost/boost/numeric/interval/arith3.hpp @ 857

Revision 857, 2.2 KB checked in by igarcia, 19 years ago (diff)
RevLine 
[857]1/* Boost interval/arith3.hpp template implementation file
2 *
3 * This headers provides arithmetical functions
4 * which compute an interval given some base
5 * numbers. The resulting interval encloses the
6 * real result of the arithmetic operation.
7 *
8 * Copyright 2003 Guillaume Melquiond
9 *
10 * Distributed under the Boost Software License, Version 1.0.
11 * (See accompanying file LICENSE_1_0.txt or
12 * copy at http://www.boost.org/LICENSE_1_0.txt)
13 */
14
15#ifndef BOOST_NUMERIC_INTERVAL_ARITH3_HPP
16#define BOOST_NUMERIC_INTERVAL_ARITH3_HPP
17
18#include <boost/numeric/interval/detail/interval_prototype.hpp>
19#include <boost/numeric/interval/detail/test_input.hpp>
20
21namespace boost {
22namespace numeric {
23namespace interval_lib {
24
25template<class I> inline
26I add(const typename I::base_type& x, const typename I::base_type& y)
27{
28  typedef typename I::traits_type Policies;
29  if (detail::test_input<typename I::base_type, Policies>(x, y))
30    return I::empty();
31  typename Policies::rounding rnd;
32  return I(rnd.add_down(x, y), rnd.add_up(x, y), true);
33}
34
35template<class I> inline
36I sub(const typename I::base_type& x, const typename I::base_type& y)
37{
38  typedef typename I::traits_type Policies;
39  if (detail::test_input<typename I::base_type, Policies>(x, y))
40    return I::empty();
41  typename Policies::rounding rnd;
42  return I(rnd.sub_down(x, y), rnd.sub_up(x, y), true);
43}
44
45template<class I> inline
46I mul(const typename I::base_type& x, const typename I::base_type& y)
47{
48  typedef typename I::traits_type Policies;
49  if (detail::test_input<typename I::base_type, Policies>(x, y))
50    return I::empty();
51  typename Policies::rounding rnd;
52  return I(rnd.mul_down(x, y), rnd.mul_up(x, y), true);
53}
54
55template<class I> inline
56I div(const typename I::base_type& x, const typename I::base_type& y)
57{
58  typedef typename I::traits_type Policies;
59  if (detail::test_input<typename I::base_type, Policies>(x, y) || user::is_zero(y))
60    return I::empty();
61  typename Policies::rounding rnd;
62  return I(rnd.div_down(x, y), rnd.div_up(x, y), true);
63}
64
65} // namespace interval_lib
66} // namespace numeric
67} // namespace boost
68
69#endif // BOOST_NUMERIC_INTERVAL_ARITH3_HPP
Note: See TracBrowser for help on using the repository browser.