Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:49:07

0001 /* Boost interval/arith3.hpp template implementation file
0002  *
0003  * This headers provides arithmetical functions
0004  * which compute an interval given some base
0005  * numbers. The resulting interval encloses the
0006  * real result of the arithmetic operation.
0007  *
0008  * Copyright 2003 Guillaume Melquiond
0009  *
0010  * Distributed under the Boost Software License, Version 1.0.
0011  * (See accompanying file LICENSE_1_0.txt or
0012  * copy at http://www.boost.org/LICENSE_1_0.txt)
0013  */
0014 
0015 #ifndef BOOST_NUMERIC_INTERVAL_ARITH3_HPP
0016 #define BOOST_NUMERIC_INTERVAL_ARITH3_HPP
0017 
0018 #include <boost/numeric/interval/detail/interval_prototype.hpp>
0019 #include <boost/numeric/interval/detail/test_input.hpp>
0020 
0021 namespace boost {
0022 namespace numeric {
0023 namespace interval_lib {
0024 
0025 template<class I> inline
0026 I add(const typename I::base_type& x, const typename I::base_type& y)
0027 {
0028   typedef typename I::traits_type Policies;
0029   if (detail::test_input<typename I::base_type, Policies>(x, y))
0030     return I::empty();
0031   typename Policies::rounding rnd;
0032   return I(rnd.add_down(x, y), rnd.add_up(x, y), true);
0033 }
0034 
0035 template<class I> inline
0036 I sub(const typename I::base_type& x, const typename I::base_type& y)
0037 {
0038   typedef typename I::traits_type Policies;
0039   if (detail::test_input<typename I::base_type, Policies>(x, y))
0040     return I::empty();
0041   typename Policies::rounding rnd;
0042   return I(rnd.sub_down(x, y), rnd.sub_up(x, y), true);
0043 }
0044 
0045 template<class I> inline
0046 I mul(const typename I::base_type& x, const typename I::base_type& y)
0047 {
0048   typedef typename I::traits_type Policies;
0049   if (detail::test_input<typename I::base_type, Policies>(x, y))
0050     return I::empty();
0051   typename Policies::rounding rnd;
0052   return I(rnd.mul_down(x, y), rnd.mul_up(x, y), true);
0053 }
0054 
0055 template<class I> inline
0056 I div(const typename I::base_type& x, const typename I::base_type& y)
0057 {
0058   typedef typename I::traits_type Policies;
0059   if (detail::test_input<typename I::base_type, Policies>(x, y) || user::is_zero(y))
0060     return I::empty();
0061   typename Policies::rounding rnd;
0062   return I(rnd.div_down(x, y), rnd.div_up(x, y), true);
0063 }
0064 
0065 } // namespace interval_lib
0066 } // namespace numeric
0067 } // namespace boost
0068 
0069 #endif // BOOST_NUMERIC_INTERVAL_ARITH3_HPP