sl@0: /* Boost interval/arith3.hpp template implementation file sl@0: * sl@0: * This headers provides arithmetical functions sl@0: * which compute an interval given some base sl@0: * numbers. The resulting interval encloses the sl@0: * real result of the arithmetic operation. sl@0: * sl@0: * Copyright 2003 Guillaume Melquiond sl@0: * sl@0: * Distributed under the Boost Software License, Version 1.0. sl@0: * (See accompanying file LICENSE_1_0.txt or sl@0: * copy at http://www.boost.org/LICENSE_1_0.txt) sl@0: */ sl@0: sl@0: #ifndef BOOST_NUMERIC_INTERVAL_ARITH3_HPP sl@0: #define BOOST_NUMERIC_INTERVAL_ARITH3_HPP sl@0: sl@0: #include sl@0: #include sl@0: sl@0: namespace boost { sl@0: namespace numeric { sl@0: namespace interval_lib { sl@0: sl@0: template inline sl@0: I add(const typename I::base_type& x, const typename I::base_type& y) sl@0: { sl@0: typedef typename I::traits_type Policies; sl@0: if (detail::test_input(x, y)) sl@0: return I::empty(); sl@0: typename Policies::rounding rnd; sl@0: return I(rnd.add_down(x, y), rnd.add_up(x, y), true); sl@0: } sl@0: sl@0: template inline sl@0: I sub(const typename I::base_type& x, const typename I::base_type& y) sl@0: { sl@0: typedef typename I::traits_type Policies; sl@0: if (detail::test_input(x, y)) sl@0: return I::empty(); sl@0: typename Policies::rounding rnd; sl@0: return I(rnd.sub_down(x, y), rnd.sub_up(x, y), true); sl@0: } sl@0: sl@0: template inline sl@0: I mul(const typename I::base_type& x, const typename I::base_type& y) sl@0: { sl@0: typedef typename I::traits_type Policies; sl@0: if (detail::test_input(x, y)) sl@0: return I::empty(); sl@0: typename Policies::rounding rnd; sl@0: return I(rnd.mul_down(x, y), rnd.mul_up(x, y), true); sl@0: } sl@0: sl@0: template inline sl@0: I div(const typename I::base_type& x, const typename I::base_type& y) sl@0: { sl@0: typedef typename I::traits_type Policies; sl@0: if (detail::test_input(x, y) || user::is_zero(y)) sl@0: return I::empty(); sl@0: typename Policies::rounding rnd; sl@0: return I(rnd.div_down(x, y), rnd.div_up(x, y), true); sl@0: } sl@0: sl@0: } // namespace interval_lib sl@0: } // namespace numeric sl@0: } // namespace boost sl@0: sl@0: #endif // BOOST_NUMERIC_INTERVAL_ARITH3_HPP