]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/numeric/interval/include/boost/numeric/interval/arith3.hpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / numeric / interval / include / boost / numeric / interval / arith3.hpp
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
21 namespace boost {
22 namespace numeric {
23 namespace interval_lib {
24
25 template<class I> inline
26 I 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
35 template<class I> inline
36 I 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
45 template<class I> inline
46 I 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
55 template<class I> inline
56 I 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