1
0
This repository has been archived on 2025-03-06. You can view files and clone it, but cannot push or open issues or pull requests.
Jip J. Dekker 3e72b0e857 Squashed 'software/gecode_on_record/' content from commit 37ed9bda4
git-subtree-dir: software/gecode_on_record
git-subtree-split: 37ed9bda495ea87e63217c19a374b5a93bb0078e
2021-06-16 14:03:52 +10:00

70 lines
2.2 KiB
C++

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