Apply consistent code formatting across the repo. Add clang-format and pre-commit hooks.

This commit is contained in:
Rob Armstrong
2025-03-27 10:30:07 -07:00
parent 2cd58fbc9a
commit ceab6e8bcc
782 changed files with 107230 additions and 106548 deletions

View File

@@ -11,12 +11,12 @@
#ifndef BOOST_NUMERIC_INTERVAL_ARITH_HPP
#define BOOST_NUMERIC_INTERVAL_ARITH_HPP
#include <boost/config.hpp>
#include <boost/numeric/interval/interval.hpp>
#include <boost/numeric/interval/detail/bugs.hpp>
#include <boost/numeric/interval/detail/test_input.hpp>
#include <boost/numeric/interval/detail/division.hpp>
#include <algorithm>
#include <boost/config.hpp>
#include <boost/numeric/interval/detail/bugs.hpp>
#include <boost/numeric/interval/detail/division.hpp>
#include <boost/numeric/interval/detail/test_input.hpp>
#include <boost/numeric/interval/interval.hpp>
namespace boost {
namespace numeric {
@@ -25,278 +25,253 @@ namespace numeric {
* Basic arithmetic operators
*/
template<class T, class Policies> inline
const interval<T, Policies>& operator+(const interval<T, Policies>& x)
template <class T, class Policies> inline const interval<T, Policies> &operator+(const interval<T, Policies> &x)
{
return x;
return x;
}
template<class T, class Policies> inline
interval<T, Policies> operator-(const interval<T, Policies>& x)
template <class T, class Policies> inline interval<T, Policies> operator-(const interval<T, Policies> &x)
{
if (interval_lib::detail::test_input(x))
return interval<T, Policies>::empty();
return interval<T, Policies>(-x.upper(), -x.lower(), true);
}
template<class T, class Policies> inline
interval<T, Policies>& interval<T, Policies>::operator+=(const interval<T, Policies>& r)
{
if (interval_lib::detail::test_input(*this, r))
set_empty();
else {
typename Policies::rounding rnd;
set(rnd.add_down(low, r.low), rnd.add_up(up, r.up));
}
return *this;
}
template<class T, class Policies> inline
interval<T, Policies>& interval<T, Policies>::operator+=(const T& r)
{
if (interval_lib::detail::test_input(*this, r))
set_empty();
else {
typename Policies::rounding rnd;
set(rnd.add_down(low, r), rnd.add_up(up, r));
}
return *this;
}
template<class T, class Policies> inline
interval<T, Policies>& interval<T, Policies>::operator-=(const interval<T, Policies>& r)
{
if (interval_lib::detail::test_input(*this, r))
set_empty();
else {
typename Policies::rounding rnd;
set(rnd.sub_down(low, r.up), rnd.sub_up(up, r.low));
}
return *this;
}
template<class T, class Policies> inline
interval<T, Policies>& interval<T, Policies>::operator-=(const T& r)
{
if (interval_lib::detail::test_input(*this, r))
set_empty();
else {
typename Policies::rounding rnd;
set(rnd.sub_down(low, r), rnd.sub_up(up, r));
}
return *this;
}
template<class T, class Policies> inline
interval<T, Policies>& interval<T, Policies>::operator*=(const interval<T, Policies>& r)
{
return *this = *this * r;
}
template<class T, class Policies> inline
interval<T, Policies>& interval<T, Policies>::operator*=(const T& r)
{
return *this = r * *this;
}
template<class T, class Policies> inline
interval<T, Policies>& interval<T, Policies>::operator/=(const interval<T, Policies>& r)
{
return *this = *this / r;
}
template<class T, class Policies> inline
interval<T, Policies>& interval<T, Policies>::operator/=(const T& r)
{
return *this = *this / r;
}
template<class T, class Policies> inline
interval<T, Policies> operator+(const interval<T, Policies>& x,
const interval<T, Policies>& y)
{
if (interval_lib::detail::test_input(x, y))
return interval<T, Policies>::empty();
typename Policies::rounding rnd;
return interval<T,Policies>(rnd.add_down(x.lower(), y.lower()),
rnd.add_up (x.upper(), y.upper()), true);
}
template<class T, class Policies> inline
interval<T, Policies> operator+(const T& x, const interval<T, Policies>& y)
{
if (interval_lib::detail::test_input(x, y))
return interval<T, Policies>::empty();
typename Policies::rounding rnd;
return interval<T,Policies>(rnd.add_down(x, y.lower()),
rnd.add_up (x, y.upper()), true);
}
template<class T, class Policies> inline
interval<T, Policies> operator+(const interval<T, Policies>& x, const T& y)
{ return y + x; }
template<class T, class Policies> inline
interval<T, Policies> operator-(const interval<T, Policies>& x,
const interval<T, Policies>& y)
{
if (interval_lib::detail::test_input(x, y))
return interval<T, Policies>::empty();
typename Policies::rounding rnd;
return interval<T,Policies>(rnd.sub_down(x.lower(), y.upper()),
rnd.sub_up (x.upper(), y.lower()), true);
}
template<class T, class Policies> inline
interval<T, Policies> operator-(const T& x, const interval<T, Policies>& y)
{
if (interval_lib::detail::test_input(x, y))
return interval<T, Policies>::empty();
typename Policies::rounding rnd;
return interval<T,Policies>(rnd.sub_down(x, y.upper()),
rnd.sub_up (x, y.lower()), true);
}
template<class T, class Policies> inline
interval<T, Policies> operator-(const interval<T, Policies>& x, const T& y)
{
if (interval_lib::detail::test_input(x, y))
return interval<T, Policies>::empty();
typename Policies::rounding rnd;
return interval<T,Policies>(rnd.sub_down(x.lower(), y),
rnd.sub_up (x.upper(), y), true);
}
template<class T, class Policies> inline
interval<T, Policies> operator*(const interval<T, Policies>& x,
const interval<T, Policies>& y)
{
BOOST_USING_STD_MIN();
BOOST_USING_STD_MAX();
typedef interval<T, Policies> I;
if (interval_lib::detail::test_input(x, y))
return I::empty();
typename Policies::rounding rnd;
const T& xl = x.lower();
const T& xu = x.upper();
const T& yl = y.lower();
const T& yu = y.upper();
if (interval_lib::user::is_neg(xl))
if (interval_lib::user::is_pos(xu))
if (interval_lib::user::is_neg(yl))
if (interval_lib::user::is_pos(yu)) // M * M
return I(min BOOST_PREVENT_MACRO_SUBSTITUTION(rnd.mul_down(xl, yu), rnd.mul_down(xu, yl)),
max BOOST_PREVENT_MACRO_SUBSTITUTION(rnd.mul_up (xl, yl), rnd.mul_up (xu, yu)), true);
else // M * N
return I(rnd.mul_down(xu, yl), rnd.mul_up(xl, yl), true);
else
if (interval_lib::user::is_pos(yu)) // M * P
return I(rnd.mul_down(xl, yu), rnd.mul_up(xu, yu), true);
else // M * Z
return I(static_cast<T>(0), static_cast<T>(0), true);
else
if (interval_lib::user::is_neg(yl))
if (interval_lib::user::is_pos(yu)) // N * M
return I(rnd.mul_down(xl, yu), rnd.mul_up(xl, yl), true);
else // N * N
return I(rnd.mul_down(xu, yu), rnd.mul_up(xl, yl), true);
else
if (interval_lib::user::is_pos(yu)) // N * P
return I(rnd.mul_down(xl, yu), rnd.mul_up(xu, yl), true);
else // N * Z
return I(static_cast<T>(0), static_cast<T>(0), true);
else
if (interval_lib::user::is_pos(xu))
if (interval_lib::user::is_neg(yl))
if (interval_lib::user::is_pos(yu)) // P * M
return I(rnd.mul_down(xu, yl), rnd.mul_up(xu, yu), true);
else // P * N
return I(rnd.mul_down(xu, yl), rnd.mul_up(xl, yu), true);
else
if (interval_lib::user::is_pos(yu)) // P * P
return I(rnd.mul_down(xl, yl), rnd.mul_up(xu, yu), true);
else // P * Z
return I(static_cast<T>(0), static_cast<T>(0), true);
else // Z * ?
return I(static_cast<T>(0), static_cast<T>(0), true);
}
template<class T, class Policies> inline
interval<T, Policies> operator*(const T& x, const interval<T, Policies>& y)
{
typedef interval<T, Policies> I;
if (interval_lib::detail::test_input(x, y))
return I::empty();
typename Policies::rounding rnd;
const T& yl = y.lower();
const T& yu = y.upper();
// x is supposed not to be infinite
if (interval_lib::user::is_neg(x))
return I(rnd.mul_down(x, yu), rnd.mul_up(x, yl), true);
else if (interval_lib::user::is_zero(x))
return I(static_cast<T>(0), static_cast<T>(0), true);
else
return I(rnd.mul_down(x, yl), rnd.mul_up(x, yu), true);
}
template<class T, class Policies> inline
interval<T, Policies> operator*(const interval<T, Policies>& x, const T& y)
{ return y * x; }
template<class T, class Policies> inline
interval<T, Policies> operator/(const interval<T, Policies>& x,
const interval<T, Policies>& y)
{
if (interval_lib::detail::test_input(x, y))
return interval<T, Policies>::empty();
if (zero_in(y))
if (!interval_lib::user::is_zero(y.lower()))
if (!interval_lib::user::is_zero(y.upper()))
return interval_lib::detail::div_zero(x);
else
return interval_lib::detail::div_negative(x, y.lower());
else
if (!interval_lib::user::is_zero(y.upper()))
return interval_lib::detail::div_positive(x, y.upper());
else
if (interval_lib::detail::test_input(x))
return interval<T, Policies>::empty();
else
return interval_lib::detail::div_non_zero(x, y);
return interval<T, Policies>(-x.upper(), -x.lower(), true);
}
template<class T, class Policies> inline
interval<T, Policies> operator/(const T& x, const interval<T, Policies>& y)
template <class T, class Policies>
inline interval<T, Policies> &interval<T, Policies>::operator+=(const interval<T, Policies> &r)
{
if (interval_lib::detail::test_input(x, y))
return interval<T, Policies>::empty();
if (zero_in(y))
if (!interval_lib::user::is_zero(y.lower()))
if (!interval_lib::user::is_zero(y.upper()))
return interval_lib::detail::div_zero<T, Policies>(x);
else
return interval_lib::detail::div_negative<T, Policies>(x, y.lower());
else
if (!interval_lib::user::is_zero(y.upper()))
return interval_lib::detail::div_positive<T, Policies>(x, y.upper());
else
if (interval_lib::detail::test_input(*this, r))
set_empty();
else {
typename Policies::rounding rnd;
set(rnd.add_down(low, r.low), rnd.add_up(up, r.up));
}
return *this;
}
template <class T, class Policies> inline interval<T, Policies> &interval<T, Policies>::operator+=(const T &r)
{
if (interval_lib::detail::test_input(*this, r))
set_empty();
else {
typename Policies::rounding rnd;
set(rnd.add_down(low, r), rnd.add_up(up, r));
}
return *this;
}
template <class T, class Policies>
inline interval<T, Policies> &interval<T, Policies>::operator-=(const interval<T, Policies> &r)
{
if (interval_lib::detail::test_input(*this, r))
set_empty();
else {
typename Policies::rounding rnd;
set(rnd.sub_down(low, r.up), rnd.sub_up(up, r.low));
}
return *this;
}
template <class T, class Policies> inline interval<T, Policies> &interval<T, Policies>::operator-=(const T &r)
{
if (interval_lib::detail::test_input(*this, r))
set_empty();
else {
typename Policies::rounding rnd;
set(rnd.sub_down(low, r), rnd.sub_up(up, r));
}
return *this;
}
template <class T, class Policies>
inline interval<T, Policies> &interval<T, Policies>::operator*=(const interval<T, Policies> &r)
{
return *this = *this * r;
}
template <class T, class Policies> inline interval<T, Policies> &interval<T, Policies>::operator*=(const T &r)
{
return *this = r * *this;
}
template <class T, class Policies>
inline interval<T, Policies> &interval<T, Policies>::operator/=(const interval<T, Policies> &r)
{
return *this = *this / r;
}
template <class T, class Policies> inline interval<T, Policies> &interval<T, Policies>::operator/=(const T &r)
{
return *this = *this / r;
}
template <class T, class Policies>
inline interval<T, Policies> operator+(const interval<T, Policies> &x, const interval<T, Policies> &y)
{
if (interval_lib::detail::test_input(x, y))
return interval<T, Policies>::empty();
else
return interval_lib::detail::div_non_zero(x, y);
typename Policies::rounding rnd;
return interval<T, Policies>(rnd.add_down(x.lower(), y.lower()), rnd.add_up(x.upper(), y.upper()), true);
}
template<class T, class Policies> inline
interval<T, Policies> operator/(const interval<T, Policies>& x, const T& y)
template <class T, class Policies> inline interval<T, Policies> operator+(const T &x, const interval<T, Policies> &y)
{
if (interval_lib::detail::test_input(x, y) || interval_lib::user::is_zero(y))
return interval<T, Policies>::empty();
typename Policies::rounding rnd;
const T& xl = x.lower();
const T& xu = x.upper();
if (interval_lib::user::is_neg(y))
return interval<T, Policies>(rnd.div_down(xu, y), rnd.div_up(xl, y), true);
else
return interval<T, Policies>(rnd.div_down(xl, y), rnd.div_up(xu, y), true);
if (interval_lib::detail::test_input(x, y))
return interval<T, Policies>::empty();
typename Policies::rounding rnd;
return interval<T, Policies>(rnd.add_down(x, y.lower()), rnd.add_up(x, y.upper()), true);
}
template <class T, class Policies> inline interval<T, Policies> operator+(const interval<T, Policies> &x, const T &y)
{
return y + x;
}
template <class T, class Policies>
inline interval<T, Policies> operator-(const interval<T, Policies> &x, const interval<T, Policies> &y)
{
if (interval_lib::detail::test_input(x, y))
return interval<T, Policies>::empty();
typename Policies::rounding rnd;
return interval<T, Policies>(rnd.sub_down(x.lower(), y.upper()), rnd.sub_up(x.upper(), y.lower()), true);
}
template <class T, class Policies> inline interval<T, Policies> operator-(const T &x, const interval<T, Policies> &y)
{
if (interval_lib::detail::test_input(x, y))
return interval<T, Policies>::empty();
typename Policies::rounding rnd;
return interval<T, Policies>(rnd.sub_down(x, y.upper()), rnd.sub_up(x, y.lower()), true);
}
template <class T, class Policies> inline interval<T, Policies> operator-(const interval<T, Policies> &x, const T &y)
{
if (interval_lib::detail::test_input(x, y))
return interval<T, Policies>::empty();
typename Policies::rounding rnd;
return interval<T, Policies>(rnd.sub_down(x.lower(), y), rnd.sub_up(x.upper(), y), true);
}
template <class T, class Policies>
inline interval<T, Policies> operator*(const interval<T, Policies> &x, const interval<T, Policies> &y)
{
BOOST_USING_STD_MIN();
BOOST_USING_STD_MAX();
typedef interval<T, Policies> I;
if (interval_lib::detail::test_input(x, y))
return I::empty();
typename Policies::rounding rnd;
const T &xl = x.lower();
const T &xu = x.upper();
const T &yl = y.lower();
const T &yu = y.upper();
if (interval_lib::user::is_neg(xl))
if (interval_lib::user::is_pos(xu))
if (interval_lib::user::is_neg(yl))
if (interval_lib::user::is_pos(yu)) // M * M
return I(min BOOST_PREVENT_MACRO_SUBSTITUTION(rnd.mul_down(xl, yu), rnd.mul_down(xu, yl)),
max BOOST_PREVENT_MACRO_SUBSTITUTION(rnd.mul_up(xl, yl), rnd.mul_up(xu, yu)),
true);
else // M * N
return I(rnd.mul_down(xu, yl), rnd.mul_up(xl, yl), true);
else if (interval_lib::user::is_pos(yu)) // M * P
return I(rnd.mul_down(xl, yu), rnd.mul_up(xu, yu), true);
else // M * Z
return I(static_cast<T>(0), static_cast<T>(0), true);
else if (interval_lib::user::is_neg(yl))
if (interval_lib::user::is_pos(yu)) // N * M
return I(rnd.mul_down(xl, yu), rnd.mul_up(xl, yl), true);
else // N * N
return I(rnd.mul_down(xu, yu), rnd.mul_up(xl, yl), true);
else if (interval_lib::user::is_pos(yu)) // N * P
return I(rnd.mul_down(xl, yu), rnd.mul_up(xu, yl), true);
else // N * Z
return I(static_cast<T>(0), static_cast<T>(0), true);
else if (interval_lib::user::is_pos(xu))
if (interval_lib::user::is_neg(yl))
if (interval_lib::user::is_pos(yu)) // P * M
return I(rnd.mul_down(xu, yl), rnd.mul_up(xu, yu), true);
else // P * N
return I(rnd.mul_down(xu, yl), rnd.mul_up(xl, yu), true);
else if (interval_lib::user::is_pos(yu)) // P * P
return I(rnd.mul_down(xl, yl), rnd.mul_up(xu, yu), true);
else // P * Z
return I(static_cast<T>(0), static_cast<T>(0), true);
else // Z * ?
return I(static_cast<T>(0), static_cast<T>(0), true);
}
template <class T, class Policies> inline interval<T, Policies> operator*(const T &x, const interval<T, Policies> &y)
{
typedef interval<T, Policies> I;
if (interval_lib::detail::test_input(x, y))
return I::empty();
typename Policies::rounding rnd;
const T &yl = y.lower();
const T &yu = y.upper();
// x is supposed not to be infinite
if (interval_lib::user::is_neg(x))
return I(rnd.mul_down(x, yu), rnd.mul_up(x, yl), true);
else if (interval_lib::user::is_zero(x))
return I(static_cast<T>(0), static_cast<T>(0), true);
else
return I(rnd.mul_down(x, yl), rnd.mul_up(x, yu), true);
}
template <class T, class Policies> inline interval<T, Policies> operator*(const interval<T, Policies> &x, const T &y)
{
return y * x;
}
template <class T, class Policies>
inline interval<T, Policies> operator/(const interval<T, Policies> &x, const interval<T, Policies> &y)
{
if (interval_lib::detail::test_input(x, y))
return interval<T, Policies>::empty();
if (zero_in(y))
if (!interval_lib::user::is_zero(y.lower()))
if (!interval_lib::user::is_zero(y.upper()))
return interval_lib::detail::div_zero(x);
else
return interval_lib::detail::div_negative(x, y.lower());
else if (!interval_lib::user::is_zero(y.upper()))
return interval_lib::detail::div_positive(x, y.upper());
else
return interval<T, Policies>::empty();
else
return interval_lib::detail::div_non_zero(x, y);
}
template <class T, class Policies> inline interval<T, Policies> operator/(const T &x, const interval<T, Policies> &y)
{
if (interval_lib::detail::test_input(x, y))
return interval<T, Policies>::empty();
if (zero_in(y))
if (!interval_lib::user::is_zero(y.lower()))
if (!interval_lib::user::is_zero(y.upper()))
return interval_lib::detail::div_zero<T, Policies>(x);
else
return interval_lib::detail::div_negative<T, Policies>(x, y.lower());
else if (!interval_lib::user::is_zero(y.upper()))
return interval_lib::detail::div_positive<T, Policies>(x, y.upper());
else
return interval<T, Policies>::empty();
else
return interval_lib::detail::div_non_zero(x, y);
}
template <class T, class Policies> inline interval<T, Policies> operator/(const interval<T, Policies> &x, const T &y)
{
if (interval_lib::detail::test_input(x, y) || interval_lib::user::is_zero(y))
return interval<T, Policies>::empty();
typename Policies::rounding rnd;
const T &xl = x.lower();
const T &xu = x.upper();
if (interval_lib::user::is_neg(y))
return interval<T, Policies>(rnd.div_down(xu, y), rnd.div_up(xl, y), true);
else
return interval<T, Policies>(rnd.div_down(xl, y), rnd.div_up(xu, y), true);
}
} // namespace numeric

View File

@@ -14,289 +14,296 @@
#ifndef BOOST_NUMERIC_INTERVAL_ARITH2_HPP
#define BOOST_NUMERIC_INTERVAL_ARITH2_HPP
#include <algorithm>
#include <boost/config.hpp>
#include <boost/numeric/interval/detail/interval_prototype.hpp>
#include <boost/numeric/interval/detail/test_input.hpp>
#include <boost/config/no_tr1/cmath.hpp>
#include <boost/numeric/interval/arith.hpp>
#include <boost/numeric/interval/detail/bugs.hpp>
#include <boost/numeric/interval/detail/division.hpp>
#include <boost/numeric/interval/arith.hpp>
#include <boost/numeric/interval/detail/interval_prototype.hpp>
#include <boost/numeric/interval/detail/test_input.hpp>
#include <boost/numeric/interval/policies.hpp>
#include <algorithm>
#include <cassert>
#include <boost/config/no_tr1/cmath.hpp>
namespace boost {
namespace numeric {
template<class T, class Policies> inline
interval<T, Policies> fmod(const interval<T, Policies>& x,
const interval<T, Policies>& y)
template <class T, class Policies>
inline interval<T, Policies> fmod(const interval<T, Policies> &x, const interval<T, Policies> &y)
{
if (interval_lib::detail::test_input(x, y))
return interval<T, Policies>::empty();
typename Policies::rounding rnd;
typedef typename interval_lib::unprotect<interval<T, Policies> >::type I;
T const &yb = interval_lib::user::is_neg(x.lower()) ? y.lower() : y.upper();
T n = rnd.int_down(rnd.div_down(x.lower(), yb));
return (const I&)x - n * (const I&)y;
if (interval_lib::detail::test_input(x, y))
return interval<T, Policies>::empty();
typename Policies::rounding rnd;
typedef typename interval_lib::unprotect<interval<T, Policies>>::type I;
T const &yb = interval_lib::user::is_neg(x.lower()) ? y.lower() : y.upper();
T n = rnd.int_down(rnd.div_down(x.lower(), yb));
return (const I &)x - n * (const I &)y;
}
template<class T, class Policies> inline
interval<T, Policies> fmod(const interval<T, Policies>& x, const T& y)
template <class T, class Policies> inline interval<T, Policies> fmod(const interval<T, Policies> &x, const T &y)
{
if (interval_lib::detail::test_input(x, y))
return interval<T, Policies>::empty();
typename Policies::rounding rnd;
typedef typename interval_lib::unprotect<interval<T, Policies> >::type I;
T n = rnd.int_down(rnd.div_down(x.lower(), y));
return (const I&)x - n * I(y);
if (interval_lib::detail::test_input(x, y))
return interval<T, Policies>::empty();
typename Policies::rounding rnd;
typedef typename interval_lib::unprotect<interval<T, Policies>>::type I;
T n = rnd.int_down(rnd.div_down(x.lower(), y));
return (const I &)x - n * I(y);
}
template<class T, class Policies> inline
interval<T, Policies> fmod(const T& x, const interval<T, Policies>& y)
template <class T, class Policies> inline interval<T, Policies> fmod(const T &x, const interval<T, Policies> &y)
{
if (interval_lib::detail::test_input(x, y))
return interval<T, Policies>::empty();
typename Policies::rounding rnd;
typedef typename interval_lib::unprotect<interval<T, Policies> >::type I;
T const &yb = interval_lib::user::is_neg(x) ? y.lower() : y.upper();
T n = rnd.int_down(rnd.div_down(x, yb));
return x - n * (const I&)y;
if (interval_lib::detail::test_input(x, y))
return interval<T, Policies>::empty();
typename Policies::rounding rnd;
typedef typename interval_lib::unprotect<interval<T, Policies>>::type I;
T const &yb = interval_lib::user::is_neg(x) ? y.lower() : y.upper();
T n = rnd.int_down(rnd.div_down(x, yb));
return x - n * (const I &)y;
}
namespace interval_lib {
template<class T, class Policies> inline
interval<T, Policies> division_part1(const interval<T, Policies>& x,
const interval<T, Policies>& y, bool& b)
template <class T, class Policies>
inline interval<T, Policies> division_part1(const interval<T, Policies> &x, const interval<T, Policies> &y, bool &b)
{
typedef interval<T, Policies> I;
b = false;
if (detail::test_input(x, y))
return I::empty();
if (zero_in(y))
if (!user::is_zero(y.lower()))
if (!user::is_zero(y.upper()))
return detail::div_zero_part1(x, y, b);
else
return detail::div_negative(x, y.lower());
else
if (!user::is_zero(y.upper()))
return detail::div_positive(x, y.upper());
else
typedef interval<T, Policies> I;
b = false;
if (detail::test_input(x, y))
return I::empty();
else
return detail::div_non_zero(x, y);
if (zero_in(y))
if (!user::is_zero(y.lower()))
if (!user::is_zero(y.upper()))
return detail::div_zero_part1(x, y, b);
else
return detail::div_negative(x, y.lower());
else if (!user::is_zero(y.upper()))
return detail::div_positive(x, y.upper());
else
return I::empty();
else
return detail::div_non_zero(x, y);
}
template<class T, class Policies> inline
interval<T, Policies> division_part2(const interval<T, Policies>& x,
const interval<T, Policies>& y, bool b = true)
template <class T, class Policies>
inline interval<T, Policies>
division_part2(const interval<T, Policies> &x, const interval<T, Policies> &y, bool b = true)
{
if (!b) return interval<T, Policies>::empty();
return detail::div_zero_part2(x, y);
if (!b)
return interval<T, Policies>::empty();
return detail::div_zero_part2(x, y);
}
template<class T, class Policies> inline
interval<T, Policies> multiplicative_inverse(const interval<T, Policies>& x)
template <class T, class Policies> inline interval<T, Policies> multiplicative_inverse(const interval<T, Policies> &x)
{
typedef interval<T, Policies> I;
if (detail::test_input(x))
return I::empty();
T one = static_cast<T>(1);
typename Policies::rounding rnd;
if (zero_in(x)) {
typedef typename Policies::checking checking;
if (!user::is_zero(x.lower()))
if (!user::is_zero(x.upper()))
return I::whole();
else
return I(checking::neg_inf(), rnd.div_up(one, x.lower()), true);
else
if (!user::is_zero(x.upper()))
return I(rnd.div_down(one, x.upper()), checking::pos_inf(), true);
else
typedef interval<T, Policies> I;
if (detail::test_input(x))
return I::empty();
} else
return I(rnd.div_down(one, x.upper()), rnd.div_up(one, x.lower()), true);
T one = static_cast<T>(1);
typename Policies::rounding rnd;
if (zero_in(x)) {
typedef typename Policies::checking checking;
if (!user::is_zero(x.lower()))
if (!user::is_zero(x.upper()))
return I::whole();
else
return I(checking::neg_inf(), rnd.div_up(one, x.lower()), true);
else if (!user::is_zero(x.upper()))
return I(rnd.div_down(one, x.upper()), checking::pos_inf(), true);
else
return I::empty();
}
else
return I(rnd.div_down(one, x.upper()), rnd.div_up(one, x.lower()), true);
}
namespace detail {
template<class T, class Rounding> inline
T pow_dn(const T& x_, int pwr, Rounding& rnd) // x and pwr are positive
template <class T, class Rounding> inline T pow_dn(const T &x_, int pwr, Rounding &rnd) // x and pwr are positive
{
T x = x_;
T y = (pwr & 1) ? x_ : static_cast<T>(1);
pwr >>= 1;
while (pwr > 0) {
x = rnd.mul_down(x, x);
if (pwr & 1) y = rnd.mul_down(x, y);
T x = x_;
T y = (pwr & 1) ? x_ : static_cast<T>(1);
pwr >>= 1;
}
return y;
while (pwr > 0) {
x = rnd.mul_down(x, x);
if (pwr & 1)
y = rnd.mul_down(x, y);
pwr >>= 1;
}
return y;
}
template<class T, class Rounding> inline
T pow_up(const T& x_, int pwr, Rounding& rnd) // x and pwr are positive
template <class T, class Rounding> inline T pow_up(const T &x_, int pwr, Rounding &rnd) // x and pwr are positive
{
T x = x_;
T y = (pwr & 1) ? x_ : static_cast<T>(1);
pwr >>= 1;
while (pwr > 0) {
x = rnd.mul_up(x, x);
if (pwr & 1) y = rnd.mul_up(x, y);
T x = x_;
T y = (pwr & 1) ? x_ : static_cast<T>(1);
pwr >>= 1;
}
return y;
while (pwr > 0) {
x = rnd.mul_up(x, x);
if (pwr & 1)
y = rnd.mul_up(x, y);
pwr >>= 1;
}
return y;
}
} // namespace detail
} // namespace interval_lib
template<class T, class Policies> inline
interval<T, Policies> pow(const interval<T, Policies>& x, int pwr)
template <class T, class Policies> inline interval<T, Policies> pow(const interval<T, Policies> &x, int pwr)
{
BOOST_USING_STD_MAX();
using interval_lib::detail::pow_dn;
using interval_lib::detail::pow_up;
typedef interval<T, Policies> I;
BOOST_USING_STD_MAX();
using interval_lib::detail::pow_dn;
using interval_lib::detail::pow_up;
typedef interval<T, Policies> I;
if (interval_lib::detail::test_input(x))
return I::empty();
if (interval_lib::detail::test_input(x))
return I::empty();
if (pwr == 0)
if (interval_lib::user::is_zero(x.lower())
&& interval_lib::user::is_zero(x.upper()))
return I::empty();
else
return I(static_cast<T>(1));
else if (pwr < 0)
return interval_lib::multiplicative_inverse(pow(x, -pwr));
if (pwr == 0)
if (interval_lib::user::is_zero(x.lower()) && interval_lib::user::is_zero(x.upper()))
return I::empty();
else
return I(static_cast<T>(1));
else if (pwr < 0)
return interval_lib::multiplicative_inverse(pow(x, -pwr));
typename Policies::rounding rnd;
if (interval_lib::user::is_neg(x.upper())) { // [-2,-1]
T yl = pow_dn(static_cast<T>(-x.upper()), pwr, rnd);
T yu = pow_up(static_cast<T>(-x.lower()), pwr, rnd);
if (pwr & 1) // [-2,-1]^1
return I(-yu, -yl, true);
else // [-2,-1]^2
return I(yl, yu, true);
} else if (interval_lib::user::is_neg(x.lower())) { // [-1,1]
if (pwr & 1) { // [-1,1]^1
return I(-pow_up(-x.lower(), pwr, rnd), pow_up(x.upper(), pwr, rnd), true);
} else { // [-1,1]^2
return I(static_cast<T>(0), pow_up(max BOOST_PREVENT_MACRO_SUBSTITUTION(static_cast<T>(-x.lower()), x.upper()), pwr, rnd), true);
typename Policies::rounding rnd;
if (interval_lib::user::is_neg(x.upper())) { // [-2,-1]
T yl = pow_dn(static_cast<T>(-x.upper()), pwr, rnd);
T yu = pow_up(static_cast<T>(-x.lower()), pwr, rnd);
if (pwr & 1) // [-2,-1]^1
return I(-yu, -yl, true);
else // [-2,-1]^2
return I(yl, yu, true);
}
else if (interval_lib::user::is_neg(x.lower())) { // [-1,1]
if (pwr & 1) { // [-1,1]^1
return I(-pow_up(-x.lower(), pwr, rnd), pow_up(x.upper(), pwr, rnd), true);
}
else { // [-1,1]^2
return I(static_cast<T>(0),
pow_up(max BOOST_PREVENT_MACRO_SUBSTITUTION(static_cast<T>(-x.lower()), x.upper()), pwr, rnd),
true);
}
}
else { // [1,2]
return I(pow_dn(x.lower(), pwr, rnd), pow_up(x.upper(), pwr, rnd), true);
}
} else { // [1,2]
return I(pow_dn(x.lower(), pwr, rnd), pow_up(x.upper(), pwr, rnd), true);
}
}
template<class T, class Policies> inline
interval<T, Policies> sqrt(const interval<T, Policies>& x)
template <class T, class Policies> inline interval<T, Policies> sqrt(const interval<T, Policies> &x)
{
typedef interval<T, Policies> I;
if (interval_lib::detail::test_input(x) || interval_lib::user::is_neg(x.upper()))
return I::empty();
typename Policies::rounding rnd;
T l = !interval_lib::user::is_pos(x.lower()) ? static_cast<T>(0) : rnd.sqrt_down(x.lower());
return I(l, rnd.sqrt_up(x.upper()), true);
typedef interval<T, Policies> I;
if (interval_lib::detail::test_input(x) || interval_lib::user::is_neg(x.upper()))
return I::empty();
typename Policies::rounding rnd;
T l = !interval_lib::user::is_pos(x.lower()) ? static_cast<T>(0) : rnd.sqrt_down(x.lower());
return I(l, rnd.sqrt_up(x.upper()), true);
}
template<class T, class Policies> inline
interval<T, Policies> square(const interval<T, Policies>& x)
template <class T, class Policies> inline interval<T, Policies> square(const interval<T, Policies> &x)
{
typedef interval<T, Policies> I;
if (interval_lib::detail::test_input(x))
return I::empty();
typename Policies::rounding rnd;
const T& xl = x.lower();
const T& xu = x.upper();
if (interval_lib::user::is_neg(xu))
return I(rnd.mul_down(xu, xu), rnd.mul_up(xl, xl), true);
else if (interval_lib::user::is_pos(x.lower()))
return I(rnd.mul_down(xl, xl), rnd.mul_up(xu, xu), true);
else
return I(static_cast<T>(0), (-xl > xu ? rnd.mul_up(xl, xl) : rnd.mul_up(xu, xu)), true);
typedef interval<T, Policies> I;
if (interval_lib::detail::test_input(x))
return I::empty();
typename Policies::rounding rnd;
const T &xl = x.lower();
const T &xu = x.upper();
if (interval_lib::user::is_neg(xu))
return I(rnd.mul_down(xu, xu), rnd.mul_up(xl, xl), true);
else if (interval_lib::user::is_pos(x.lower()))
return I(rnd.mul_down(xl, xl), rnd.mul_up(xu, xu), true);
else
return I(static_cast<T>(0), (-xl > xu ? rnd.mul_up(xl, xl) : rnd.mul_up(xu, xu)), true);
}
namespace interval_lib {
namespace detail {
template< class I > inline
I root_aux(typename I::base_type const &x, int k) // x and k are bigger than one
template <class I> inline I root_aux(typename I::base_type const &x, int k) // x and k are bigger than one
{
typedef typename I::base_type T;
T tk(k);
I y(static_cast<T>(1), x, true);
for(;;) {
T y0 = median(y);
I yy = intersect(y, y0 - (pow(I(y0, y0, true), k) - x) / (tk * pow(y, k - 1)));
if (equal(y, yy)) return y;
y = yy;
}
typedef typename I::base_type T;
T tk(k);
I y(static_cast<T>(1), x, true);
for (;;) {
T y0 = median(y);
I yy = intersect(y, y0 - (pow(I(y0, y0, true), k) - x) / (tk * pow(y, k - 1)));
if (equal(y, yy))
return y;
y = yy;
}
}
template< class I > inline // x is positive and k bigger than one
typename I::base_type root_aux_dn(typename I::base_type const &x, int k)
template <class I>
inline // x is positive and k bigger than one
typename I::base_type
root_aux_dn(typename I::base_type const &x, int k)
{
typedef typename I::base_type T;
typedef typename I::traits_type Policies;
typename Policies::rounding rnd;
T one(1);
if (x > one) return root_aux<I>(x, k).lower();
if (x == one) return one;
return rnd.div_down(one, root_aux<I>(rnd.div_up(one, x), k).upper());
typedef typename I::base_type T;
typedef typename I::traits_type Policies;
typename Policies::rounding rnd;
T one(1);
if (x > one)
return root_aux<I>(x, k).lower();
if (x == one)
return one;
return rnd.div_down(one, root_aux<I>(rnd.div_up(one, x), k).upper());
}
template< class I > inline // x is positive and k bigger than one
typename I::base_type root_aux_up(typename I::base_type const &x, int k)
template <class I>
inline // x is positive and k bigger than one
typename I::base_type
root_aux_up(typename I::base_type const &x, int k)
{
typedef typename I::base_type T;
typedef typename I::traits_type Policies;
typename Policies::rounding rnd;
T one(1);
if (x > one) return root_aux<I>(x, k).upper();
if (x == one) return one;
return rnd.div_up(one, root_aux<I>(rnd.div_down(one, x), k).lower());
typedef typename I::base_type T;
typedef typename I::traits_type Policies;
typename Policies::rounding rnd;
T one(1);
if (x > one)
return root_aux<I>(x, k).upper();
if (x == one)
return one;
return rnd.div_up(one, root_aux<I>(rnd.div_down(one, x), k).lower());
}
} // namespace detail
} // namespace interval_lib
template< class T, class Policies > inline
interval<T, Policies> nth_root(interval<T, Policies> const &x, int k)
template <class T, class Policies> inline interval<T, Policies> nth_root(interval<T, Policies> const &x, int k)
{
typedef interval<T, Policies> I;
if (interval_lib::detail::test_input(x)) return I::empty();
assert(k > 0);
if (k == 1) return x;
typename Policies::rounding rnd;
typedef typename interval_lib::unprotect<I>::type R;
if (!interval_lib::user::is_pos(x.upper())) {
if (interval_lib::user::is_zero(x.upper())) {
T zero(0);
if (!(k & 1) || interval_lib::user::is_zero(x.lower())) // [-1,0]^/2 or [0,0]
return I(zero, zero, true);
else // [-1,0]^/3
return I(-interval_lib::detail::root_aux_up<R>(-x.lower(), k), zero, true);
} else if (!(k & 1)) // [-2,-1]^/2
return I::empty();
else { // [-2,-1]^/3
return I(-interval_lib::detail::root_aux_up<R>(-x.lower(), k),
-interval_lib::detail::root_aux_dn<R>(-x.upper(), k), true);
typedef interval<T, Policies> I;
if (interval_lib::detail::test_input(x))
return I::empty();
assert(k > 0);
if (k == 1)
return x;
typename Policies::rounding rnd;
typedef typename interval_lib::unprotect<I>::type R;
if (!interval_lib::user::is_pos(x.upper())) {
if (interval_lib::user::is_zero(x.upper())) {
T zero(0);
if (!(k & 1) || interval_lib::user::is_zero(x.lower())) // [-1,0]^/2 or [0,0]
return I(zero, zero, true);
else // [-1,0]^/3
return I(-interval_lib::detail::root_aux_up<R>(-x.lower(), k), zero, true);
}
else if (!(k & 1)) // [-2,-1]^/2
return I::empty();
else { // [-2,-1]^/3
return I(-interval_lib::detail::root_aux_up<R>(-x.lower(), k),
-interval_lib::detail::root_aux_dn<R>(-x.upper(), k),
true);
}
}
}
T u = interval_lib::detail::root_aux_up<R>(x.upper(), k);
if (!interval_lib::user::is_pos(x.lower()))
if (!(k & 1) || interval_lib::user::is_zero(x.lower())) // [-1,1]^/2 or [0,1]
return I(static_cast<T>(0), u, true);
else // [-1,1]^/3
return I(-interval_lib::detail::root_aux_up<R>(-x.lower(), k), u, true);
else // [1,2]
return I(interval_lib::detail::root_aux_dn<R>(x.lower(), k), u, true);
T u = interval_lib::detail::root_aux_up<R>(x.upper(), k);
if (!interval_lib::user::is_pos(x.lower()))
if (!(k & 1) || interval_lib::user::is_zero(x.lower())) // [-1,1]^/2 or [0,1]
return I(static_cast<T>(0), u, true);
else // [-1,1]^/3
return I(-interval_lib::detail::root_aux_up<R>(-x.lower(), k), u, true);
else // [1,2]
return I(interval_lib::detail::root_aux_dn<R>(x.lower(), k), u, true);
}
} // namespace numeric

View File

@@ -22,44 +22,40 @@ namespace boost {
namespace numeric {
namespace interval_lib {
template<class I> inline
I add(const typename I::base_type& x, const typename I::base_type& y)
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);
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)
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);
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)
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);
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)
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);
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

View File

@@ -10,10 +10,10 @@
#ifndef BOOST_NUMERIC_INTERVAL_CHECKING_HPP
#define BOOST_NUMERIC_INTERVAL_CHECKING_HPP
#include <boost/limits.hpp>
#include <cassert>
#include <stdexcept>
#include <string>
#include <cassert>
#include <boost/limits.hpp>
namespace boost {
namespace numeric {
@@ -21,107 +21,86 @@ namespace interval_lib {
struct exception_create_empty
{
void operator()()
{
throw std::runtime_error("boost::interval: empty interval created");
}
void operator()() { throw std::runtime_error("boost::interval: empty interval created"); }
};
struct exception_invalid_number
{
void operator()()
{
throw std::invalid_argument("boost::interval: invalid number");
}
void operator()() { throw std::invalid_argument("boost::interval: invalid number"); }
};
template<class T>
struct checking_base
template <class T> struct checking_base
{
static T pos_inf()
{
assert(std::numeric_limits<T>::has_infinity);
return std::numeric_limits<T>::infinity();
}
static T neg_inf()
{
assert(std::numeric_limits<T>::has_infinity);
return -std::numeric_limits<T>::infinity();
}
static T nan()
{
assert(std::numeric_limits<T>::has_quiet_NaN);
return std::numeric_limits<T>::quiet_NaN();
}
static bool is_nan(const T& x)
{
return std::numeric_limits<T>::has_quiet_NaN && (x != x);
}
static T empty_lower()
{
return (std::numeric_limits<T>::has_quiet_NaN ?
std::numeric_limits<T>::quiet_NaN() : static_cast<T>(1));
}
static T empty_upper()
{
return (std::numeric_limits<T>::has_quiet_NaN ?
std::numeric_limits<T>::quiet_NaN() : static_cast<T>(0));
}
static bool is_empty(const T& l, const T& u)
{
return !(l <= u); // safety for partial orders
}
static T pos_inf()
{
assert(std::numeric_limits<T>::has_infinity);
return std::numeric_limits<T>::infinity();
}
static T neg_inf()
{
assert(std::numeric_limits<T>::has_infinity);
return -std::numeric_limits<T>::infinity();
}
static T nan()
{
assert(std::numeric_limits<T>::has_quiet_NaN);
return std::numeric_limits<T>::quiet_NaN();
}
static bool is_nan(const T &x) { return std::numeric_limits<T>::has_quiet_NaN && (x != x); }
static T empty_lower()
{
return (std::numeric_limits<T>::has_quiet_NaN ? std::numeric_limits<T>::quiet_NaN() : static_cast<T>(1));
}
static T empty_upper()
{
return (std::numeric_limits<T>::has_quiet_NaN ? std::numeric_limits<T>::quiet_NaN() : static_cast<T>(0));
}
static bool is_empty(const T &l, const T &u)
{
return !(l <= u); // safety for partial orders
}
};
template<class T, class Checking = checking_base<T>,
class Exception = exception_create_empty>
struct checking_no_empty: Checking
template <class T, class Checking = checking_base<T>, class Exception = exception_create_empty>
struct checking_no_empty : Checking
{
static T nan()
{
assert(false);
return Checking::nan();
}
static T empty_lower()
{
Exception()();
return Checking::empty_lower();
}
static T empty_upper()
{
Exception()();
return Checking::empty_upper();
}
static bool is_empty(const T&, const T&)
{
return false;
}
static T nan()
{
assert(false);
return Checking::nan();
}
static T empty_lower()
{
Exception()();
return Checking::empty_lower();
}
static T empty_upper()
{
Exception()();
return Checking::empty_upper();
}
static bool is_empty(const T &, const T &) { return false; }
};
template<class T, class Checking = checking_base<T> >
struct checking_no_nan: Checking
template <class T, class Checking = checking_base<T>> struct checking_no_nan : Checking
{
static bool is_nan(const T&)
{
return false;
}
static bool is_nan(const T &) { return false; }
};
template<class T, class Checking = checking_base<T>,
class Exception = exception_invalid_number>
struct checking_catch_nan: Checking
template <class T, class Checking = checking_base<T>, class Exception = exception_invalid_number>
struct checking_catch_nan : Checking
{
static bool is_nan(const T& x)
{
if (Checking::is_nan(x)) Exception()();
return false;
}
static bool is_nan(const T &x)
{
if (Checking::is_nan(x))
Exception()();
return false;
}
};
template<class T>
struct checking_strict:
checking_no_nan<T, checking_no_empty<T> >
{};
template <class T> struct checking_strict : checking_no_nan<T, checking_no_empty<T>>
{
};
} // namespace interval_lib
} // namespace numeric

View File

@@ -11,9 +11,9 @@
#define BOOST_NUMERIC_INTERVAL_COMPARE_HPP
#include <boost/numeric/interval/compare/certain.hpp>
#include <boost/numeric/interval/compare/possible.hpp>
#include <boost/numeric/interval/compare/explicit.hpp>
#include <boost/numeric/interval/compare/lexicographic.hpp>
#include <boost/numeric/interval/compare/possible.hpp>
#include <boost/numeric/interval/compare/set.hpp>
#endif // BOOST_NUMERIC_INTERVAL_COMPARE_HPP

View File

@@ -19,88 +19,94 @@ namespace interval_lib {
namespace compare {
namespace certain {
template<class T, class Policies1, class Policies2> inline
bool operator<(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
template <class T, class Policies1, class Policies2>
inline bool operator<(const interval<T, Policies1> &x, const interval<T, Policies2> &y)
{
if (detail::test_input(x, y)) throw comparison_error();
return x.upper() < y.lower();
if (detail::test_input(x, y))
throw comparison_error();
return x.upper() < y.lower();
}
template<class T, class Policies> inline
bool operator<(const interval<T, Policies>& x, const T& y)
template <class T, class Policies> inline bool operator<(const interval<T, Policies> &x, const T &y)
{
if (detail::test_input(x, y)) throw comparison_error();
return x.upper() < y;
if (detail::test_input(x, y))
throw comparison_error();
return x.upper() < y;
}
template<class T, class Policies1, class Policies2> inline
bool operator<=(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
template <class T, class Policies1, class Policies2>
inline bool operator<=(const interval<T, Policies1> &x, const interval<T, Policies2> &y)
{
if (detail::test_input(x, y)) throw comparison_error();
return x.upper() <= y.lower();
if (detail::test_input(x, y))
throw comparison_error();
return x.upper() <= y.lower();
}
template<class T, class Policies> inline
bool operator<=(const interval<T, Policies>& x, const T& y)
template <class T, class Policies> inline bool operator<=(const interval<T, Policies> &x, const T &y)
{
if (detail::test_input(x, y)) throw comparison_error();
return x.upper() <= y;
if (detail::test_input(x, y))
throw comparison_error();
return x.upper() <= y;
}
template<class T, class Policies1, class Policies2> inline
bool operator>(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
template <class T, class Policies1, class Policies2>
inline bool operator>(const interval<T, Policies1> &x, const interval<T, Policies2> &y)
{
if (detail::test_input(x, y)) throw comparison_error();
return x.lower() > y.upper();
if (detail::test_input(x, y))
throw comparison_error();
return x.lower() > y.upper();
}
template<class T, class Policies> inline
bool operator>(const interval<T, Policies>& x, const T& y)
template <class T, class Policies> inline bool operator>(const interval<T, Policies> &x, const T &y)
{
if (detail::test_input(x, y)) throw comparison_error();
return x.lower() > y;
if (detail::test_input(x, y))
throw comparison_error();
return x.lower() > y;
}
template<class T, class Policies1, class Policies2> inline
bool operator>=(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
template <class T, class Policies1, class Policies2>
inline bool operator>=(const interval<T, Policies1> &x, const interval<T, Policies2> &y)
{
if (detail::test_input(x, y)) throw comparison_error();
return x.lower() >= y.upper();
if (detail::test_input(x, y))
throw comparison_error();
return x.lower() >= y.upper();
}
template<class T, class Policies> inline
bool operator>=(const interval<T, Policies>& x, const T& y)
template <class T, class Policies> inline bool operator>=(const interval<T, Policies> &x, const T &y)
{
if (detail::test_input(x, y)) throw comparison_error();
return x.lower() >= y;
if (detail::test_input(x, y))
throw comparison_error();
return x.lower() >= y;
}
template<class T, class Policies1, class Policies2> inline
bool operator==(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
template <class T, class Policies1, class Policies2>
inline bool operator==(const interval<T, Policies1> &x, const interval<T, Policies2> &y)
{
if (detail::test_input(x, y)) throw comparison_error();
return x.upper() == y.lower() && x.lower() == y.upper();
if (detail::test_input(x, y))
throw comparison_error();
return x.upper() == y.lower() && x.lower() == y.upper();
}
template<class T, class Policies> inline
bool operator==(const interval<T, Policies>& x, const T& y)
template <class T, class Policies> inline bool operator==(const interval<T, Policies> &x, const T &y)
{
if (detail::test_input(x, y)) throw comparison_error();
return x.upper() == y && x.lower() == y;
if (detail::test_input(x, y))
throw comparison_error();
return x.upper() == y && x.lower() == y;
}
template<class T, class Policies1, class Policies2> inline
bool operator!=(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
template <class T, class Policies1, class Policies2>
inline bool operator!=(const interval<T, Policies1> &x, const interval<T, Policies2> &y)
{
if (detail::test_input(x, y)) throw comparison_error();
return x.upper() < y.lower() || x.lower() > y.upper();
if (detail::test_input(x, y))
throw comparison_error();
return x.upper() < y.lower() || x.lower() > y.upper();
}
template<class T, class Policies> inline
bool operator!=(const interval<T, Policies>& x, const T& y)
template <class T, class Policies> inline bool operator!=(const interval<T, Policies> &x, const T &y)
{
if (detail::test_input(x, y)) throw comparison_error();
return x.upper() < y || x.lower() > y;
if (detail::test_input(x, y))
throw comparison_error();
return x.upper() < y || x.lower() > y;
}
} // namespace certain

View File

@@ -21,228 +21,204 @@ namespace interval_lib {
* Certainly... operations
*/
template<class T, class Policies1, class Policies2> inline
bool cerlt(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
template <class T, class Policies1, class Policies2>
inline bool cerlt(const interval<T, Policies1> &x, const interval<T, Policies2> &y)
{
return x.upper() < y.lower();
return x.upper() < y.lower();
}
template<class T, class Policies> inline
bool cerlt(const interval<T, Policies>& x, const T& y)
template <class T, class Policies> inline bool cerlt(const interval<T, Policies> &x, const T &y)
{
return x.upper() < y;
return x.upper() < y;
}
template<class T, class Policies> inline
bool cerlt(const T& x, const interval<T, Policies>& y)
template <class T, class Policies> inline bool cerlt(const T &x, const interval<T, Policies> &y)
{
return x < y.lower();
return x < y.lower();
}
template<class T, class Policies1, class Policies2> inline
bool cerle(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
template <class T, class Policies1, class Policies2>
inline bool cerle(const interval<T, Policies1> &x, const interval<T, Policies2> &y)
{
return x.upper() <= y.lower();
return x.upper() <= y.lower();
}
template<class T, class Policies> inline
bool cerle(const interval<T, Policies>& x, const T& y)
template <class T, class Policies> inline bool cerle(const interval<T, Policies> &x, const T &y)
{
return x.upper() <= y;
return x.upper() <= y;
}
template<class T, class Policies> inline
bool cerle(const T& x, const interval<T, Policies>& y)
template <class T, class Policies> inline bool cerle(const T &x, const interval<T, Policies> &y)
{
return x <= y.lower();
return x <= y.lower();
}
template<class T, class Policies1, class Policies2> inline
bool cergt(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
template <class T, class Policies1, class Policies2>
inline bool cergt(const interval<T, Policies1> &x, const interval<T, Policies2> &y)
{
return x.lower() > y.upper();
return x.lower() > y.upper();
}
template<class T, class Policies> inline
bool cergt(const interval<T, Policies>& x, const T& y)
template <class T, class Policies> inline bool cergt(const interval<T, Policies> &x, const T &y)
{
return x.lower() > y;
return x.lower() > y;
}
template<class T, class Policies> inline
bool cergt(const T& x, const interval<T, Policies>& y)
template <class T, class Policies> inline bool cergt(const T &x, const interval<T, Policies> &y)
{
return x > y.upper();
return x > y.upper();
}
template<class T, class Policies1, class Policies2> inline
bool cerge(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
template <class T, class Policies1, class Policies2>
inline bool cerge(const interval<T, Policies1> &x, const interval<T, Policies2> &y)
{
return x.lower() >= y.upper();
return x.lower() >= y.upper();
}
template<class T, class Policies> inline
bool cerge(const interval<T, Policies>& x, const T& y)
template <class T, class Policies> inline bool cerge(const interval<T, Policies> &x, const T &y)
{
return x.lower() >= y;
return x.lower() >= y;
}
template<class T, class Policies> inline
bool cerge(const T& x, const interval<T, Policies>& y)
template <class T, class Policies> inline bool cerge(const T &x, const interval<T, Policies> &y)
{
return x >= y.upper();
return x >= y.upper();
}
template<class T, class Policies1, class Policies2> inline
bool cereq(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
template <class T, class Policies1, class Policies2>
inline bool cereq(const interval<T, Policies1> &x, const interval<T, Policies2> &y)
{
return x.lower() == y.upper() && y.lower() == x.upper();
return x.lower() == y.upper() && y.lower() == x.upper();
}
template<class T, class Policies> inline
bool cereq(const interval<T, Policies>& x, const T& y)
template <class T, class Policies> inline bool cereq(const interval<T, Policies> &x, const T &y)
{
return x.lower() == y && x.upper() == y;
return x.lower() == y && x.upper() == y;
}
template<class T, class Policies> inline
bool cereq(const T& x, const interval<T, Policies>& y)
template <class T, class Policies> inline bool cereq(const T &x, const interval<T, Policies> &y)
{
return x == y.lower() && x == y.upper();
return x == y.lower() && x == y.upper();
}
template<class T, class Policies1, class Policies2> inline
bool cerne(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
template <class T, class Policies1, class Policies2>
inline bool cerne(const interval<T, Policies1> &x, const interval<T, Policies2> &y)
{
return x.upper() < y.lower() || y.upper() < x.lower();
return x.upper() < y.lower() || y.upper() < x.lower();
}
template<class T, class Policies> inline
bool cerne(const interval<T, Policies>& x, const T& y)
template <class T, class Policies> inline bool cerne(const interval<T, Policies> &x, const T &y)
{
return x.upper() < y || y < x.lower();
return x.upper() < y || y < x.lower();
}
template<class T, class Policies> inline
bool cerne(const T& x, const interval<T, Policies>& y)
template <class T, class Policies> inline bool cerne(const T &x, const interval<T, Policies> &y)
{
return x < y.lower() || y.upper() < x;
return x < y.lower() || y.upper() < x;
}
/*
* Possibly... comparisons
*/
template<class T, class Policies1, class Policies2> inline
bool poslt(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
template <class T, class Policies1, class Policies2>
inline bool poslt(const interval<T, Policies1> &x, const interval<T, Policies2> &y)
{
return x.lower() < y.upper();
return x.lower() < y.upper();
}
template<class T, class Policies> inline
bool poslt(const interval<T, Policies>& x, const T& y)
template <class T, class Policies> inline bool poslt(const interval<T, Policies> &x, const T &y)
{
return x.lower() < y;
return x.lower() < y;
}
template<class T, class Policies> inline
bool poslt(const T& x, const interval<T, Policies>& y)
template <class T, class Policies> inline bool poslt(const T &x, const interval<T, Policies> &y)
{
return x < y.upper();
return x < y.upper();
}
template<class T, class Policies1, class Policies2> inline
bool posle(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
template <class T, class Policies1, class Policies2>
inline bool posle(const interval<T, Policies1> &x, const interval<T, Policies2> &y)
{
return x.lower() <= y.upper();
return x.lower() <= y.upper();
}
template<class T, class Policies> inline
bool posle(const interval<T, Policies>& x, const T& y)
template <class T, class Policies> inline bool posle(const interval<T, Policies> &x, const T &y)
{
return x.lower() <= y;
return x.lower() <= y;
}
template<class T, class Policies> inline
bool posle(const T& x, const interval<T, Policies>& y)
template <class T, class Policies> inline bool posle(const T &x, const interval<T, Policies> &y)
{
return x <= y.upper();
return x <= y.upper();
}
template<class T, class Policies1, class Policies2> inline
bool posgt(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
template <class T, class Policies1, class Policies2>
inline bool posgt(const interval<T, Policies1> &x, const interval<T, Policies2> &y)
{
return x.upper() > y.lower();
return x.upper() > y.lower();
}
template<class T, class Policies> inline
bool posgt(const interval<T, Policies>& x, const T& y)
template <class T, class Policies> inline bool posgt(const interval<T, Policies> &x, const T &y)
{
return x.upper() > y;
return x.upper() > y;
}
template<class T, class Policies> inline
bool posgt(const T& x, const interval<T, Policies> & y)
template <class T, class Policies> inline bool posgt(const T &x, const interval<T, Policies> &y)
{
return x > y.lower();
return x > y.lower();
}
template<class T, class Policies1, class Policies2> inline
bool posge(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
template <class T, class Policies1, class Policies2>
inline bool posge(const interval<T, Policies1> &x, const interval<T, Policies2> &y)
{
return x.upper() >= y.lower();
return x.upper() >= y.lower();
}
template<class T, class Policies> inline
bool posge(const interval<T, Policies>& x, const T& y)
template <class T, class Policies> inline bool posge(const interval<T, Policies> &x, const T &y)
{
return x.upper() >= y;
return x.upper() >= y;
}
template<class T, class Policies> inline
bool posge(const T& x, const interval<T, Policies>& y)
template <class T, class Policies> inline bool posge(const T &x, const interval<T, Policies> &y)
{
return x >= y.lower();
return x >= y.lower();
}
template<class T, class Policies1, class Policies2> inline
bool poseq(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
template <class T, class Policies1, class Policies2>
inline bool poseq(const interval<T, Policies1> &x, const interval<T, Policies2> &y)
{
return x.upper() >= y.lower() && y.upper() >= x.lower();
return x.upper() >= y.lower() && y.upper() >= x.lower();
}
template<class T, class Policies> inline
bool poseq(const interval<T, Policies>& x, const T& y)
template <class T, class Policies> inline bool poseq(const interval<T, Policies> &x, const T &y)
{
return x.upper() >= y && y >= x.lower();
return x.upper() >= y && y >= x.lower();
}
template<class T, class Policies> inline
bool poseq(const T& x, const interval<T, Policies>& y)
template <class T, class Policies> inline bool poseq(const T &x, const interval<T, Policies> &y)
{
return x >= y.lower() && y.upper() >= x;
return x >= y.lower() && y.upper() >= x;
}
template<class T, class Policies1, class Policies2> inline
bool posne(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
template <class T, class Policies1, class Policies2>
inline bool posne(const interval<T, Policies1> &x, const interval<T, Policies2> &y)
{
return x.upper() != y.lower() || y.upper() != x.lower();
return x.upper() != y.lower() || y.upper() != x.lower();
}
template<class T, class Policies> inline
bool posne(const interval<T, Policies>& x, const T& y)
template <class T, class Policies> inline bool posne(const interval<T, Policies> &x, const T &y)
{
return x.upper() != y || y != x.lower();
return x.upper() != y || y != x.lower();
}
template<class T, class Policies> inline
bool posne(const T& x, const interval<T, Policies>& y)
template <class T, class Policies> inline bool posne(const T &x, const interval<T, Policies> &y)
{
return x != y.lower() || y.upper() != x;
return x != y.lower() || y.upper() != x;
}
} // namespace interval_lib
} // namespace numeric
} //namespace boost
} // namespace boost
#endif // BOOST_NUMERIC_INTERVAL_COMPARE_EXPLICIT_HPP

View File

@@ -19,98 +19,104 @@ namespace interval_lib {
namespace compare {
namespace lexicographic {
template<class T, class Policies1, class Policies2> inline
bool operator<(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
template <class T, class Policies1, class Policies2>
inline bool operator<(const interval<T, Policies1> &x, const interval<T, Policies2> &y)
{
if (detail::test_input(x, y)) throw comparison_error();
const T& xl = x.lower();
const T& yl = y.lower();
return xl < yl || (xl == yl && x.upper() < y.upper());
if (detail::test_input(x, y))
throw comparison_error();
const T &xl = x.lower();
const T &yl = y.lower();
return xl < yl || (xl == yl && x.upper() < y.upper());
}
template<class T, class Policies> inline
bool operator<(const interval<T, Policies>& x, const T& y)
template <class T, class Policies> inline bool operator<(const interval<T, Policies> &x, const T &y)
{
if (detail::test_input(x, y)) throw comparison_error();
return x.lower() < y;
if (detail::test_input(x, y))
throw comparison_error();
return x.lower() < y;
}
template<class T, class Policies1, class Policies2> inline
bool operator<=(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
template <class T, class Policies1, class Policies2>
inline bool operator<=(const interval<T, Policies1> &x, const interval<T, Policies2> &y)
{
if (detail::test_input(x, y)) throw comparison_error();
const T& xl = x.lower();
const T& yl = y.lower();
return xl < yl || (xl == yl && x.upper() <= y.upper());
if (detail::test_input(x, y))
throw comparison_error();
const T &xl = x.lower();
const T &yl = y.lower();
return xl < yl || (xl == yl && x.upper() <= y.upper());
}
template<class T, class Policies> inline
bool operator<=(const interval<T, Policies>& x, const T& y)
template <class T, class Policies> inline bool operator<=(const interval<T, Policies> &x, const T &y)
{
if (detail::test_input(x, y)) throw comparison_error();
const T& xl = x.lower();
return xl < y || (xl == y && x.upper() <= y);
if (detail::test_input(x, y))
throw comparison_error();
const T &xl = x.lower();
return xl < y || (xl == y && x.upper() <= y);
}
template<class T, class Policies1, class Policies2> inline
bool operator>(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
template <class T, class Policies1, class Policies2>
inline bool operator>(const interval<T, Policies1> &x, const interval<T, Policies2> &y)
{
if (detail::test_input(x, y)) throw comparison_error();
const T& xl = x.lower();
const T& yl = y.lower();
return xl > yl || (xl == yl && x.upper() > y.upper());
if (detail::test_input(x, y))
throw comparison_error();
const T &xl = x.lower();
const T &yl = y.lower();
return xl > yl || (xl == yl && x.upper() > y.upper());
}
template<class T, class Policies> inline
bool operator>(const interval<T, Policies>& x, const T& y)
template <class T, class Policies> inline bool operator>(const interval<T, Policies> &x, const T &y)
{
if (detail::test_input(x, y)) throw comparison_error();
const T& xl = x.lower();
return xl > y || (xl == y && x.upper() > y);
if (detail::test_input(x, y))
throw comparison_error();
const T &xl = x.lower();
return xl > y || (xl == y && x.upper() > y);
}
template<class T, class Policies1, class Policies2> inline
bool operator>=(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
template <class T, class Policies1, class Policies2>
inline bool operator>=(const interval<T, Policies1> &x, const interval<T, Policies2> &y)
{
if (detail::test_input(x, y)) throw comparison_error();
const T& xl = x.lower();
const T& yl = y.lower();
return xl > yl || (xl == yl && x.upper() >= y.upper());
if (detail::test_input(x, y))
throw comparison_error();
const T &xl = x.lower();
const T &yl = y.lower();
return xl > yl || (xl == yl && x.upper() >= y.upper());
}
template<class T, class Policies> inline
bool operator>=(const interval<T, Policies>& x, const T& y)
template <class T, class Policies> inline bool operator>=(const interval<T, Policies> &x, const T &y)
{
if (detail::test_input(x, y)) throw comparison_error();
return x.lower() >= y;
if (detail::test_input(x, y))
throw comparison_error();
return x.lower() >= y;
}
template<class T, class Policies1, class Policies2> inline
bool operator==(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
template <class T, class Policies1, class Policies2>
inline bool operator==(const interval<T, Policies1> &x, const interval<T, Policies2> &y)
{
if (detail::test_input(x, y)) throw comparison_error();
return x.lower() == y.lower() && x.upper() == y.upper();
if (detail::test_input(x, y))
throw comparison_error();
return x.lower() == y.lower() && x.upper() == y.upper();
}
template<class T, class Policies> inline
bool operator==(const interval<T, Policies>& x, const T& y)
template <class T, class Policies> inline bool operator==(const interval<T, Policies> &x, const T &y)
{
if (detail::test_input(x, y)) throw comparison_error();
return x.lower() == y && x.upper() == y;
if (detail::test_input(x, y))
throw comparison_error();
return x.lower() == y && x.upper() == y;
}
template<class T, class Policies1, class Policies2> inline
bool operator!=(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
template <class T, class Policies1, class Policies2>
inline bool operator!=(const interval<T, Policies1> &x, const interval<T, Policies2> &y)
{
if (detail::test_input(x, y)) throw comparison_error();
return x.lower() != y.lower() || x.upper() != y.upper();
if (detail::test_input(x, y))
throw comparison_error();
return x.lower() != y.lower() || x.upper() != y.upper();
}
template<class T, class Policies> inline
bool operator!=(const interval<T, Policies>& x, const T& y)
template <class T, class Policies> inline bool operator!=(const interval<T, Policies> &x, const T &y)
{
if (detail::test_input(x, y)) throw comparison_error();
return x.lower() != y || x.upper() != y;
if (detail::test_input(x, y))
throw comparison_error();
return x.lower() != y || x.upper() != y;
}
} // namespace lexicographic

View File

@@ -19,88 +19,94 @@ namespace interval_lib {
namespace compare {
namespace possible {
template<class T, class Policies1, class Policies2> inline
bool operator<(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
template <class T, class Policies1, class Policies2>
inline bool operator<(const interval<T, Policies1> &x, const interval<T, Policies2> &y)
{
if (detail::test_input(x, y)) throw comparison_error();
return x.lower() < y.upper();
if (detail::test_input(x, y))
throw comparison_error();
return x.lower() < y.upper();
}
template<class T, class Policies> inline
bool operator<(const interval<T, Policies>& x, const T& y)
template <class T, class Policies> inline bool operator<(const interval<T, Policies> &x, const T &y)
{
if (detail::test_input(x, y)) throw comparison_error();
return x.lower() < y;
if (detail::test_input(x, y))
throw comparison_error();
return x.lower() < y;
}
template<class T, class Policies1, class Policies2> inline
bool operator<=(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
template <class T, class Policies1, class Policies2>
inline bool operator<=(const interval<T, Policies1> &x, const interval<T, Policies2> &y)
{
if (detail::test_input(x, y)) throw comparison_error();
return x.lower() <= y.upper();
if (detail::test_input(x, y))
throw comparison_error();
return x.lower() <= y.upper();
}
template<class T, class Policies> inline
bool operator<=(const interval<T, Policies>& x, const T& y)
template <class T, class Policies> inline bool operator<=(const interval<T, Policies> &x, const T &y)
{
if (detail::test_input(x, y)) throw comparison_error();
return x.lower() <= y;
if (detail::test_input(x, y))
throw comparison_error();
return x.lower() <= y;
}
template<class T, class Policies1, class Policies2> inline
bool operator>(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
template <class T, class Policies1, class Policies2>
inline bool operator>(const interval<T, Policies1> &x, const interval<T, Policies2> &y)
{
if (detail::test_input(x, y)) throw comparison_error();
return x.upper() > y.lower();
if (detail::test_input(x, y))
throw comparison_error();
return x.upper() > y.lower();
}
template<class T, class Policies> inline
bool operator>(const interval<T, Policies>& x, const T& y)
template <class T, class Policies> inline bool operator>(const interval<T, Policies> &x, const T &y)
{
if (detail::test_input(x, y)) throw comparison_error();
return x.upper() > y;
if (detail::test_input(x, y))
throw comparison_error();
return x.upper() > y;
}
template<class T, class Policies1, class Policies2> inline
bool operator>=(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
template <class T, class Policies1, class Policies2>
inline bool operator>=(const interval<T, Policies1> &x, const interval<T, Policies2> &y)
{
if (detail::test_input(x, y)) throw comparison_error();
return x.upper() >= y.lower();
if (detail::test_input(x, y))
throw comparison_error();
return x.upper() >= y.lower();
}
template<class T, class Policies> inline
bool operator>=(const interval<T, Policies>& x, const T& y)
template <class T, class Policies> inline bool operator>=(const interval<T, Policies> &x, const T &y)
{
if (detail::test_input(x, y)) throw comparison_error();
return x.upper() >= y;
if (detail::test_input(x, y))
throw comparison_error();
return x.upper() >= y;
}
template<class T, class Policies1, class Policies2> inline
bool operator==(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
template <class T, class Policies1, class Policies2>
inline bool operator==(const interval<T, Policies1> &x, const interval<T, Policies2> &y)
{
if (detail::test_input(x, y)) throw comparison_error();
return x.lower() <= y.upper() && x.upper() >= y.lower();
if (detail::test_input(x, y))
throw comparison_error();
return x.lower() <= y.upper() && x.upper() >= y.lower();
}
template<class T, class Policies> inline
bool operator==(const interval<T, Policies>& x, const T& y)
template <class T, class Policies> inline bool operator==(const interval<T, Policies> &x, const T &y)
{
if (detail::test_input(x, y)) throw comparison_error();
return x.lower() <= y && x.upper() >= y;
if (detail::test_input(x, y))
throw comparison_error();
return x.lower() <= y && x.upper() >= y;
}
template<class T, class Policies1, class Policies2> inline
bool operator!=(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
template <class T, class Policies1, class Policies2>
inline bool operator!=(const interval<T, Policies1> &x, const interval<T, Policies2> &y)
{
if (detail::test_input(x, y)) throw comparison_error();
return x.lower() != y.upper() || x.upper() != y.lower();
if (detail::test_input(x, y))
throw comparison_error();
return x.lower() != y.upper() || x.upper() != y.lower();
}
template<class T, class Policies> inline
bool operator!=(const interval<T, Policies>& x, const T& y)
template <class T, class Policies> inline bool operator!=(const interval<T, Policies> &x, const T &y)
{
if (detail::test_input(x, y)) throw comparison_error();
return x.lower() != y || x.upper() != y;
if (detail::test_input(x, y))
throw comparison_error();
return x.lower() != y || x.upper() != y;
}
} // namespace possible

View File

@@ -20,76 +20,70 @@ namespace interval_lib {
namespace compare {
namespace set {
template<class T, class Policies1, class Policies2> inline
bool operator<(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
template <class T, class Policies1, class Policies2>
inline bool operator<(const interval<T, Policies1> &x, const interval<T, Policies2> &y)
{
return proper_subset(x, y);
return proper_subset(x, y);
}
template<class T, class Policies> inline
bool operator<(const interval<T, Policies>& x, const T& y)
template <class T, class Policies> inline bool operator<(const interval<T, Policies> &x, const T &y)
{
throw comparison_error();
throw comparison_error();
}
template<class T, class Policies1, class Policies2> inline
bool operator<=(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
template <class T, class Policies1, class Policies2>
inline bool operator<=(const interval<T, Policies1> &x, const interval<T, Policies2> &y)
{
return subset(x, y);
return subset(x, y);
}
template<class T, class Policies> inline
bool operator<=(const interval<T, Policies>& x, const T& y)
template <class T, class Policies> inline bool operator<=(const interval<T, Policies> &x, const T &y)
{
throw comparison_error();
throw comparison_error();
}
template<class T, class Policies1, class Policies2> inline
bool operator>(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
template <class T, class Policies1, class Policies2>
inline bool operator>(const interval<T, Policies1> &x, const interval<T, Policies2> &y)
{
return proper_subset(y, x);
return proper_subset(y, x);
}
template<class T, class Policies> inline
bool operator>(const interval<T, Policies>& x, const T& y)
template <class T, class Policies> inline bool operator>(const interval<T, Policies> &x, const T &y)
{
throw comparison_error();
throw comparison_error();
}
template<class T, class Policies1, class Policies2> inline
bool operator>=(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
template <class T, class Policies1, class Policies2>
inline bool operator>=(const interval<T, Policies1> &x, const interval<T, Policies2> &y)
{
return subset(y, x);
return subset(y, x);
}
template<class T, class Policies> inline
bool operator>=(const interval<T, Policies>& x, const T& y)
template <class T, class Policies> inline bool operator>=(const interval<T, Policies> &x, const T &y)
{
throw comparison_error();
throw comparison_error();
}
template<class T, class Policies1, class Policies2> inline
bool operator==(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
template <class T, class Policies1, class Policies2>
inline bool operator==(const interval<T, Policies1> &x, const interval<T, Policies2> &y)
{
return equal(y, x);
return equal(y, x);
}
template<class T, class Policies> inline
bool operator==(const interval<T, Policies>& x, const T& y)
template <class T, class Policies> inline bool operator==(const interval<T, Policies> &x, const T &y)
{
throw comparison_error();
throw comparison_error();
}
template<class T, class Policies1, class Policies2> inline
bool operator!=(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
template <class T, class Policies1, class Policies2>
inline bool operator!=(const interval<T, Policies1> &x, const interval<T, Policies2> &y)
{
return !equal(y, x);
return !equal(y, x);
}
template<class T, class Policies> inline
bool operator!=(const interval<T, Policies>& x, const T& y)
template <class T, class Policies> inline bool operator!=(const interval<T, Policies> &x, const T &y)
{
throw comparison_error();
throw comparison_error();
}
} // namespace set

View File

@@ -10,9 +10,9 @@
#ifndef BOOST_NUMERIC_INTERVAL_COMPARE_TRIBOOL_HPP
#define BOOST_NUMERIC_INTERVAL_COMPARE_TRIBOOL_HPP
#include <boost/logic/tribool.hpp>
#include <boost/numeric/interval/detail/interval_prototype.hpp>
#include <boost/numeric/interval/detail/test_input.hpp>
#include <boost/logic/tribool.hpp>
namespace boost {
namespace numeric {
@@ -20,112 +20,142 @@ namespace interval_lib {
namespace compare {
namespace tribool {
template<class T, class Policies1, class Policies2> inline
logic::tribool operator<(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
template <class T, class Policies1, class Policies2>
inline logic::tribool operator<(const interval<T, Policies1> &x, const interval<T, Policies2> &y)
{
if (detail::test_input(x, y)) throw comparison_error();
if (x.upper() < y.lower()) return true;
if (x.lower() >= y.upper()) return false;
return logic::indeterminate;
if (detail::test_input(x, y))
throw comparison_error();
if (x.upper() < y.lower())
return true;
if (x.lower() >= y.upper())
return false;
return logic::indeterminate;
}
template<class T, class Policies> inline
logic::tribool operator<(const interval<T, Policies>& x, const T& y)
template <class T, class Policies> inline logic::tribool operator<(const interval<T, Policies> &x, const T &y)
{
if (detail::test_input(x, y)) throw comparison_error();
if (x.upper() < y) return true;
if (x.lower() >= y) return false;
return logic::indeterminate;
if (detail::test_input(x, y))
throw comparison_error();
if (x.upper() < y)
return true;
if (x.lower() >= y)
return false;
return logic::indeterminate;
}
template<class T, class Policies1, class Policies2> inline
logic::tribool operator<=(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
template <class T, class Policies1, class Policies2>
inline logic::tribool operator<=(const interval<T, Policies1> &x, const interval<T, Policies2> &y)
{
if (detail::test_input(x, y)) throw comparison_error();
if (x.upper() <= y.lower()) return true;
if (x.lower() > y.upper()) return false;
return logic::indeterminate;
if (detail::test_input(x, y))
throw comparison_error();
if (x.upper() <= y.lower())
return true;
if (x.lower() > y.upper())
return false;
return logic::indeterminate;
}
template<class T, class Policies> inline
logic::tribool operator<=(const interval<T, Policies>& x, const T& y)
template <class T, class Policies> inline logic::tribool operator<=(const interval<T, Policies> &x, const T &y)
{
if (detail::test_input(x, y)) throw comparison_error();
if (x.upper() <= y) return true;
if (x.lower() > y) return false;
return logic::indeterminate;
if (detail::test_input(x, y))
throw comparison_error();
if (x.upper() <= y)
return true;
if (x.lower() > y)
return false;
return logic::indeterminate;
}
template<class T, class Policies1, class Policies2> inline
logic::tribool operator>(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
template <class T, class Policies1, class Policies2>
inline logic::tribool operator>(const interval<T, Policies1> &x, const interval<T, Policies2> &y)
{
if (detail::test_input(x, y)) throw comparison_error();
if (x.lower() > y.upper()) return true;
if (x.upper() <= y.lower()) return false;
return logic::indeterminate;
if (detail::test_input(x, y))
throw comparison_error();
if (x.lower() > y.upper())
return true;
if (x.upper() <= y.lower())
return false;
return logic::indeterminate;
}
template<class T, class Policies> inline
logic::tribool operator>(const interval<T, Policies>& x, const T& y)
template <class T, class Policies> inline logic::tribool operator>(const interval<T, Policies> &x, const T &y)
{
if (detail::test_input(x, y)) throw comparison_error();
if (x.lower() > y) return true;
if (x.upper() <= y) return false;
return logic::indeterminate;
if (detail::test_input(x, y))
throw comparison_error();
if (x.lower() > y)
return true;
if (x.upper() <= y)
return false;
return logic::indeterminate;
}
template<class T, class Policies1, class Policies2> inline
logic::tribool operator>=(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
template <class T, class Policies1, class Policies2>
inline logic::tribool operator>=(const interval<T, Policies1> &x, const interval<T, Policies2> &y)
{
if (detail::test_input(x, y)) throw comparison_error();
if (x.lower() >= y.upper()) return true;
if (x.upper() < y.lower()) return false;
return logic::indeterminate;
if (detail::test_input(x, y))
throw comparison_error();
if (x.lower() >= y.upper())
return true;
if (x.upper() < y.lower())
return false;
return logic::indeterminate;
}
template<class T, class Policies> inline
logic::tribool operator>=(const interval<T, Policies>& x, const T& y)
template <class T, class Policies> inline logic::tribool operator>=(const interval<T, Policies> &x, const T &y)
{
if (detail::test_input(x, y)) throw comparison_error();
if (x.lower() >= y) return true;
if (x.upper() < y) return false;
return logic::indeterminate;
if (detail::test_input(x, y))
throw comparison_error();
if (x.lower() >= y)
return true;
if (x.upper() < y)
return false;
return logic::indeterminate;
}
template<class T, class Policies1, class Policies2> inline
logic::tribool operator==(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
template <class T, class Policies1, class Policies2>
inline logic::tribool operator==(const interval<T, Policies1> &x, const interval<T, Policies2> &y)
{
if (detail::test_input(x, y)) throw comparison_error();
if (x.upper() == y.lower() && x.lower() == y.upper()) return true;
if (x.upper() < y.lower() || x.lower() > y.upper()) return false;
return logic::indeterminate;
if (detail::test_input(x, y))
throw comparison_error();
if (x.upper() == y.lower() && x.lower() == y.upper())
return true;
if (x.upper() < y.lower() || x.lower() > y.upper())
return false;
return logic::indeterminate;
}
template<class T, class Policies> inline
logic::tribool operator==(const interval<T, Policies>& x, const T& y)
template <class T, class Policies> inline logic::tribool operator==(const interval<T, Policies> &x, const T &y)
{
if (detail::test_input(x, y)) throw comparison_error();
if (x.upper() == y && x.lower() == y) return true;
if (x.upper() < y || x.lower() > y) return false;
return logic::indeterminate;
if (detail::test_input(x, y))
throw comparison_error();
if (x.upper() == y && x.lower() == y)
return true;
if (x.upper() < y || x.lower() > y)
return false;
return logic::indeterminate;
}
template<class T, class Policies1, class Policies2> inline
logic::tribool operator!=(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
template <class T, class Policies1, class Policies2>
inline logic::tribool operator!=(const interval<T, Policies1> &x, const interval<T, Policies2> &y)
{
if (detail::test_input(x, y)) throw comparison_error();
if (x.upper() < y.lower() || x.lower() > y.upper()) return true;
if (x.upper() == y.lower() && x.lower() == y.upper()) return false;
return logic::indeterminate;
if (detail::test_input(x, y))
throw comparison_error();
if (x.upper() < y.lower() || x.lower() > y.upper())
return true;
if (x.upper() == y.lower() && x.lower() == y.upper())
return false;
return logic::indeterminate;
}
template<class T, class Policies> inline
logic::tribool operator!=(const interval<T, Policies>& x, const T& y)
template <class T, class Policies> inline logic::tribool operator!=(const interval<T, Policies> &x, const T &y)
{
if (detail::test_input(x, y)) throw comparison_error();
if (x.upper() < y || x.lower() > y) return true;
if (x.upper() == y && x.lower() == y) return false;
return logic::indeterminate;
if (detail::test_input(x, y))
throw comparison_error();
if (x.upper() < y || x.lower() > y)
return true;
if (x.upper() == y && x.lower() == y)
return false;
return logic::indeterminate;
}
} // namespace tribool

View File

@@ -19,63 +19,57 @@ namespace constants {
// Decimal representations wouldn't do it since the standard doesn't
// specify the rounding (even nearest) that should be used.
static const float pi_f_l = 13176794.0f/(1<<22);
static const float pi_f_u = 13176795.0f/(1<<22);
static const double pi_d_l = (3373259426.0 + 273688.0 / (1<<21)) / (1<<30);
static const double pi_d_u = (3373259426.0 + 273689.0 / (1<<21)) / (1<<30);
static const float pi_f_l = 13176794.0f / (1 << 22);
static const float pi_f_u = 13176795.0f / (1 << 22);
static const double pi_d_l = (3373259426.0 + 273688.0 / (1 << 21)) / (1 << 30);
static const double pi_d_u = (3373259426.0 + 273689.0 / (1 << 21)) / (1 << 30);
template<class T> inline T pi_lower() { return 3; }
template<class T> inline T pi_upper() { return 4; }
template<class T> inline T pi_half_lower() { return 1; }
template<class T> inline T pi_half_upper() { return 2; }
template<class T> inline T pi_twice_lower() { return 6; }
template<class T> inline T pi_twice_upper() { return 7; }
template <class T> inline T pi_lower() { return 3; }
template <class T> inline T pi_upper() { return 4; }
template <class T> inline T pi_half_lower() { return 1; }
template <class T> inline T pi_half_upper() { return 2; }
template <class T> inline T pi_twice_lower() { return 6; }
template <class T> inline T pi_twice_upper() { return 7; }
template<> inline float pi_lower<float>() { return pi_f_l; }
template<> inline float pi_upper<float>() { return pi_f_u; }
template<> inline float pi_half_lower<float>() { return pi_f_l / 2; }
template<> inline float pi_half_upper<float>() { return pi_f_u / 2; }
template<> inline float pi_twice_lower<float>() { return pi_f_l * 2; }
template<> inline float pi_twice_upper<float>() { return pi_f_u * 2; }
template <> inline float pi_lower<float>() { return pi_f_l; }
template <> inline float pi_upper<float>() { return pi_f_u; }
template <> inline float pi_half_lower<float>() { return pi_f_l / 2; }
template <> inline float pi_half_upper<float>() { return pi_f_u / 2; }
template <> inline float pi_twice_lower<float>() { return pi_f_l * 2; }
template <> inline float pi_twice_upper<float>() { return pi_f_u * 2; }
template<> inline double pi_lower<double>() { return pi_d_l; }
template<> inline double pi_upper<double>() { return pi_d_u; }
template<> inline double pi_half_lower<double>() { return pi_d_l / 2; }
template<> inline double pi_half_upper<double>() { return pi_d_u / 2; }
template<> inline double pi_twice_lower<double>() { return pi_d_l * 2; }
template<> inline double pi_twice_upper<double>() { return pi_d_u * 2; }
template <> inline double pi_lower<double>() { return pi_d_l; }
template <> inline double pi_upper<double>() { return pi_d_u; }
template <> inline double pi_half_lower<double>() { return pi_d_l / 2; }
template <> inline double pi_half_upper<double>() { return pi_d_u / 2; }
template <> inline double pi_twice_lower<double>() { return pi_d_l * 2; }
template <> inline double pi_twice_upper<double>() { return pi_d_u * 2; }
template<> inline long double pi_lower<long double>() { return pi_d_l; }
template<> inline long double pi_upper<long double>() { return pi_d_u; }
template<> inline long double pi_half_lower<long double>() { return pi_d_l / 2; }
template<> inline long double pi_half_upper<long double>() { return pi_d_u / 2; }
template<> inline long double pi_twice_lower<long double>() { return pi_d_l * 2; }
template<> inline long double pi_twice_upper<long double>() { return pi_d_u * 2; }
template <> inline long double pi_lower<long double>() { return pi_d_l; }
template <> inline long double pi_upper<long double>() { return pi_d_u; }
template <> inline long double pi_half_lower<long double>() { return pi_d_l / 2; }
template <> inline long double pi_half_upper<long double>() { return pi_d_u / 2; }
template <> inline long double pi_twice_lower<long double>() { return pi_d_l * 2; }
template <> inline long double pi_twice_upper<long double>() { return pi_d_u * 2; }
} // namespace constants
template<class I> inline
I pi()
template <class I> inline I pi()
{
typedef typename I::base_type T;
return I(constants::pi_lower<T>(),
constants::pi_upper<T>(), true);
typedef typename I::base_type T;
return I(constants::pi_lower<T>(), constants::pi_upper<T>(), true);
}
template<class I> inline
I pi_half()
template <class I> inline I pi_half()
{
typedef typename I::base_type T;
return I(constants::pi_half_lower<T>(),
constants::pi_half_upper<T>(), true);
typedef typename I::base_type T;
return I(constants::pi_half_lower<T>(), constants::pi_half_upper<T>(), true);
}
template<class I> inline
I pi_twice()
template <class I> inline I pi_twice()
{
typedef typename I::base_type T;
return I(constants::pi_twice_lower<T>(),
constants::pi_twice_upper<T>(), true);
typedef typename I::base_type T;
return I(constants::pi_twice_lower<T>(), constants::pi_twice_upper<T>(), true);
}
} // namespace interval_lib

View File

@@ -23,84 +23,81 @@ namespace numeric {
namespace interval_lib {
namespace detail {
#if defined(__GNUC__ )
typedef union {
#if defined(__GNUC__)
typedef union
{
::boost::long_long_type imode;
double dmode;
} rounding_mode_struct;
double dmode;
} rounding_mode_struct;
// set bits 59-58 (DYN),
// clear all exception bits and disable overflow (51) and inexact exceptions (62)
static const rounding_mode_struct mode_upward = { 0x4C08000000000000LL };
static const rounding_mode_struct mode_downward = { 0x4408000000000000LL };
static const rounding_mode_struct mode_to_nearest = { 0x4808000000000000LL };
static const rounding_mode_struct mode_toward_zero = { 0x4008000000000000LL };
// set bits 59-58 (DYN),
// clear all exception bits and disable overflow (51) and inexact exceptions (62)
static const rounding_mode_struct mode_upward = {0x4C08000000000000LL};
static const rounding_mode_struct mode_downward = {0x4408000000000000LL};
static const rounding_mode_struct mode_to_nearest = {0x4808000000000000LL};
static const rounding_mode_struct mode_toward_zero = {0x4008000000000000LL};
struct alpha_rounding_control
{
struct alpha_rounding_control
{
typedef double rounding_mode;
static void set_rounding_mode(const rounding_mode mode)
{ __asm__ __volatile__ ("mt_fpcr %0" : : "f"(mode)); }
static void set_rounding_mode(const rounding_mode mode) { __asm__ __volatile__("mt_fpcr %0" : : "f"(mode)); }
static void get_rounding_mode(rounding_mode& mode)
{ __asm__ __volatile__ ("mf_fpcr %0" : "=f"(mode)); }
static void get_rounding_mode(rounding_mode &mode) { __asm__ __volatile__("mf_fpcr %0" : "=f"(mode)); }
static void downward() { set_rounding_mode(mode_downward.dmode); }
static void upward() { set_rounding_mode(mode_upward.dmode); }
static void to_nearest() { set_rounding_mode(mode_to_nearest.dmode); }
static void downward() { set_rounding_mode(mode_downward.dmode); }
static void upward() { set_rounding_mode(mode_upward.dmode); }
static void to_nearest() { set_rounding_mode(mode_to_nearest.dmode); }
static void toward_zero() { set_rounding_mode(mode_toward_zero.dmode); }
};
};
#elif defined(__digital__) || defined(__DECCXX)
#if defined(__DECCXX) && !(defined(__FLT_ROUNDS) && __FLT_ROUNDS == -1)
#error Dynamic rounding mode not enabled. See cxx man page for details.
#endif
struct alpha_rounding_control
{
struct alpha_rounding_control
{
typedef unsigned int rounding_mode;
static void set_rounding_mode(const rounding_mode& mode) { write_rnd(mode); }
static void get_rounding_mode(rounding_mode& mode) { mode = read_rnd(); }
static void set_rounding_mode(const rounding_mode &mode) { write_rnd(mode); }
static void get_rounding_mode(rounding_mode &mode) { mode = read_rnd(); }
static void downward() { set_rounding_mode(FP_RND_RM); }
static void upward() { set_rounding_mode(FP_RND_RP); }
static void to_nearest() { set_rounding_mode(FP_RND_RN); }
static void downward() { set_rounding_mode(FP_RND_RM); }
static void upward() { set_rounding_mode(FP_RND_RP); }
static void to_nearest() { set_rounding_mode(FP_RND_RN); }
static void toward_zero() { set_rounding_mode(FP_RND_RZ); }
};
};
#endif
} // namespace detail
extern "C" {
float rintf(float);
double rint(double);
long double rintl(long double);
extern "C"
{
float rintf(float);
double rint(double);
long double rintl(long double);
}
template<>
struct rounding_control<float>:
detail::alpha_rounding_control
template <> struct rounding_control<float> : detail::alpha_rounding_control
{
static float force_rounding(const float r)
{ volatile float _r = r; return _r; }
static float to_int(const float& x) { return rintf(x); }
static float force_rounding(const float r)
{
volatile float _r = r;
return _r;
}
static float to_int(const float &x) { return rintf(x); }
};
template<>
struct rounding_control<double>:
detail::alpha_rounding_control
template <> struct rounding_control<double> : detail::alpha_rounding_control
{
static const double & force_rounding(const double& r) { return r; }
static double to_int(const double& r) { return rint(r); }
static const double &force_rounding(const double &r) { return r; }
static double to_int(const double &r) { return rint(r); }
};
template<>
struct rounding_control<long double>:
detail::alpha_rounding_control
template <> struct rounding_control<long double> : detail::alpha_rounding_control
{
static const long double & force_rounding(const long double& r) { return r; }
static long double to_int(const long double& r) { return rintl(r); }
static const long double &force_rounding(const long double &r) { return r; }
static long double to_int(const long double &r) { return rintl(r); }
};
} // namespace interval_lib

View File

@@ -12,14 +12,14 @@
#define BOOST_NUMERIC_INTERVAL_DETAIL_BCC_ROUNDING_CONTROL_HPP
#ifndef __BORLANDC__
# error This header is only intended for Borland C++.
#error This header is only intended for Borland C++.
#endif
#ifndef _M_IX86
# error This header only works on x86 CPUs.
#error This header only works on x86 CPUs.
#endif
#include <float.h> // Borland C++ rounding control
#include <float.h> // Borland C++ rounding control
namespace boost {
namespace numeric {
@@ -27,26 +27,31 @@ namespace interval_lib {
namespace detail {
#ifndef BOOST_NUMERIC_INTERVAL_KEEP_EXCEPTIONS_FOR_BCC
extern "C" { unsigned int _RTLENTRY _fm_init(void); }
extern "C"
{
unsigned int _RTLENTRY _fm_init(void);
}
struct borland_workaround {
borland_workaround() { _fm_init(); }
struct borland_workaround
{
borland_workaround() { _fm_init(); }
};
static borland_workaround borland_workaround_exec;
#endif // BOOST_NUMERIC_INTERVAL_KEEP_EXCEPTIONS_FOR_BCC
__inline double rint(double)
{ __emit__(0xD9); __emit__(0xFC); /* asm FRNDINT */ }
{
__emit__(0xD9);
__emit__(0xFC); /* asm FRNDINT */
}
struct x86_rounding
{
typedef unsigned int rounding_mode;
static void get_rounding_mode(rounding_mode& mode)
{ mode = _control87(0, 0); }
static void set_rounding_mode(const rounding_mode mode)
{ _control87(mode, 0xffff); }
static double to_int(const double& x) { return rint(x); }
typedef unsigned int rounding_mode;
static void get_rounding_mode(rounding_mode &mode) { mode = _control87(0, 0); }
static void set_rounding_mode(const rounding_mode mode) { _control87(mode, 0xffff); }
static double to_int(const double &x) { return rint(x); }
};
} // namespace detail

View File

@@ -13,36 +13,37 @@
#include <boost/config.hpp>
#if defined(__GLIBC__) && (defined(__USE_MISC) || defined(__USE_XOPEN_EXTENDED) || defined(__USE_ISOC99)) && !defined(__ICC)
# define BOOST_HAS_INV_HYPERBOLIC
#if defined(__GLIBC__) && (defined(__USE_MISC) || defined(__USE_XOPEN_EXTENDED) || defined(__USE_ISOC99)) \
&& !defined(__ICC)
#define BOOST_HAS_INV_HYPERBOLIC
#endif
#ifdef BOOST_NO_STDC_NAMESPACE
# define BOOST_NUMERIC_INTERVAL_using_math(a) using ::a
# ifdef BOOST_HAS_INV_HYPERBOLIC
# define BOOST_NUMERIC_INTERVAL_using_ahyp(a) using ::a
# endif
#define BOOST_NUMERIC_INTERVAL_using_math(a) using ::a
#ifdef BOOST_HAS_INV_HYPERBOLIC
#define BOOST_NUMERIC_INTERVAL_using_ahyp(a) using ::a
#endif
#else
# define BOOST_NUMERIC_INTERVAL_using_math(a) using std::a
# if defined(BOOST_HAS_INV_HYPERBOLIC)
# if defined(__GLIBCPP__) || defined(__GLIBCXX__)
# define BOOST_NUMERIC_INTERVAL_using_ahyp(a) using ::a
# else
# define BOOST_NUMERIC_INTERVAL_using_ahyp(a) using std::a
# endif
# endif
#define BOOST_NUMERIC_INTERVAL_using_math(a) using std::a
#if defined(BOOST_HAS_INV_HYPERBOLIC)
#if defined(__GLIBCPP__) || defined(__GLIBCXX__)
#define BOOST_NUMERIC_INTERVAL_using_ahyp(a) using ::a
#else
#define BOOST_NUMERIC_INTERVAL_using_ahyp(a) using std::a
#endif
#endif
#endif
#if defined(__COMO__) || defined(BOOST_INTEL)
# define BOOST_NUMERIC_INTERVAL_using_max(a) using std::a
#define BOOST_NUMERIC_INTERVAL_using_max(a) using std::a
#elif defined(BOOST_NO_STDC_NAMESPACE)
# define BOOST_NUMERIC_INTERVAL_using_max(a) using ::a
#define BOOST_NUMERIC_INTERVAL_using_max(a) using ::a
#else
# define BOOST_NUMERIC_INTERVAL_using_max(a) using std::a
#define BOOST_NUMERIC_INTERVAL_using_max(a) using std::a
#endif
#ifndef BOOST_NUMERIC_INTERVAL_using_ahyp
# define BOOST_NUMERIC_INTERVAL_using_ahyp(a)
#define BOOST_NUMERIC_INTERVAL_using_ahyp(a)
#endif
#if defined(__GNUC__) && (__GNUC__ <= 2)
@@ -51,27 +52,27 @@
#include <boost/config/no_tr1/cmath.hpp>
namespace boost {
namespace numeric {
using std::min;
using std::max;
using std::sqrt;
using std::exp;
using std::log;
using std::cos;
using std::tan;
using std::asin;
using std::acos;
using std::atan;
using std::ceil;
using std::floor;
using std::sinh;
using std::cosh;
using std::tanh;
# undef BOOST_NUMERIC_INTERVAL_using_max
# undef BOOST_NUMERIC_INTERVAL_using_math
# define BOOST_NUMERIC_INTERVAL_using_max(a)
# define BOOST_NUMERIC_INTERVAL_using_math(a)
# undef BOOST_NUMERIC_INTERVAL_using_ahyp
# define BOOST_NUMERIC_INTERVAL_using_ahyp(a)
using std::acos;
using std::asin;
using std::atan;
using std::ceil;
using std::cos;
using std::cosh;
using std::exp;
using std::floor;
using std::log;
using std::max;
using std::min;
using std::sinh;
using std::sqrt;
using std::tan;
using std::tanh;
#undef BOOST_NUMERIC_INTERVAL_using_max
#undef BOOST_NUMERIC_INTERVAL_using_math
#define BOOST_NUMERIC_INTERVAL_using_max(a)
#define BOOST_NUMERIC_INTERVAL_using_math(a)
#undef BOOST_NUMERIC_INTERVAL_using_ahyp
#define BOOST_NUMERIC_INTERVAL_using_ahyp(a)
} // namespace numeric
} // namespace boost
#endif

View File

@@ -18,25 +18,28 @@ namespace numeric {
namespace interval_lib {
namespace detail {
struct c99_rounding_control: c99_rounding
struct c99_rounding_control : c99_rounding
{
template<class T>
static T force_rounding(const T& r) { volatile T r_ = r; return r_; }
template <class T> static T force_rounding(const T &r)
{
volatile T r_ = r;
return r_;
}
};
} // namespace detail
template<>
struct rounding_control<float>:
detail::c99_rounding_control { };
template <> struct rounding_control<float> : detail::c99_rounding_control
{
};
template<>
struct rounding_control<double>:
detail::c99_rounding_control { };
template <> struct rounding_control<double> : detail::c99_rounding_control
{
};
template<>
struct rounding_control<long double>:
detail::c99_rounding_control { };
template <> struct rounding_control<long double> : detail::c99_rounding_control
{
};
} // namespace interval_lib
} // namespace numeric

View File

@@ -11,28 +11,30 @@
#ifndef BOOST_NUMERIC_INTERVAL_DETAIL_C99SUB_ROUNDING_CONTROL_HPP
#define BOOST_NUMERIC_INTERVAL_DETAIL_C99SUB_ROUNDING_CONTROL_HPP
#include <fenv.h> // ISO C 99 rounding mode control
#include <fenv.h> // ISO C 99 rounding mode control
namespace boost {
namespace numeric {
namespace interval_lib {
namespace detail {
extern "C" { double rint(double); }
extern "C"
{
double rint(double);
}
struct c99_rounding
{
typedef int rounding_mode;
typedef int rounding_mode;
static void set_rounding_mode(const rounding_mode mode) { fesetround(mode); }
static void get_rounding_mode(rounding_mode &mode) { mode = fegetround(); }
static void downward() { set_rounding_mode(FE_DOWNWARD); }
static void upward() { set_rounding_mode(FE_UPWARD); }
static void to_nearest() { set_rounding_mode(FE_TONEAREST); }
static void toward_zero() { set_rounding_mode(FE_TOWARDZERO); }
static void set_rounding_mode(const rounding_mode mode) { fesetround(mode); }
static void get_rounding_mode(rounding_mode &mode) { mode = fegetround(); }
static void downward() { set_rounding_mode(FE_DOWNWARD); }
static void upward() { set_rounding_mode(FE_UPWARD); }
static void to_nearest() { set_rounding_mode(FE_TONEAREST); }
static void toward_zero() { set_rounding_mode(FE_TOWARDZERO); }
template<class T>
static T to_int(const T& r) { return rint(r); }
template <class T> static T to_int(const T &r) { return rint(r); }
};
} // namespace detail

View File

@@ -10,180 +10,184 @@
#ifndef BOOST_NUMERIC_INTERVAL_DETAIL_DIVISION_HPP
#define BOOST_NUMERIC_INTERVAL_DETAIL_DIVISION_HPP
#include <boost/numeric/interval/detail/interval_prototype.hpp>
#include <algorithm>
#include <boost/numeric/interval/detail/bugs.hpp>
#include <boost/numeric/interval/detail/interval_prototype.hpp>
#include <boost/numeric/interval/detail/test_input.hpp>
#include <boost/numeric/interval/rounded_arith.hpp>
#include <algorithm>
namespace boost {
namespace numeric {
namespace interval_lib {
namespace detail {
template<class T, class Policies> inline
interval<T, Policies> div_non_zero(const interval<T, Policies>& x,
const interval<T, Policies>& y)
template <class T, class Policies>
inline interval<T, Policies> div_non_zero(const interval<T, Policies> &x, const interval<T, Policies> &y)
{
// assert(!in_zero(y));
typename Policies::rounding rnd;
typedef interval<T, Policies> I;
const T& xl = x.lower();
const T& xu = x.upper();
const T& yl = y.lower();
const T& yu = y.upper();
if (::boost::numeric::interval_lib::user::is_neg(xu))
if (::boost::numeric::interval_lib::user::is_neg(yu))
return I(rnd.div_down(xu, yl), rnd.div_up(xl, yu), true);
// assert(!in_zero(y));
typename Policies::rounding rnd;
typedef interval<T, Policies> I;
const T &xl = x.lower();
const T &xu = x.upper();
const T &yl = y.lower();
const T &yu = y.upper();
if (::boost::numeric::interval_lib::user::is_neg(xu))
if (::boost::numeric::interval_lib::user::is_neg(yu))
return I(rnd.div_down(xu, yl), rnd.div_up(xl, yu), true);
else
return I(rnd.div_down(xl, yl), rnd.div_up(xu, yu), true);
else if (::boost::numeric::interval_lib::user::is_neg(xl))
if (::boost::numeric::interval_lib::user::is_neg(yu))
return I(rnd.div_down(xu, yu), rnd.div_up(xl, yu), true);
else
return I(rnd.div_down(xl, yl), rnd.div_up(xu, yl), true);
else if (::boost::numeric::interval_lib::user::is_neg(yu))
return I(rnd.div_down(xu, yu), rnd.div_up(xl, yl), true);
else
return I(rnd.div_down(xl, yl), rnd.div_up(xu, yu), true);
else if (::boost::numeric::interval_lib::user::is_neg(xl))
if (::boost::numeric::interval_lib::user::is_neg(yu))
return I(rnd.div_down(xu, yu), rnd.div_up(xl, yu), true);
return I(rnd.div_down(xl, yu), rnd.div_up(xu, yl), true);
}
template <class T, class Policies> inline interval<T, Policies> div_non_zero(const T &x, const interval<T, Policies> &y)
{
// assert(!in_zero(y));
typename Policies::rounding rnd;
typedef interval<T, Policies> I;
const T &yl = y.lower();
const T &yu = y.upper();
if (::boost::numeric::interval_lib::user::is_neg(x))
return I(rnd.div_down(x, yl), rnd.div_up(x, yu), true);
else
return I(rnd.div_down(xl, yl), rnd.div_up(xu, yl), true);
else
if (::boost::numeric::interval_lib::user::is_neg(yu))
return I(rnd.div_down(xu, yu), rnd.div_up(xl, yl), true);
return I(rnd.div_down(x, yu), rnd.div_up(x, yl), true);
}
template <class T, class Policies>
inline interval<T, Policies> div_positive(const interval<T, Policies> &x, const T &yu)
{
// assert(::boost::numeric::interval_lib::user::is_pos(yu));
if (::boost::numeric::interval_lib::user::is_zero(x.lower())
&& ::boost::numeric::interval_lib::user::is_zero(x.upper()))
return x;
typename Policies::rounding rnd;
typedef interval<T, Policies> I;
const T &xl = x.lower();
const T &xu = x.upper();
typedef typename Policies::checking checking;
if (::boost::numeric::interval_lib::user::is_neg(xu))
return I(checking::neg_inf(), rnd.div_up(xu, yu), true);
else if (::boost::numeric::interval_lib::user::is_neg(xl))
return I(checking::neg_inf(), checking::pos_inf(), true);
else
return I(rnd.div_down(xl, yu), rnd.div_up(xu, yl), true);
return I(rnd.div_down(xl, yu), checking::pos_inf(), true);
}
template<class T, class Policies> inline
interval<T, Policies> div_non_zero(const T& x, const interval<T, Policies>& y)
template <class T, class Policies> inline interval<T, Policies> div_positive(const T &x, const T &yu)
{
// assert(!in_zero(y));
typename Policies::rounding rnd;
typedef interval<T, Policies> I;
const T& yl = y.lower();
const T& yu = y.upper();
if (::boost::numeric::interval_lib::user::is_neg(x))
return I(rnd.div_down(x, yl), rnd.div_up(x, yu), true);
else
return I(rnd.div_down(x, yu), rnd.div_up(x, yl), true);
// assert(::boost::numeric::interval_lib::user::is_pos(yu));
typedef interval<T, Policies> I;
if (::boost::numeric::interval_lib::user::is_zero(x))
return I(static_cast<T>(0), static_cast<T>(0), true);
typename Policies::rounding rnd;
typedef typename Policies::checking checking;
if (::boost::numeric::interval_lib::user::is_neg(x))
return I(checking::neg_inf(), rnd.div_up(x, yu), true);
else
return I(rnd.div_down(x, yu), checking::pos_inf(), true);
}
template<class T, class Policies> inline
interval<T, Policies> div_positive(const interval<T, Policies>& x, const T& yu)
template <class T, class Policies>
inline interval<T, Policies> div_negative(const interval<T, Policies> &x, const T &yl)
{
// assert(::boost::numeric::interval_lib::user::is_pos(yu));
if (::boost::numeric::interval_lib::user::is_zero(x.lower()) &&
::boost::numeric::interval_lib::user::is_zero(x.upper()))
return x;
typename Policies::rounding rnd;
typedef interval<T, Policies> I;
const T& xl = x.lower();
const T& xu = x.upper();
typedef typename Policies::checking checking;
if (::boost::numeric::interval_lib::user::is_neg(xu))
return I(checking::neg_inf(), rnd.div_up(xu, yu), true);
else if (::boost::numeric::interval_lib::user::is_neg(xl))
return I(checking::neg_inf(), checking::pos_inf(), true);
else
return I(rnd.div_down(xl, yu), checking::pos_inf(), true);
// assert(::boost::numeric::interval_lib::user::is_neg(yl));
if (::boost::numeric::interval_lib::user::is_zero(x.lower())
&& ::boost::numeric::interval_lib::user::is_zero(x.upper()))
return x;
typename Policies::rounding rnd;
typedef interval<T, Policies> I;
const T &xl = x.lower();
const T &xu = x.upper();
typedef typename Policies::checking checking;
if (::boost::numeric::interval_lib::user::is_neg(xu))
return I(rnd.div_down(xu, yl), checking::pos_inf(), true);
else if (::boost::numeric::interval_lib::user::is_neg(xl))
return I(checking::neg_inf(), checking::pos_inf(), true);
else
return I(checking::neg_inf(), rnd.div_up(xl, yl), true);
}
template<class T, class Policies> inline
interval<T, Policies> div_positive(const T& x, const T& yu)
template <class T, class Policies> inline interval<T, Policies> div_negative(const T &x, const T &yl)
{
// assert(::boost::numeric::interval_lib::user::is_pos(yu));
typedef interval<T, Policies> I;
if (::boost::numeric::interval_lib::user::is_zero(x))
return I(static_cast<T>(0), static_cast<T>(0), true);
typename Policies::rounding rnd;
typedef typename Policies::checking checking;
if (::boost::numeric::interval_lib::user::is_neg(x))
return I(checking::neg_inf(), rnd.div_up(x, yu), true);
else
return I(rnd.div_down(x, yu), checking::pos_inf(), true);
// assert(::boost::numeric::interval_lib::user::is_neg(yl));
typedef interval<T, Policies> I;
if (::boost::numeric::interval_lib::user::is_zero(x))
return I(static_cast<T>(0), static_cast<T>(0), true);
typename Policies::rounding rnd;
typedef typename Policies::checking checking;
if (::boost::numeric::interval_lib::user::is_neg(x))
return I(rnd.div_down(x, yl), checking::pos_inf(), true);
else
return I(checking::neg_inf(), rnd.div_up(x, yl), true);
}
template<class T, class Policies> inline
interval<T, Policies> div_negative(const interval<T, Policies>& x, const T& yl)
template <class T, class Policies> inline interval<T, Policies> div_zero(const interval<T, Policies> &x)
{
// assert(::boost::numeric::interval_lib::user::is_neg(yl));
if (::boost::numeric::interval_lib::user::is_zero(x.lower()) &&
::boost::numeric::interval_lib::user::is_zero(x.upper()))
return x;
typename Policies::rounding rnd;
typedef interval<T, Policies> I;
const T& xl = x.lower();
const T& xu = x.upper();
typedef typename Policies::checking checking;
if (::boost::numeric::interval_lib::user::is_neg(xu))
return I(rnd.div_down(xu, yl), checking::pos_inf(), true);
else if (::boost::numeric::interval_lib::user::is_neg(xl))
return I(checking::neg_inf(), checking::pos_inf(), true);
else
return I(checking::neg_inf(), rnd.div_up(xl, yl), true);
if (::boost::numeric::interval_lib::user::is_zero(x.lower())
&& ::boost::numeric::interval_lib::user::is_zero(x.upper()))
return x;
else
return interval<T, Policies>::whole();
}
template<class T, class Policies> inline
interval<T, Policies> div_negative(const T& x, const T& yl)
template <class T, class Policies> inline interval<T, Policies> div_zero(const T &x)
{
// assert(::boost::numeric::interval_lib::user::is_neg(yl));
typedef interval<T, Policies> I;
if (::boost::numeric::interval_lib::user::is_zero(x))
return I(static_cast<T>(0), static_cast<T>(0), true);
typename Policies::rounding rnd;
typedef typename Policies::checking checking;
if (::boost::numeric::interval_lib::user::is_neg(x))
return I(rnd.div_down(x, yl), checking::pos_inf(), true);
else
return I(checking::neg_inf(), rnd.div_up(x, yl), true);
if (::boost::numeric::interval_lib::user::is_zero(x))
return interval<T, Policies>(static_cast<T>(0), static_cast<T>(0), true);
else
return interval<T, Policies>::whole();
}
template<class T, class Policies> inline
interval<T, Policies> div_zero(const interval<T, Policies>& x)
template <class T, class Policies>
inline interval<T, Policies> div_zero_part1(const interval<T, Policies> &x, const interval<T, Policies> &y, bool &b)
{
if (::boost::numeric::interval_lib::user::is_zero(x.lower()) &&
::boost::numeric::interval_lib::user::is_zero(x.upper()))
return x;
else return interval<T, Policies>::whole();
// assert(::boost::numeric::interval_lib::user::is_neg(y.lower()) &&
// ::boost::numeric::interval_lib::user::is_pos(y.upper()));
if (::boost::numeric::interval_lib::user::is_zero(x.lower())
&& ::boost::numeric::interval_lib::user::is_zero(x.upper())) {
b = false;
return x;
}
typename Policies::rounding rnd;
typedef interval<T, Policies> I;
const T &xl = x.lower();
const T &xu = x.upper();
const T &yl = y.lower();
const T &yu = y.upper();
typedef typename Policies::checking checking;
if (::boost::numeric::interval_lib::user::is_neg(xu)) {
b = true;
return I(checking::neg_inf(), rnd.div_up(xu, yu), true);
}
else if (::boost::numeric::interval_lib::user::is_neg(xl)) {
b = false;
return I(checking::neg_inf(), checking::pos_inf(), true);
}
else {
b = true;
return I(checking::neg_inf(), rnd.div_up(xl, yl), true);
}
}
template<class T, class Policies> inline
interval<T, Policies> div_zero(const T& x)
template <class T, class Policies>
inline interval<T, Policies> div_zero_part2(const interval<T, Policies> &x, const interval<T, Policies> &y)
{
if (::boost::numeric::interval_lib::user::is_zero(x))
return interval<T, Policies>(static_cast<T>(0), static_cast<T>(0), true);
else return interval<T, Policies>::whole();
}
template<class T, class Policies> inline
interval<T, Policies> div_zero_part1(const interval<T, Policies>& x,
const interval<T, Policies>& y, bool& b)
{
// assert(::boost::numeric::interval_lib::user::is_neg(y.lower()) && ::boost::numeric::interval_lib::user::is_pos(y.upper()));
if (::boost::numeric::interval_lib::user::is_zero(x.lower()) && ::boost::numeric::interval_lib::user::is_zero(x.upper()))
{ b = false; return x; }
typename Policies::rounding rnd;
typedef interval<T, Policies> I;
const T& xl = x.lower();
const T& xu = x.upper();
const T& yl = y.lower();
const T& yu = y.upper();
typedef typename Policies::checking checking;
if (::boost::numeric::interval_lib::user::is_neg(xu))
{ b = true; return I(checking::neg_inf(), rnd.div_up(xu, yu), true); }
else if (::boost::numeric::interval_lib::user::is_neg(xl))
{ b = false; return I(checking::neg_inf(), checking::pos_inf(), true); }
else
{ b = true; return I(checking::neg_inf(), rnd.div_up(xl, yl), true); }
}
template<class T, class Policies> inline
interval<T, Policies> div_zero_part2(const interval<T, Policies>& x,
const interval<T, Policies>& y)
{
// assert(::boost::numeric::interval_lib::user::is_neg(y.lower()) && ::boost::numeric::interval_lib::user::is_pos(y.upper()) && (div_zero_part1(x, y, b), b));
typename Policies::rounding rnd;
typedef interval<T, Policies> I;
typedef typename Policies::checking checking;
if (::boost::numeric::interval_lib::user::is_neg(x.upper()))
return I(rnd.div_down(x.upper(), y.lower()), checking::pos_inf(), true);
else
return I(rnd.div_down(x.lower(), y.upper()), checking::pos_inf(), true);
// assert(::boost::numeric::interval_lib::user::is_neg(y.lower()) &&
// ::boost::numeric::interval_lib::user::is_pos(y.upper()) && (div_zero_part1(x, y, b), b));
typename Policies::rounding rnd;
typedef interval<T, Policies> I;
typedef typename Policies::checking checking;
if (::boost::numeric::interval_lib::user::is_neg(x.upper()))
return I(rnd.div_down(x.upper(), y.lower()), checking::pos_inf(), true);
else
return I(rnd.div_down(x.lower(), y.upper()), checking::pos_inf(), true);
}
} // namespace detail

View File

@@ -16,7 +16,7 @@
#if defined(__hpux)
# include <fenv.h>
#include <fenv.h>
namespace boost {
namespace numeric {
@@ -24,51 +24,48 @@ namespace interval_lib {
namespace detail {
struct ia64_rounding_control
{
struct ia64_rounding_control
{
typedef unsigned int rounding_mode;
static void set_rounding_mode(const rounding_mode& mode) {
fesetround(mode); }
static void get_rounding_mode(rounding_mode& mode) { mode = fegetround(); }
static void set_rounding_mode(const rounding_mode &mode) { fesetround(mode); }
static void get_rounding_mode(rounding_mode &mode) { mode = fegetround(); }
static void downward() { set_rounding_mode(FE_DOWNWARD); }
static void upward() { set_rounding_mode(FE_UPWARD); }
static void to_nearest() { set_rounding_mode(FE_TONEAREST); }
static void downward() { set_rounding_mode(FE_DOWNWARD); }
static void upward() { set_rounding_mode(FE_UPWARD); }
static void to_nearest() { set_rounding_mode(FE_TONEAREST); }
static void toward_zero() { set_rounding_mode(FE_TOWARDZERO); }
};
};
} // namespace detail
extern "C" {
float rintf(float);
double rint(double);
long double rintl(long double);
extern "C"
{
float rintf(float);
double rint(double);
long double rintl(long double);
}
template<>
struct rounding_control<float>:
detail::ia64_rounding_control
template <> struct rounding_control<float> : detail::ia64_rounding_control
{
static float force_rounding(const float r)
{ volatile float _r = r; return _r; }
static float to_int(const float& x) { return rintf(x); }
static float force_rounding(const float r)
{
volatile float _r = r;
return _r;
}
static float to_int(const float &x) { return rintf(x); }
};
template<>
struct rounding_control<double>:
detail::ia64_rounding_control
template <> struct rounding_control<double> : detail::ia64_rounding_control
{
static const double & force_rounding(const double& r) { return r; }
static double to_int(const double& r) { return rint(r); }
static const double &force_rounding(const double &r) { return r; }
static double to_int(const double &r) { return rint(r); }
};
template<>
struct rounding_control<long double>:
detail::ia64_rounding_control
template <> struct rounding_control<long double> : detail::ia64_rounding_control
{
static const long double & force_rounding(const long double& r) { return r; }
static long double to_int(const long double& r) { return rintl(r); }
static const long double &force_rounding(const long double &r) { return r; }
static long double to_int(const long double &r) { return rintl(r); }
};
} // namespace interval_lib
@@ -80,4 +77,3 @@ struct rounding_control<long double>:
#endif /* __hpux */
#endif /* BOOST_NUMERIC_INTERVAL_DETAIL_IA64_ROUNDING_CONTROL_HPP */

View File

@@ -15,25 +15,23 @@ namespace numeric {
namespace interval_lib {
template<class T> struct rounded_math;
template<class T> struct checking_strict;
template <class T> struct rounded_math;
template <class T> struct checking_strict;
class comparison_error;
template<class Rounding, class Checking> struct policies;
template <class Rounding, class Checking> struct policies;
/*
* default policies class
*/
template<class T>
struct default_policies
template <class T> struct default_policies
{
typedef policies<rounded_math<T>, checking_strict<T> > type;
typedef policies<rounded_math<T>, checking_strict<T>> type;
};
} // namespace interval_lib
template<class T, class Policies = typename interval_lib::default_policies<T>::type >
class interval;
template <class T, class Policies = typename interval_lib::default_policies<T>::type> class interval;
} // namespace numeric
} // namespace boost

View File

@@ -12,10 +12,10 @@
#define BOOST_NUMERIC_INTERVAL_DETAIL_MSVC_ROUNDING_CONTROL_HPP
#ifndef _MSC_VER
# error This header is only intended for MSVC, but might work for Borland as well
#error This header is only intended for MSVC, but might work for Borland as well
#endif
#include <float.h> // MSVC rounding control
#include <float.h> // MSVC rounding control
// Although the function is called _control87, it seems to work for
// other FPUs too, so it does not have to be changed to _controlfp.
@@ -25,74 +25,123 @@ namespace numeric {
namespace interval_lib {
namespace detail {
extern "C" { double rint(double); }
extern "C"
{
double rint(double);
}
struct x86_rounding
{
static unsigned int hard2msvc(unsigned short m) {
unsigned int n = 0;
if (m & 0x01) n |= _EM_INVALID;
if (m & 0x02) n |= _EM_DENORMAL;
if (m & 0x04) n |= _EM_ZERODIVIDE;
if (m & 0x08) n |= _EM_OVERFLOW;
if (m & 0x10) n |= _EM_UNDERFLOW;
if (m & 0x20) n |= _EM_INEXACT;
switch (m & 0x300) {
case 0x000: n |= _PC_24; break;
case 0x200: n |= _PC_53; break;
case 0x300: n |= _PC_64; break;
static unsigned int hard2msvc(unsigned short m)
{
unsigned int n = 0;
if (m & 0x01)
n |= _EM_INVALID;
if (m & 0x02)
n |= _EM_DENORMAL;
if (m & 0x04)
n |= _EM_ZERODIVIDE;
if (m & 0x08)
n |= _EM_OVERFLOW;
if (m & 0x10)
n |= _EM_UNDERFLOW;
if (m & 0x20)
n |= _EM_INEXACT;
switch (m & 0x300) {
case 0x000:
n |= _PC_24;
break;
case 0x200:
n |= _PC_53;
break;
case 0x300:
n |= _PC_64;
break;
}
switch (m & 0xC00) {
case 0x000:
n |= _RC_NEAR;
break;
case 0x400:
n |= _RC_DOWN;
break;
case 0x800:
n |= _RC_UP;
break;
case 0xC00:
n |= _RC_CHOP;
break;
}
if (m & 0x1000)
n |= _IC_AFFINE; // only useful on 287
return n;
}
switch (m & 0xC00) {
case 0x000: n |= _RC_NEAR; break;
case 0x400: n |= _RC_DOWN; break;
case 0x800: n |= _RC_UP; break;
case 0xC00: n |= _RC_CHOP; break;
}
if (m & 0x1000) n |= _IC_AFFINE; // only useful on 287
return n;
}
static unsigned short msvc2hard(unsigned int n) {
unsigned short m = 0;
if (n & _EM_INVALID) m |= 0x01;
if (n & _EM_DENORMAL) m |= 0x02;
if (n & _EM_ZERODIVIDE) m |= 0x04;
if (n & _EM_OVERFLOW) m |= 0x08;
if (n & _EM_UNDERFLOW) m |= 0x10;
if (n & _EM_INEXACT) m |= 0x20;
switch (n & _MCW_RC) {
case _RC_NEAR: m |= 0x000; break;
case _RC_DOWN: m |= 0x400; break;
case _RC_UP: m |= 0x800; break;
case _RC_CHOP: m |= 0xC00; break;
static unsigned short msvc2hard(unsigned int n)
{
unsigned short m = 0;
if (n & _EM_INVALID)
m |= 0x01;
if (n & _EM_DENORMAL)
m |= 0x02;
if (n & _EM_ZERODIVIDE)
m |= 0x04;
if (n & _EM_OVERFLOW)
m |= 0x08;
if (n & _EM_UNDERFLOW)
m |= 0x10;
if (n & _EM_INEXACT)
m |= 0x20;
switch (n & _MCW_RC) {
case _RC_NEAR:
m |= 0x000;
break;
case _RC_DOWN:
m |= 0x400;
break;
case _RC_UP:
m |= 0x800;
break;
case _RC_CHOP:
m |= 0xC00;
break;
}
switch (n & _MCW_PC) {
case _PC_24:
m |= 0x000;
break;
case _PC_53:
m |= 0x200;
break;
case _PC_64:
m |= 0x300;
break;
}
if ((n & _MCW_IC) == _IC_AFFINE)
m |= 0x1000;
return m;
}
switch (n & _MCW_PC) {
case _PC_24: m |= 0x000; break;
case _PC_53: m |= 0x200; break;
case _PC_64: m |= 0x300; break;
}
if ((n & _MCW_IC) == _IC_AFFINE) m |= 0x1000;
return m;
}
typedef unsigned short rounding_mode;
static void get_rounding_mode(rounding_mode& mode)
{ mode = msvc2hard(_control87(0, 0)); }
static void set_rounding_mode(const rounding_mode mode)
{ _control87(hard2msvc(mode),
_MCW_EM | _MCW_RC
typedef unsigned short rounding_mode;
static void get_rounding_mode(rounding_mode &mode) { mode = msvc2hard(_control87(0, 0)); }
static void set_rounding_mode(const rounding_mode mode)
{
_control87(hard2msvc(mode),
_MCW_EM
| _MCW_RC
// This is updated as per fix in boost 1.58
#if !defined(_M_AMD64) && !defined(_M_ARM)
// x64 ignores _MCW_PC and _MCW_IC, and the Debug CRT library actually
// asserts when these are passed to _control87.
// MSDN says on '_control87' that changing precision (_MCW_PC) or
// infinity (_MCW_IC) handling is not supported on the ARM and x64
// architectures and that _control87 raises an assertion
// and the invalid parameter handler is invoked.
| _MCW_PC | _MCW_IC
// x64 ignores _MCW_PC and _MCW_IC, and the Debug CRT library actually
// asserts when these are passed to _control87.
// MSDN says on '_control87' that changing precision (_MCW_PC) or
// infinity (_MCW_IC) handling is not supported on the ARM and x64
// architectures and that _control87 raises an assertion
// and the invalid parameter handler is invoked.
| _MCW_PC | _MCW_IC
#endif
); }
static double to_int(const double& x) { return rint(x); }
);
}
static double to_int(const double &x) { return rint(x); }
};
} // namespace detail

View File

@@ -16,37 +16,36 @@
#error This header only works on PPC CPUs.
#endif
#if defined(__GNUC__ ) || (__IBMCPP__ >= 700)
#if defined(__GNUC__) || (__IBMCPP__ >= 700)
namespace boost {
namespace numeric {
namespace interval_lib {
namespace detail {
typedef union {
::boost::long_long_type imode;
double dmode;
typedef union
{
::boost::long_long_type imode;
double dmode;
} rounding_mode_struct;
static const rounding_mode_struct mode_upward = { static_cast<boost::long_long_type>(0xFFF8000000000002LL) };
static const rounding_mode_struct mode_downward = { static_cast<boost::long_long_type>(0xFFF8000000000003LL) };
static const rounding_mode_struct mode_to_nearest = { static_cast<boost::long_long_type>(0xFFF8000000000000LL) };
static const rounding_mode_struct mode_toward_zero = { static_cast<boost::long_long_type>(0xFFF8000000000001LL) };
static const rounding_mode_struct mode_upward = {static_cast<boost::long_long_type>(0xFFF8000000000002LL)};
static const rounding_mode_struct mode_downward = {static_cast<boost::long_long_type>(0xFFF8000000000003LL)};
static const rounding_mode_struct mode_to_nearest = {static_cast<boost::long_long_type>(0xFFF8000000000000LL)};
static const rounding_mode_struct mode_toward_zero = {static_cast<boost::long_long_type>(0xFFF8000000000001LL)};
struct ppc_rounding_control
{
typedef double rounding_mode;
typedef double rounding_mode;
static void set_rounding_mode(const rounding_mode mode)
{ __asm__ __volatile__ ("mtfsf 255,%0" : : "f"(mode)); }
static void set_rounding_mode(const rounding_mode mode) { __asm__ __volatile__("mtfsf 255,%0" : : "f"(mode)); }
static void get_rounding_mode(rounding_mode& mode)
{ __asm__ __volatile__ ("mffs %0" : "=f"(mode)); }
static void get_rounding_mode(rounding_mode &mode) { __asm__ __volatile__("mffs %0" : "=f"(mode)); }
static void downward() { set_rounding_mode(mode_downward.dmode); }
static void upward() { set_rounding_mode(mode_upward.dmode); }
static void to_nearest() { set_rounding_mode(mode_to_nearest.dmode); }
static void toward_zero() { set_rounding_mode(mode_toward_zero.dmode); }
static void downward() { set_rounding_mode(mode_downward.dmode); }
static void upward() { set_rounding_mode(mode_upward.dmode); }
static void to_nearest() { set_rounding_mode(mode_to_nearest.dmode); }
static void toward_zero() { set_rounding_mode(mode_toward_zero.dmode); }
};
} // namespace detail
@@ -54,39 +53,34 @@ struct ppc_rounding_control
// Do not declare the following C99 symbols if <math.h> provides them.
// Otherwise, conflicts may occur, due to differences between prototypes.
#if !defined(_ISOC99_SOURCE) && !defined(__USE_ISOC99)
extern "C" {
float rintf(float);
double rint(double);
extern "C"
{
float rintf(float);
double rint(double);
}
#endif
template<>
struct rounding_control<float>:
detail::ppc_rounding_control
template <> struct rounding_control<float> : detail::ppc_rounding_control
{
static float force_rounding(const float r)
{
float tmp;
__asm__ __volatile__ ("frsp %0, %1" : "=f" (tmp) : "f" (r));
return tmp;
}
static float to_int(const float& x) { return rintf(x); }
static float force_rounding(const float r)
{
float tmp;
__asm__ __volatile__("frsp %0, %1" : "=f"(tmp) : "f"(r));
return tmp;
}
static float to_int(const float &x) { return rintf(x); }
};
template<>
struct rounding_control<double>:
detail::ppc_rounding_control
template <> struct rounding_control<double> : detail::ppc_rounding_control
{
static const double & force_rounding(const double& r) { return r; }
static double to_int(const double& r) { return rint(r); }
static const double &force_rounding(const double &r) { return r; }
static double to_int(const double &r) { return rint(r); }
};
template<>
struct rounding_control<long double>:
detail::ppc_rounding_control
template <> struct rounding_control<long double> : detail::ppc_rounding_control
{
static const long double & force_rounding(const long double& r) { return r; }
static long double to_int(const long double& r) { return rint(static_cast<double>(r)); }
static const long double &force_rounding(const long double &r) { return r; }
static long double to_int(const long double &r) { return rint(static_cast<double>(r)); }
};
} // namespace interval_lib

View File

@@ -14,11 +14,11 @@
#define BOOST_NUMERIC_INTERVAL_DETAIL_SPARC_ROUNDING_CONTROL_HPP
#if !defined(sparc) && !defined(__sparc__)
# error This header is only intended for SPARC CPUs.
#error This header is only intended for SPARC CPUs.
#endif
#ifdef __SUNPRO_CC
# include <ieeefp.h>
#include <ieeefp.h>
#endif
@@ -29,78 +29,73 @@ namespace detail {
struct sparc_rounding_control
{
typedef unsigned int rounding_mode;
typedef unsigned int rounding_mode;
static void set_rounding_mode(const rounding_mode& mode)
{
# if defined(__GNUC__)
__asm__ __volatile__("ld %0, %%fsr" : : "m"(mode));
# elif defined (__SUNPRO_CC)
fpsetround(fp_rnd(mode));
# elif defined(__KCC)
asm("sethi %hi(mode), %o1");
asm("ld [%o1+%lo(mode)], %fsr");
# else
# error Unsupported compiler for Sparc rounding control.
# endif
}
static void set_rounding_mode(const rounding_mode &mode)
{
#if defined(__GNUC__)
__asm__ __volatile__("ld %0, %%fsr" : : "m"(mode));
#elif defined(__SUNPRO_CC)
fpsetround(fp_rnd(mode));
#elif defined(__KCC)
asm("sethi %hi(mode), %o1");
asm("ld [%o1+%lo(mode)], %fsr");
#else
#error Unsupported compiler for Sparc rounding control.
#endif
}
static void get_rounding_mode(rounding_mode& mode)
{
# if defined(__GNUC__)
__asm__ __volatile__("st %%fsr, %0" : "=m"(mode));
# elif defined (__SUNPRO_CC)
mode = fpgetround();
# elif defined(__KCC)
# error KCC on Sun SPARC get_round_mode: please fix me
asm("st %fsr, [mode]");
# else
# error Unsupported compiler for Sparc rounding control.
# endif
}
static void get_rounding_mode(rounding_mode &mode)
{
#if defined(__GNUC__)
__asm__ __volatile__("st %%fsr, %0" : "=m"(mode));
#elif defined(__SUNPRO_CC)
mode = fpgetround();
#elif defined(__KCC)
#error KCC on Sun SPARC get_round_mode: please fix me
asm("st %fsr, [mode]");
#else
#error Unsupported compiler for Sparc rounding control.
#endif
}
#if defined(__SUNPRO_CC)
static void downward() { set_rounding_mode(FP_RM); }
static void upward() { set_rounding_mode(FP_RP); }
static void to_nearest() { set_rounding_mode(FP_RN); }
static void toward_zero() { set_rounding_mode(FP_RZ); }
static void downward() { set_rounding_mode(FP_RM); }
static void upward() { set_rounding_mode(FP_RP); }
static void to_nearest() { set_rounding_mode(FP_RN); }
static void toward_zero() { set_rounding_mode(FP_RZ); }
#else
static void downward() { set_rounding_mode(0xc0000000); }
static void upward() { set_rounding_mode(0x80000000); }
static void to_nearest() { set_rounding_mode(0x00000000); }
static void toward_zero() { set_rounding_mode(0x40000000); }
static void downward() { set_rounding_mode(0xc0000000); }
static void upward() { set_rounding_mode(0x80000000); }
static void to_nearest() { set_rounding_mode(0x00000000); }
static void toward_zero() { set_rounding_mode(0x40000000); }
#endif
};
} // namespace detail
extern "C" {
float rintf(float);
double rint(double);
extern "C"
{
float rintf(float);
double rint(double);
}
template<>
struct rounding_control<float>:
detail::sparc_rounding_control
template <> struct rounding_control<float> : detail::sparc_rounding_control
{
static const float& force_rounding(const float& x) { return x; }
static float to_int(const float& x) { return rintf(x); }
static const float &force_rounding(const float &x) { return x; }
static float to_int(const float &x) { return rintf(x); }
};
template<>
struct rounding_control<double>:
detail::sparc_rounding_control
template <> struct rounding_control<double> : detail::sparc_rounding_control
{
static const double& force_rounding(const double& x) { return x; }
static double to_int(const double& x) { return rint(x); }
static const double &force_rounding(const double &x) { return x; }
static double to_int(const double &x) { return rint(x); }
};
template<>
struct rounding_control<long double>:
detail::sparc_rounding_control
template <> struct rounding_control<long double> : detail::sparc_rounding_control
{
static const long double& force_rounding(const long double& x) { return x; }
static long double to_int(const long double& x) { return rint(x); }
static const long double &force_rounding(const long double &x) { return x; }
static long double to_int(const long double &x) { return rint(x); }
};
} // namespace interval_lib

View File

@@ -17,55 +17,52 @@ namespace numeric {
namespace interval_lib {
namespace user {
template<class T> inline
bool is_zero(T const &v) { return v == static_cast<T>(0); }
template <class T> inline bool is_zero(T const &v) { return v == static_cast<T>(0); }
template<class T> inline
bool is_neg (T const &v) { return v < static_cast<T>(0); }
template <class T> inline bool is_neg(T const &v) { return v < static_cast<T>(0); }
template<class T> inline
bool is_pos (T const &v) { return v > static_cast<T>(0); }
template <class T> inline bool is_pos(T const &v) { return v > static_cast<T>(0); }
} // namespace user
namespace detail {
template<class T, class Policies> inline
bool test_input(const interval<T, Policies>& x) {
typedef typename Policies::checking checking;
return checking::is_empty(x.lower(), x.upper());
template <class T, class Policies> inline bool test_input(const interval<T, Policies> &x)
{
typedef typename Policies::checking checking;
return checking::is_empty(x.lower(), x.upper());
}
template<class T, class Policies1, class Policies2> inline
bool test_input(const interval<T, Policies1>& x, const interval<T, Policies2>& y) {
typedef typename Policies1::checking checking1;
typedef typename Policies2::checking checking2;
return checking1::is_empty(x.lower(), x.upper()) ||
checking2::is_empty(y.lower(), y.upper());
template <class T, class Policies1, class Policies2>
inline bool test_input(const interval<T, Policies1> &x, const interval<T, Policies2> &y)
{
typedef typename Policies1::checking checking1;
typedef typename Policies2::checking checking2;
return checking1::is_empty(x.lower(), x.upper()) || checking2::is_empty(y.lower(), y.upper());
}
template<class T, class Policies> inline
bool test_input(const T& x, const interval<T, Policies>& y) {
typedef typename Policies::checking checking;
return checking::is_nan(x) || checking::is_empty(y.lower(), y.upper());
template <class T, class Policies> inline bool test_input(const T &x, const interval<T, Policies> &y)
{
typedef typename Policies::checking checking;
return checking::is_nan(x) || checking::is_empty(y.lower(), y.upper());
}
template<class T, class Policies> inline
bool test_input(const interval<T, Policies>& x, const T& y) {
typedef typename Policies::checking checking;
return checking::is_empty(x.lower(), x.upper()) || checking::is_nan(y);
template <class T, class Policies> inline bool test_input(const interval<T, Policies> &x, const T &y)
{
typedef typename Policies::checking checking;
return checking::is_empty(x.lower(), x.upper()) || checking::is_nan(y);
}
template<class T, class Policies> inline
bool test_input(const T& x) {
typedef typename Policies::checking checking;
return checking::is_nan(x);
template <class T, class Policies> inline bool test_input(const T &x)
{
typedef typename Policies::checking checking;
return checking::is_nan(x);
}
template<class T, class Policies> inline
bool test_input(const T& x, const T& y) {
typedef typename Policies::checking checking;
return checking::is_nan(x) || checking::is_nan(y);
template <class T, class Policies> inline bool test_input(const T &x, const T &y)
{
typedef typename Policies::checking checking;
return checking::is_nan(x) || checking::is_nan(y);
}
} // namespace detail

View File

@@ -12,16 +12,16 @@
#define BOOST_NUMERIC_INTERVAL_DETAIL_X86_ROUNDING_CONTROL_HPP
#ifdef __GNUC__
# include <boost/numeric/interval/detail/x86gcc_rounding_control.hpp>
#include <boost/numeric/interval/detail/x86gcc_rounding_control.hpp>
#elif defined(__BORLANDC__)
# include <boost/numeric/interval/detail/bcc_rounding_control.hpp>
#include <boost/numeric/interval/detail/bcc_rounding_control.hpp>
#elif defined(_MSC_VER)
# include <boost/numeric/interval/detail/msvc_rounding_control.hpp>
#include <boost/numeric/interval/detail/msvc_rounding_control.hpp>
#elif defined(__MWERKS__) || defined(__ICC)
# define BOOST_NUMERIC_INTERVAL_USE_C99_SUBSYSTEM
# include <boost/numeric/interval/detail/c99sub_rounding_control.hpp>
#define BOOST_NUMERIC_INTERVAL_USE_C99_SUBSYSTEM
#include <boost/numeric/interval/detail/c99sub_rounding_control.hpp>
#else
# error Unsupported C++ compiler.
#error Unsupported C++ compiler.
#endif
namespace boost {
@@ -36,68 +36,70 @@ typedef c99_rounding x86_rounding_control;
#else
struct fpu_rounding_modes
{
unsigned short to_nearest;
unsigned short downward;
unsigned short upward;
unsigned short toward_zero;
unsigned short to_nearest;
unsigned short downward;
unsigned short upward;
unsigned short toward_zero;
};
// exceptions masked, extended precision
// hardware default is 0x037f (0x1000 only has a meaning on 287)
static const fpu_rounding_modes rnd_mode = { 0x137f, 0x177f, 0x1b7f, 0x1f7f };
static const fpu_rounding_modes rnd_mode = {0x137f, 0x177f, 0x1b7f, 0x1f7f};
struct x86_rounding_control: x86_rounding
struct x86_rounding_control : x86_rounding
{
static void to_nearest() { set_rounding_mode(rnd_mode.to_nearest); }
static void downward() { set_rounding_mode(rnd_mode.downward); }
static void upward() { set_rounding_mode(rnd_mode.upward); }
static void toward_zero() { set_rounding_mode(rnd_mode.toward_zero); }
static void to_nearest() { set_rounding_mode(rnd_mode.to_nearest); }
static void downward() { set_rounding_mode(rnd_mode.downward); }
static void upward() { set_rounding_mode(rnd_mode.upward); }
static void toward_zero() { set_rounding_mode(rnd_mode.toward_zero); }
};
#endif // BOOST_NUMERIC_INTERVAL_USE_C99_SUBSYSTEM
} // namespace detail
template<>
struct rounding_control<float>: detail::x86_rounding_control
template <> struct rounding_control<float> : detail::x86_rounding_control
{
static float force_rounding(const float& r)
{ volatile float r_ = r; return r_; }
static float force_rounding(const float &r)
{
volatile float r_ = r;
return r_;
}
};
template<>
struct rounding_control<double>: detail::x86_rounding_control
template <> struct rounding_control<double> : detail::x86_rounding_control
{
/*static double force_rounding(double r)
{ asm volatile ("" : "+m"(r) : ); return r; }*/
static double force_rounding(const double& r)
{ volatile double r_ = r; return r_; }
/*static double force_rounding(double r)
{ asm volatile ("" : "+m"(r) : ); return r; }*/
static double force_rounding(const double &r)
{
volatile double r_ = r;
return r_;
}
};
namespace detail {
template<bool>
struct x86_rounding_control_long_double;
template <bool> struct x86_rounding_control_long_double;
template<>
struct x86_rounding_control_long_double<false>: x86_rounding_control
template <> struct x86_rounding_control_long_double<false> : x86_rounding_control
{
static long double force_rounding(long double const &r)
{ volatile long double r_ = r; return r_; }
static long double force_rounding(long double const &r)
{
volatile long double r_ = r;
return r_;
}
};
template<>
struct x86_rounding_control_long_double<true>: x86_rounding_control
template <> struct x86_rounding_control_long_double<true> : x86_rounding_control
{
static long double const &force_rounding(long double const &r)
{ return r; }
static long double const &force_rounding(long double const &r) { return r; }
};
} // namespace detail
template<>
struct rounding_control<long double>:
detail::x86_rounding_control_long_double< (sizeof(long double) >= 10) >
{};
template <> struct rounding_control<long double> : detail::x86_rounding_control_long_double<(sizeof(long double) >= 10)>
{
};
} // namespace interval_lib
} // namespace numeric

View File

@@ -12,11 +12,11 @@
#define BOOST_NUMERIC_INTERVAL_DETAIL_X86GCC_ROUNDING_CONTROL_HPP
#ifndef __GNUC__
# error This header only works with GNU CC.
#error This header only works with GNU CC.
#endif
#ifndef __i386__
# error This header only works on x86 CPUs.
#error This header only works on x86 CPUs.
#endif
namespace boost {
@@ -26,21 +26,18 @@ namespace detail {
struct x86_rounding
{
typedef unsigned short rounding_mode;
typedef unsigned short rounding_mode;
static void set_rounding_mode(const rounding_mode& mode)
{ __asm__ __volatile__ ("fldcw %0" : : "m"(mode)); }
static void set_rounding_mode(const rounding_mode &mode) { __asm__ __volatile__("fldcw %0" : : "m"(mode)); }
static void get_rounding_mode(rounding_mode& mode)
{ __asm__ __volatile__ ("fnstcw %0" : "=m"(mode)); }
static void get_rounding_mode(rounding_mode &mode) { __asm__ __volatile__("fnstcw %0" : "=m"(mode)); }
template<class T>
static T to_int(T r)
{
T r_;
__asm__ ("frndint" : "=&t"(r_) : "0"(r));
return r_;
}
template <class T> static T to_int(T r)
{
T r_;
__asm__("frndint" : "=&t"(r_) : "0"(r));
return r_;
}
};
} // namespace detail

View File

@@ -16,52 +16,44 @@
namespace boost {
namespace numeric {
template<class T, class Policies> inline
interval<T, Policies> operator+ (const interval<T, Policies>& x, int y)
template <class T, class Policies> inline interval<T, Policies> operator+(const interval<T, Policies> &x, int y)
{
return x + static_cast<T>(y);
return x + static_cast<T>(y);
}
template<class T, class Policies> inline
interval<T, Policies> operator+ (int x, const interval<T, Policies>& y)
template <class T, class Policies> inline interval<T, Policies> operator+(int x, const interval<T, Policies> &y)
{
return static_cast<T>(x) + y;
return static_cast<T>(x) + y;
}
template<class T, class Policies> inline
interval<T, Policies> operator- (const interval<T, Policies>& x, int y)
template <class T, class Policies> inline interval<T, Policies> operator-(const interval<T, Policies> &x, int y)
{
return x - static_cast<T>(y);
return x - static_cast<T>(y);
}
template<class T, class Policies> inline
interval<T, Policies> operator- (int x, const interval<T, Policies>& y)
template <class T, class Policies> inline interval<T, Policies> operator-(int x, const interval<T, Policies> &y)
{
return static_cast<T>(x) - y;
return static_cast<T>(x) - y;
}
template<class T, class Policies> inline
interval<T, Policies> operator* (const interval<T, Policies>& x, int y)
template <class T, class Policies> inline interval<T, Policies> operator*(const interval<T, Policies> &x, int y)
{
return x * static_cast<T>(y);
return x * static_cast<T>(y);
}
template<class T, class Policies> inline
interval<T, Policies> operator* (int x, const interval<T, Policies>& y)
template <class T, class Policies> inline interval<T, Policies> operator*(int x, const interval<T, Policies> &y)
{
return static_cast<T>(x) * y;
return static_cast<T>(x) * y;
}
template<class T, class Policies> inline
interval<T, Policies> operator/ (const interval<T, Policies>& x, int y)
template <class T, class Policies> inline interval<T, Policies> operator/(const interval<T, Policies> &x, int y)
{
return x / static_cast<T>(y);
return x / static_cast<T>(y);
}
template<class T, class Policies> inline
interval<T, Policies> operator/ (int x, const interval<T, Policies>& y)
template <class T, class Policies> inline interval<T, Policies> operator/(int x, const interval<T, Policies> &y)
{
return static_cast<T>(x) / y;
return static_cast<T>(x) / y;
}
} // namespace numeric

View File

@@ -24,43 +24,39 @@ namespace interval_lib {
namespace detail {
// exceptions masked, expected precision (the mask is 0x0300)
static const fpu_rounding_modes rnd_mode_f = { 0x107f, 0x147f, 0x187f, 0x1c7f };
static const fpu_rounding_modes rnd_mode_d = { 0x127f, 0x167f, 0x1a7f, 0x1e7f };
static const fpu_rounding_modes rnd_mode_l = { 0x137f, 0x177f, 0x1b7f, 0x1f7f };
static const fpu_rounding_modes rnd_mode_f = {0x107f, 0x147f, 0x187f, 0x1c7f};
static const fpu_rounding_modes rnd_mode_d = {0x127f, 0x167f, 0x1a7f, 0x1e7f};
static const fpu_rounding_modes rnd_mode_l = {0x137f, 0x177f, 0x1b7f, 0x1f7f};
} // namespace detail
template<class T>
struct x86_fast_rounding_control;
template <class T> struct x86_fast_rounding_control;
template<>
struct x86_fast_rounding_control<float>: detail::x86_rounding
template <> struct x86_fast_rounding_control<float> : detail::x86_rounding
{
static void to_nearest() { set_rounding_mode(detail::rnd_mode_f.to_nearest); }
static void downward() { set_rounding_mode(detail::rnd_mode_f.downward); }
static void upward() { set_rounding_mode(detail::rnd_mode_f.upward); }
static void toward_zero() { set_rounding_mode(detail::rnd_mode_f.toward_zero); }
static const float& force_rounding(const float& r) { return r; }
static void to_nearest() { set_rounding_mode(detail::rnd_mode_f.to_nearest); }
static void downward() { set_rounding_mode(detail::rnd_mode_f.downward); }
static void upward() { set_rounding_mode(detail::rnd_mode_f.upward); }
static void toward_zero() { set_rounding_mode(detail::rnd_mode_f.toward_zero); }
static const float &force_rounding(const float &r) { return r; }
};
template<>
struct x86_fast_rounding_control<double>: detail::x86_rounding
template <> struct x86_fast_rounding_control<double> : detail::x86_rounding
{
static void to_nearest() { set_rounding_mode(detail::rnd_mode_d.to_nearest); }
static void downward() { set_rounding_mode(detail::rnd_mode_d.downward); }
static void upward() { set_rounding_mode(detail::rnd_mode_d.upward); }
static void toward_zero() { set_rounding_mode(detail::rnd_mode_d.toward_zero); }
static const double& force_rounding(const double& r) { return r; }
static void to_nearest() { set_rounding_mode(detail::rnd_mode_d.to_nearest); }
static void downward() { set_rounding_mode(detail::rnd_mode_d.downward); }
static void upward() { set_rounding_mode(detail::rnd_mode_d.upward); }
static void toward_zero() { set_rounding_mode(detail::rnd_mode_d.toward_zero); }
static const double &force_rounding(const double &r) { return r; }
};
template<>
struct x86_fast_rounding_control<long double>: detail::x86_rounding
template <> struct x86_fast_rounding_control<long double> : detail::x86_rounding
{
static void to_nearest() { set_rounding_mode(detail::rnd_mode_l.to_nearest); }
static void downward() { set_rounding_mode(detail::rnd_mode_l.downward); }
static void upward() { set_rounding_mode(detail::rnd_mode_l.upward); }
static void toward_zero() { set_rounding_mode(detail::rnd_mode_l.toward_zero); }
static const long double& force_rounding(const long double& r) { return r; }
static void to_nearest() { set_rounding_mode(detail::rnd_mode_l.to_nearest); }
static void downward() { set_rounding_mode(detail::rnd_mode_l.downward); }
static void upward() { set_rounding_mode(detail::rnd_mode_l.upward); }
static void toward_zero() { set_rounding_mode(detail::rnd_mode_l.toward_zero); }
static const long double &force_rounding(const long double &r) { return r; }
};
} // namespace interval_lib

View File

@@ -11,33 +11,33 @@
#ifndef BOOST_NUMERIC_INTERVAL_HW_ROUNDING_HPP
#define BOOST_NUMERIC_INTERVAL_HW_ROUNDING_HPP
#include <boost/numeric/interval/rounding.hpp>
#include <boost/numeric/interval/rounded_arith.hpp>
#include <boost/numeric/interval/rounding.hpp>
#define BOOST_NUMERIC_INTERVAL_NO_HARDWARE
// define appropriate specialization of rounding_control for built-in types
#if defined(__x86_64__) && defined(__USE_ISOC99)
# include <boost/numeric/interval/detail/c99_rounding_control.hpp>
#include <boost/numeric/interval/detail/c99_rounding_control.hpp>
#elif defined(__i386__) || defined(_M_IX86) || defined(__BORLANDC__) || defined(_M_X64)
# include <boost/numeric/interval/detail/x86_rounding_control.hpp>
#include <boost/numeric/interval/detail/x86_rounding_control.hpp>
#elif defined(powerpc) || defined(__powerpc__) || defined(__ppc__)
# include <boost/numeric/interval/detail/ppc_rounding_control.hpp>
#include <boost/numeric/interval/detail/ppc_rounding_control.hpp>
#elif defined(sparc) || defined(__sparc__)
# include <boost/numeric/interval/detail/sparc_rounding_control.hpp>
#include <boost/numeric/interval/detail/sparc_rounding_control.hpp>
#elif defined(alpha) || defined(__alpha__)
# include <boost/numeric/interval/detail/alpha_rounding_control.hpp>
#include <boost/numeric/interval/detail/alpha_rounding_control.hpp>
#elif defined(ia64) || defined(__ia64) || defined(__ia64__)
# include <boost/numeric/interval/detail/ia64_rounding_control.hpp>
#include <boost/numeric/interval/detail/ia64_rounding_control.hpp>
#endif
#if defined(BOOST_NUMERIC_INTERVAL_NO_HARDWARE) && (defined(__USE_ISOC99) || defined(__MSL__))
# include <boost/numeric/interval/detail/c99_rounding_control.hpp>
#include <boost/numeric/interval/detail/c99_rounding_control.hpp>
#endif
#if defined(BOOST_NUMERIC_INTERVAL_NO_HARDWARE)
# undef BOOST_NUMERIC_INTERVAL_NO_HARDWARE
# error Boost.Numeric.Interval: Please specify rounding control mechanism.
#undef BOOST_NUMERIC_INTERVAL_NO_HARDWARE
#error Boost.Numeric.Interval: Please specify rounding control mechanism.
#endif
namespace boost {
@@ -48,20 +48,17 @@ namespace interval_lib {
* Three specializations of rounded_math<T>
*/
template<>
struct rounded_math<float>
: save_state<rounded_arith_opp<float> >
{};
template <> struct rounded_math<float> : save_state<rounded_arith_opp<float>>
{
};
template<>
struct rounded_math<double>
: save_state<rounded_arith_opp<double> >
{};
template <> struct rounded_math<double> : save_state<rounded_arith_opp<double>>
{
};
template<>
struct rounded_math<long double>
: save_state<rounded_arith_opp<long double> >
{};
template <> struct rounded_math<long double> : save_state<rounded_arith_opp<long double>>
{
};
} // namespace interval_lib
} // namespace numeric

View File

@@ -10,22 +10,22 @@
#ifndef BOOST_NUMERIC_INTERVAL_INTERVAL_HPP
#define BOOST_NUMERIC_INTERVAL_INTERVAL_HPP
#include <boost/numeric/interval/detail/interval_prototype.hpp>
#include <stdexcept>
#include <string>
#include <boost/numeric/interval/detail/interval_prototype.hpp>
namespace boost {
namespace numeric {
namespace interval_lib {
class comparison_error
: public std::runtime_error
class comparison_error : public std::runtime_error
{
public:
comparison_error()
: std::runtime_error("boost::interval: uncertain comparison")
{ }
comparison_error()
: std::runtime_error("boost::interval: uncertain comparison")
{
}
};
} // namespace interval_lib
@@ -34,414 +34,448 @@ public:
* interval class
*/
template<class T, class Policies>
class interval
template <class T, class Policies> class interval
{
private:
struct interval_holder;
struct number_holder;
struct interval_holder;
struct number_holder;
public:
typedef T base_type;
typedef Policies traits_type;
typedef T base_type;
typedef Policies traits_type;
T const &lower() const;
T const &upper() const;
T const &lower() const;
T const &upper() const;
interval();
interval(T const &v);
template<class T1> interval(T1 const &v);
interval(T const &l, T const &u);
template<class T1, class T2> interval(T1 const &l, T2 const &u);
interval(interval<T, Policies> const &r);
template<class Policies1> interval(interval<T, Policies1> const &r);
template<class T1, class Policies1> interval(interval<T1, Policies1> const &r);
interval();
interval(T const &v);
template <class T1> interval(T1 const &v);
interval(T const &l, T const &u);
template <class T1, class T2> interval(T1 const &l, T2 const &u);
interval(interval<T, Policies> const &r);
template <class Policies1> interval(interval<T, Policies1> const &r);
template <class T1, class Policies1> interval(interval<T1, Policies1> const &r);
interval &operator=(T const &v);
template<class T1> interval &operator=(T1 const &v);
interval &operator=(interval<T, Policies> const &r);
template<class Policies1> interval &operator=(interval<T, Policies1> const &r);
template<class T1, class Policies1> interval &operator=(interval<T1, Policies1> const &r);
void assign(const T& l, const T& u);
interval &operator=(T const &v);
template <class T1> interval &operator=(T1 const &v);
interval &operator=(interval<T, Policies> const &r);
template <class Policies1> interval &operator=(interval<T, Policies1> const &r);
template <class T1, class Policies1> interval &operator=(interval<T1, Policies1> const &r);
static interval empty();
static interval whole();
static interval hull(const T& x, const T& y);
void assign(const T &l, const T &u);
interval& operator+= (const T& r);
interval& operator+= (const interval& r);
interval& operator-= (const T& r);
interval& operator-= (const interval& r);
interval& operator*= (const T& r);
interval& operator*= (const interval& r);
interval& operator/= (const T& r);
interval& operator/= (const interval& r);
static interval empty();
static interval whole();
static interval hull(const T &x, const T &y);
bool operator< (const interval_holder& r) const;
bool operator> (const interval_holder& r) const;
bool operator<= (const interval_holder& r) const;
bool operator>= (const interval_holder& r) const;
bool operator== (const interval_holder& r) const;
bool operator!= (const interval_holder& r) const;
interval &operator+=(const T &r);
interval &operator+=(const interval &r);
interval &operator-=(const T &r);
interval &operator-=(const interval &r);
interval &operator*=(const T &r);
interval &operator*=(const interval &r);
interval &operator/=(const T &r);
interval &operator/=(const interval &r);
bool operator< (const number_holder& r) const;
bool operator> (const number_holder& r) const;
bool operator<= (const number_holder& r) const;
bool operator>= (const number_holder& r) const;
bool operator== (const number_holder& r) const;
bool operator!= (const number_holder& r) const;
bool operator<(const interval_holder &r) const;
bool operator>(const interval_holder &r) const;
bool operator<=(const interval_holder &r) const;
bool operator>=(const interval_holder &r) const;
bool operator==(const interval_holder &r) const;
bool operator!=(const interval_holder &r) const;
// the following is for internal use only, it is not a published interface
// nevertheless, it's public because friends don't always work correctly.
interval(const T& l, const T& u, bool): low(l), up(u) {}
void set_empty();
void set_whole();
void set(const T& l, const T& u);
bool operator<(const number_holder &r) const;
bool operator>(const number_holder &r) const;
bool operator<=(const number_holder &r) const;
bool operator>=(const number_holder &r) const;
bool operator==(const number_holder &r) const;
bool operator!=(const number_holder &r) const;
// the following is for internal use only, it is not a published interface
// nevertheless, it's public because friends don't always work correctly.
interval(const T &l, const T &u, bool)
: low(l)
, up(u)
{
}
void set_empty();
void set_whole();
void set(const T &l, const T &u);
private:
struct interval_holder {
template<class Policies2>
interval_holder(const interval<T, Policies2>& r)
: low(r.lower()), up(r.upper())
struct interval_holder
{
typedef typename Policies2::checking checking2;
if (checking2::is_empty(low, up))
throw interval_lib::comparison_error();
}
template <class Policies2>
interval_holder(const interval<T, Policies2> &r)
: low(r.lower())
, up(r.upper())
{
typedef typename Policies2::checking checking2;
if (checking2::is_empty(low, up))
throw interval_lib::comparison_error();
}
const T& low;
const T& up;
};
const T &low;
const T &up;
};
struct number_holder {
number_holder(const T& r) : val(r)
struct number_holder
{
typedef typename Policies::checking checking;
if (checking::is_nan(r))
throw interval_lib::comparison_error();
}
const T& val;
};
number_holder(const T &r)
: val(r)
{
typedef typename Policies::checking checking;
if (checking::is_nan(r))
throw interval_lib::comparison_error();
}
typedef typename Policies::checking checking;
typedef typename Policies::rounding rounding;
const T &val;
};
T low;
T up;
typedef typename Policies::checking checking;
typedef typename Policies::rounding rounding;
T low;
T up;
};
template<class T, class Policies> inline
interval<T, Policies>::interval():
low(static_cast<T>(0)), up(static_cast<T>(0))
{}
template<class T, class Policies> inline
interval<T, Policies>::interval(T const &v): low(v), up(v)
template <class T, class Policies>
inline interval<T, Policies>::interval()
: low(static_cast<T>(0))
, up(static_cast<T>(0))
{
if (checking::is_nan(v)) set_empty();
}
template<class T, class Policies> template<class T1> inline
interval<T, Policies>::interval(T1 const &v)
template <class T, class Policies>
inline interval<T, Policies>::interval(T const &v)
: low(v)
, up(v)
{
if (checking::is_nan(v)) set_empty();
else {
rounding rnd;
low = rnd.conv_down(v);
up = rnd.conv_up (v);
}
if (checking::is_nan(v))
set_empty();
}
template<class T, class Policies> template<class T1, class T2> inline
interval<T, Policies>::interval(T1 const &l, T2 const &u)
template <class T, class Policies> template <class T1> inline interval<T, Policies>::interval(T1 const &v)
{
if (checking::is_nan(l) || checking::is_nan(u) || !(l <= u)) set_empty();
else {
rounding rnd;
low = rnd.conv_down(l);
up = rnd.conv_up (u);
}
if (checking::is_nan(v))
set_empty();
else {
rounding rnd;
low = rnd.conv_down(v);
up = rnd.conv_up(v);
}
}
template<class T, class Policies> inline
interval<T, Policies>::interval(T const &l, T const &u): low(l), up(u)
template <class T, class Policies>
template <class T1, class T2>
inline interval<T, Policies>::interval(T1 const &l, T2 const &u)
{
if (checking::is_nan(l) || checking::is_nan(u) || !(l <= u))
set_empty();
if (checking::is_nan(l) || checking::is_nan(u) || !(l <= u))
set_empty();
else {
rounding rnd;
low = rnd.conv_down(l);
up = rnd.conv_up(u);
}
}
template <class T, class Policies>
inline interval<T, Policies>::interval(T const &l, T const &u)
: low(l)
, up(u)
{
if (checking::is_nan(l) || checking::is_nan(u) || !(l <= u))
set_empty();
}
template<class T, class Policies> inline
interval<T, Policies>::interval(interval<T, Policies> const &r): low(r.lower()), up(r.upper())
{}
template<class T, class Policies> template<class Policies1> inline
interval<T, Policies>::interval(interval<T, Policies1> const &r): low(r.lower()), up(r.upper())
template <class T, class Policies>
inline interval<T, Policies>::interval(interval<T, Policies> const &r)
: low(r.lower())
, up(r.upper())
{
typedef typename Policies1::checking checking1;
if (checking1::is_empty(r.lower(), r.upper())) set_empty();
}
template<class T, class Policies> template<class T1, class Policies1> inline
interval<T, Policies>::interval(interval<T1, Policies1> const &r)
template <class T, class Policies>
template <class Policies1>
inline interval<T, Policies>::interval(interval<T, Policies1> const &r)
: low(r.lower())
, up(r.upper())
{
typedef typename Policies1::checking checking1;
if (checking1::is_empty(r.lower(), r.upper())) set_empty();
else {
rounding rnd;
low = rnd.conv_down(r.lower());
up = rnd.conv_up (r.upper());
}
typedef typename Policies1::checking checking1;
if (checking1::is_empty(r.lower(), r.upper()))
set_empty();
}
template<class T, class Policies> inline
interval<T, Policies> &interval<T, Policies>::operator=(T const &v)
template <class T, class Policies>
template <class T1, class Policies1>
inline interval<T, Policies>::interval(interval<T1, Policies1> const &r)
{
if (checking::is_nan(v)) set_empty();
else low = up = v;
return *this;
typedef typename Policies1::checking checking1;
if (checking1::is_empty(r.lower(), r.upper()))
set_empty();
else {
rounding rnd;
low = rnd.conv_down(r.lower());
up = rnd.conv_up(r.upper());
}
}
template<class T, class Policies> template<class T1> inline
interval<T, Policies> &interval<T, Policies>::operator=(T1 const &v)
template <class T, class Policies> inline interval<T, Policies> &interval<T, Policies>::operator=(T const &v)
{
if (checking::is_nan(v)) set_empty();
else {
rounding rnd;
low = rnd.conv_down(v);
up = rnd.conv_up (v);
}
return *this;
if (checking::is_nan(v))
set_empty();
else
low = up = v;
return *this;
}
template<class T, class Policies> inline
interval<T, Policies> &interval<T, Policies>::operator=(interval<T, Policies> const &r)
template <class T, class Policies>
template <class T1>
inline interval<T, Policies> &interval<T, Policies>::operator=(T1 const &v)
{
low = r.lower();
up = r.upper();
return *this;
if (checking::is_nan(v))
set_empty();
else {
rounding rnd;
low = rnd.conv_down(v);
up = rnd.conv_up(v);
}
return *this;
}
template<class T, class Policies> template<class Policies1> inline
interval<T, Policies> &interval<T, Policies>::operator=(interval<T, Policies1> const &r)
template <class T, class Policies>
inline interval<T, Policies> &interval<T, Policies>::operator=(interval<T, Policies> const &r)
{
typedef typename Policies1::checking checking1;
if (checking1::is_empty(r.lower(), r.upper())) set_empty();
else {
low = r.lower();
up = r.upper();
}
return *this;
return *this;
}
template<class T, class Policies> template<class T1, class Policies1> inline
interval<T, Policies> &interval<T, Policies>::operator=(interval<T1, Policies1> const &r)
template <class T, class Policies>
template <class Policies1>
inline interval<T, Policies> &interval<T, Policies>::operator=(interval<T, Policies1> const &r)
{
typedef typename Policies1::checking checking1;
if (checking1::is_empty(r.lower(), r.upper())) set_empty();
else {
rounding rnd;
low = rnd.conv_down(r.lower());
up = rnd.conv_up (r.upper());
}
return *this;
typedef typename Policies1::checking checking1;
if (checking1::is_empty(r.lower(), r.upper()))
set_empty();
else {
low = r.lower();
up = r.upper();
}
return *this;
}
template<class T, class Policies> inline
void interval<T, Policies>::assign(const T& l, const T& u)
template <class T, class Policies>
template <class T1, class Policies1>
inline interval<T, Policies> &interval<T, Policies>::operator=(interval<T1, Policies1> const &r)
{
if (checking::is_nan(l) || checking::is_nan(u) || !(l <= u))
set_empty();
else set(l, u);
typedef typename Policies1::checking checking1;
if (checking1::is_empty(r.lower(), r.upper()))
set_empty();
else {
rounding rnd;
low = rnd.conv_down(r.lower());
up = rnd.conv_up(r.upper());
}
return *this;
}
template<class T, class Policies> inline
void interval<T, Policies>::set(const T& l, const T& u)
template <class T, class Policies> inline void interval<T, Policies>::assign(const T &l, const T &u)
{
low = l;
up = u;
if (checking::is_nan(l) || checking::is_nan(u) || !(l <= u))
set_empty();
else
set(l, u);
}
template<class T, class Policies> inline
void interval<T, Policies>::set_empty()
template <class T, class Policies> inline void interval<T, Policies>::set(const T &l, const T &u)
{
low = checking::empty_lower();
up = checking::empty_upper();
low = l;
up = u;
}
template<class T, class Policies> inline
void interval<T, Policies>::set_whole()
template <class T, class Policies> inline void interval<T, Policies>::set_empty()
{
low = checking::neg_inf();
up = checking::pos_inf();
low = checking::empty_lower();
up = checking::empty_upper();
}
template<class T, class Policies> inline
interval<T, Policies> interval<T, Policies>::hull(const T& x, const T& y)
template <class T, class Policies> inline void interval<T, Policies>::set_whole()
{
bool bad_x = checking::is_nan(x);
bool bad_y = checking::is_nan(y);
if (bad_x)
if (bad_y) return interval::empty();
else return interval(y, y, true);
else
if (bad_y) return interval(x, x, true);
if (x <= y) return interval(x, y, true);
else return interval(y, x, true);
low = checking::neg_inf();
up = checking::pos_inf();
}
template<class T, class Policies> inline
interval<T, Policies> interval<T, Policies>::empty()
template <class T, class Policies> inline interval<T, Policies> interval<T, Policies>::hull(const T &x, const T &y)
{
return interval<T, Policies>(checking::empty_lower(),
checking::empty_upper(), true);
bool bad_x = checking::is_nan(x);
bool bad_y = checking::is_nan(y);
if (bad_x)
if (bad_y)
return interval::empty();
else
return interval(y, y, true);
else if (bad_y)
return interval(x, x, true);
if (x <= y)
return interval(x, y, true);
else
return interval(y, x, true);
}
template<class T, class Policies> inline
interval<T, Policies> interval<T, Policies>::whole()
template <class T, class Policies> inline interval<T, Policies> interval<T, Policies>::empty()
{
return interval<T, Policies>(checking::neg_inf(), checking::pos_inf(), true);
return interval<T, Policies>(checking::empty_lower(), checking::empty_upper(), true);
}
template<class T, class Policies> inline
const T& interval<T, Policies>::lower() const
template <class T, class Policies> inline interval<T, Policies> interval<T, Policies>::whole()
{
return low;
return interval<T, Policies>(checking::neg_inf(), checking::pos_inf(), true);
}
template<class T, class Policies> inline
const T& interval<T, Policies>::upper() const
{
return up;
}
template <class T, class Policies> inline const T &interval<T, Policies>::lower() const { return low; }
template <class T, class Policies> inline const T &interval<T, Policies>::upper() const { return up; }
/*
* interval/interval comparisons
*/
template<class T, class Policies> inline
bool interval<T, Policies>::operator< (const interval_holder& r) const
template <class T, class Policies> inline bool interval<T, Policies>::operator<(const interval_holder &r) const
{
if (!checking::is_empty(low, up)) {
if (up < r.low) return true;
else if (low >= r.up) return false;
}
throw interval_lib::comparison_error();
if (!checking::is_empty(low, up)) {
if (up < r.low)
return true;
else if (low >= r.up)
return false;
}
throw interval_lib::comparison_error();
}
template<class T, class Policies> inline
bool interval<T, Policies>::operator> (const interval_holder& r) const
template <class T, class Policies> inline bool interval<T, Policies>::operator>(const interval_holder &r) const
{
if (!checking::is_empty(low, up)) {
if (low > r.up) return true;
else if (up <= r.low) return false;
}
throw interval_lib::comparison_error();
if (!checking::is_empty(low, up)) {
if (low > r.up)
return true;
else if (up <= r.low)
return false;
}
throw interval_lib::comparison_error();
}
template<class T, class Policies> inline
bool interval<T, Policies>::operator<= (const interval_holder& r) const
template <class T, class Policies> inline bool interval<T, Policies>::operator<=(const interval_holder &r) const
{
if (!checking::is_empty(low, up)) {
if (up <= r.low) return true;
else if (low > r.up) return false;
}
throw interval_lib::comparison_error();
if (!checking::is_empty(low, up)) {
if (up <= r.low)
return true;
else if (low > r.up)
return false;
}
throw interval_lib::comparison_error();
}
template<class T, class Policies> inline
bool interval<T, Policies>::operator>= (const interval_holder& r) const
template <class T, class Policies> inline bool interval<T, Policies>::operator>=(const interval_holder &r) const
{
if (!checking::is_empty(low, up)) {
if (low >= r.up) return true;
else if (up < r.low) return false;
}
throw interval_lib::comparison_error();
if (!checking::is_empty(low, up)) {
if (low >= r.up)
return true;
else if (up < r.low)
return false;
}
throw interval_lib::comparison_error();
}
template<class T, class Policies> inline
bool interval<T, Policies>::operator== (const interval_holder& r) const
template <class T, class Policies> inline bool interval<T, Policies>::operator==(const interval_holder &r) const
{
if (!checking::is_empty(low, up)) {
if (up == r.low && low == r.up) return true;
else if (up < r.low || low > r.up) return false;
}
throw interval_lib::comparison_error();
if (!checking::is_empty(low, up)) {
if (up == r.low && low == r.up)
return true;
else if (up < r.low || low > r.up)
return false;
}
throw interval_lib::comparison_error();
}
template<class T, class Policies> inline
bool interval<T, Policies>::operator!= (const interval_holder& r) const
template <class T, class Policies> inline bool interval<T, Policies>::operator!=(const interval_holder &r) const
{
if (!checking::is_empty(low, up)) {
if (up < r.low || low > r.up) return true;
else if (up == r.low && low == r.up) return false;
}
throw interval_lib::comparison_error();
if (!checking::is_empty(low, up)) {
if (up < r.low || low > r.up)
return true;
else if (up == r.low && low == r.up)
return false;
}
throw interval_lib::comparison_error();
}
/*
* interval/number comparisons
*/
template<class T, class Policies> inline
bool interval<T, Policies>::operator< (const number_holder& r) const
template <class T, class Policies> inline bool interval<T, Policies>::operator<(const number_holder &r) const
{
if (!checking::is_empty(low, up)) {
if (up < r.val) return true;
else if (low >= r.val) return false;
}
throw interval_lib::comparison_error();
if (!checking::is_empty(low, up)) {
if (up < r.val)
return true;
else if (low >= r.val)
return false;
}
throw interval_lib::comparison_error();
}
template<class T, class Policies> inline
bool interval<T, Policies>::operator> (const number_holder& r) const
template <class T, class Policies> inline bool interval<T, Policies>::operator>(const number_holder &r) const
{
if (!checking::is_empty(low, up)) {
if (low > r.val) return true;
else if (up <= r.val) return false;
}
throw interval_lib::comparison_error();
if (!checking::is_empty(low, up)) {
if (low > r.val)
return true;
else if (up <= r.val)
return false;
}
throw interval_lib::comparison_error();
}
template<class T, class Policies> inline
bool interval<T, Policies>::operator<= (const number_holder& r) const
template <class T, class Policies> inline bool interval<T, Policies>::operator<=(const number_holder &r) const
{
if (!checking::is_empty(low, up)) {
if (up <= r.val) return true;
else if (low > r.val) return false;
}
throw interval_lib::comparison_error();
if (!checking::is_empty(low, up)) {
if (up <= r.val)
return true;
else if (low > r.val)
return false;
}
throw interval_lib::comparison_error();
}
template<class T, class Policies> inline
bool interval<T, Policies>::operator>= (const number_holder& r) const
template <class T, class Policies> inline bool interval<T, Policies>::operator>=(const number_holder &r) const
{
if (!checking::is_empty(low, up)) {
if (low >= r.val) return true;
else if (up < r.val) return false;
}
throw interval_lib::comparison_error();
if (!checking::is_empty(low, up)) {
if (low >= r.val)
return true;
else if (up < r.val)
return false;
}
throw interval_lib::comparison_error();
}
template<class T, class Policies> inline
bool interval<T, Policies>::operator== (const number_holder& r) const
template <class T, class Policies> inline bool interval<T, Policies>::operator==(const number_holder &r) const
{
if (!checking::is_empty(low, up)) {
if (up == r.val && low == r.val) return true;
else if (up < r.val || low > r.val) return false;
}
throw interval_lib::comparison_error();
if (!checking::is_empty(low, up)) {
if (up == r.val && low == r.val)
return true;
else if (up < r.val || low > r.val)
return false;
}
throw interval_lib::comparison_error();
}
template<class T, class Policies> inline
bool interval<T, Policies>::operator!= (const number_holder& r) const
template <class T, class Policies> inline bool interval<T, Policies>::operator!=(const number_holder &r) const
{
if (!checking::is_empty(low, up)) {
if (up < r.val || low > r.val) return true;
else if (up == r.val && low == r.val) return false;
}
throw interval_lib::comparison_error();
if (!checking::is_empty(low, up)) {
if (up < r.val || low > r.val)
return true;
else if (up == r.val && low == r.val)
return false;
}
throw interval_lib::comparison_error();
}
} // namespace numeric

View File

@@ -24,15 +24,14 @@
namespace boost {
namespace numeric {
template<class CharType, class CharTraits, class T, class Policies>
std::basic_ostream<CharType, CharTraits> &operator<<
(std::basic_ostream<CharType, CharTraits> &stream,
interval<T, Policies> const &value)
template <class CharType, class CharTraits, class T, class Policies>
std::basic_ostream<CharType, CharTraits> &operator<<(std::basic_ostream<CharType, CharTraits> &stream,
interval<T, Policies> const &value)
{
if (empty(value))
return stream << "[]";
else
return stream << '[' << lower(value) << ',' << upper(value) << ']';
if (empty(value))
return stream << "[]";
else
return stream << '[' << lower(value) << ',' << upper(value) << ']';
}
} // namespace numeric

View File

@@ -19,29 +19,28 @@
namespace std {
template<class T, class Policies>
class numeric_limits<boost::numeric::interval<T, Policies> >
: public numeric_limits<T>
template <class T, class Policies>
class numeric_limits<boost::numeric::interval<T, Policies>> : public numeric_limits<T>
{
private:
typedef boost::numeric::interval<T, Policies> I;
typedef numeric_limits<T> bl;
typedef boost::numeric::interval<T, Policies> I;
typedef numeric_limits<T> bl;
public:
static I min BOOST_PREVENT_MACRO_SUBSTITUTION () throw() { return I((bl::min)(), (bl::min)()); }
static I max BOOST_PREVENT_MACRO_SUBSTITUTION () throw() { return I((bl::max)(), (bl::max)()); }
static I epsilon() throw() { return I(bl::epsilon(), bl::epsilon()); }
static I min BOOST_PREVENT_MACRO_SUBSTITUTION() throw() { return I((bl::min)(), (bl::min)()); }
static I max BOOST_PREVENT_MACRO_SUBSTITUTION() throw() { return I((bl::max)(), (bl::max)()); }
static I epsilon() throw() { return I(bl::epsilon(), bl::epsilon()); }
BOOST_STATIC_CONSTANT(float_round_style, round_style = round_indeterminate);
BOOST_STATIC_CONSTANT(bool, is_iec559 = false);
BOOST_STATIC_CONSTANT(float_round_style, round_style = round_indeterminate);
BOOST_STATIC_CONSTANT(bool, is_iec559 = false);
static I infinity() throw() { return I::whole(); }
static I quiet_NaN() throw() { return I::empty(); }
static I signaling_NaN() throw() { return I(bl::signaling_NaN(), bl::signaling_Nan()); }
static I denorm_min() throw() { return I(bl::denorm_min(), bl::denorm_min()); }
static I infinity () throw() { return I::whole(); }
static I quiet_NaN() throw() { return I::empty(); }
static I signaling_NaN() throw()
{ return I(bl::signaling_NaN(), bl::signaling_Nan()); }
static I denorm_min() throw()
{ return I(bl::denorm_min(), bl::denorm_min()); }
private:
static I round_error(); // hide this on purpose, not yet implemented
static I round_error(); // hide this on purpose, not yet implemented
};
} // namespace std

View File

@@ -20,35 +20,34 @@ namespace interval_lib {
* policies class
*/
template<class Rounding, class Checking>
struct policies
template <class Rounding, class Checking> struct policies
{
typedef Rounding rounding;
typedef Checking checking;
typedef Rounding rounding;
typedef Checking checking;
};
/*
* policies switching classes
*/
template<class OldInterval, class NewRounding>
class change_rounding
template <class OldInterval, class NewRounding> class change_rounding
{
typedef typename OldInterval::base_type T;
typedef typename OldInterval::traits_type p;
typedef typename p::checking checking;
typedef typename OldInterval::base_type T;
typedef typename OldInterval::traits_type p;
typedef typename p::checking checking;
public:
typedef interval<T, policies<NewRounding, checking> > type;
typedef interval<T, policies<NewRounding, checking>> type;
};
template<class OldInterval, class NewChecking>
class change_checking
template <class OldInterval, class NewChecking> class change_checking
{
typedef typename OldInterval::base_type T;
typedef typename OldInterval::traits_type p;
typedef typename p::rounding rounding;
typedef typename OldInterval::base_type T;
typedef typename OldInterval::traits_type p;
typedef typename p::rounding rounding;
public:
typedef interval<T, policies<rounding, NewChecking> > type;
typedef interval<T, policies<rounding, NewChecking>> type;
};
/*
@@ -56,15 +55,15 @@ public:
* at each operation, rather than once and for all.
*/
template<class OldInterval>
class unprotect
template <class OldInterval> class unprotect
{
typedef typename OldInterval::base_type T;
typedef typename OldInterval::traits_type p;
typedef typename p::rounding r;
typedef typename r::unprotected_rounding newRounding;
typedef typename OldInterval::base_type T;
typedef typename OldInterval::traits_type p;
typedef typename p::rounding r;
typedef typename r::unprotected_rounding newRounding;
public:
typedef typename change_rounding<OldInterval, newRounding>::type type;
typedef typename change_rounding<OldInterval, newRounding>::type type;
};
} // namespace interval_lib

View File

@@ -10,9 +10,9 @@
#ifndef BOOST_NUMERIC_INTERVAL_ROUNDED_ARITH_HPP
#define BOOST_NUMERIC_INTERVAL_ROUNDED_ARITH_HPP
#include <boost/numeric/interval/rounding.hpp>
#include <boost/numeric/interval/detail/bugs.hpp>
#include <boost/config/no_tr1/cmath.hpp>
#include <boost/numeric/interval/detail/bugs.hpp>
#include <boost/numeric/interval/rounding.hpp>
namespace boost {
namespace numeric {
@@ -23,94 +23,132 @@ namespace interval_lib {
* See documentation for details.
*/
template<class T, class Rounding>
struct rounded_arith_exact: Rounding {
void init() { }
template<class U> T conv_down(U const &v) { return v; }
template<class U> T conv_up (U const &v) { return v; }
T add_down (const T& x, const T& y) { return x + y; }
T add_up (const T& x, const T& y) { return x + y; }
T sub_down (const T& x, const T& y) { return x - y; }
T sub_up (const T& x, const T& y) { return x - y; }
T mul_down (const T& x, const T& y) { return x * y; }
T mul_up (const T& x, const T& y) { return x * y; }
T div_down (const T& x, const T& y) { return x / y; }
T div_up (const T& x, const T& y) { return x / y; }
T median (const T& x, const T& y) { return (x + y) / 2; }
T sqrt_down(const T& x)
{ BOOST_NUMERIC_INTERVAL_using_math(sqrt); return sqrt(x); }
T sqrt_up (const T& x)
{ BOOST_NUMERIC_INTERVAL_using_math(sqrt); return sqrt(x); }
T int_down (const T& x)
{ BOOST_NUMERIC_INTERVAL_using_math(floor); return floor(x); }
T int_up (const T& x)
{ BOOST_NUMERIC_INTERVAL_using_math(ceil); return ceil(x); }
template <class T, class Rounding> struct rounded_arith_exact : Rounding
{
void init() {}
template <class U> T conv_down(U const &v) { return v; }
template <class U> T conv_up(U const &v) { return v; }
T add_down(const T &x, const T &y) { return x + y; }
T add_up(const T &x, const T &y) { return x + y; }
T sub_down(const T &x, const T &y) { return x - y; }
T sub_up(const T &x, const T &y) { return x - y; }
T mul_down(const T &x, const T &y) { return x * y; }
T mul_up(const T &x, const T &y) { return x * y; }
T div_down(const T &x, const T &y) { return x / y; }
T div_up(const T &x, const T &y) { return x / y; }
T median(const T &x, const T &y) { return (x + y) / 2; }
T sqrt_down(const T &x)
{
BOOST_NUMERIC_INTERVAL_using_math(sqrt);
return sqrt(x);
}
T sqrt_up(const T &x)
{
BOOST_NUMERIC_INTERVAL_using_math(sqrt);
return sqrt(x);
}
T int_down(const T &x)
{
BOOST_NUMERIC_INTERVAL_using_math(floor);
return floor(x);
}
T int_up(const T &x)
{
BOOST_NUMERIC_INTERVAL_using_math(ceil);
return ceil(x);
}
};
template<class T, class Rounding>
struct rounded_arith_std: Rounding {
# define BOOST_DN(EXPR) this->downward(); return this->force_rounding(EXPR)
# define BOOST_NR(EXPR) this->to_nearest(); return this->force_rounding(EXPR)
# define BOOST_UP(EXPR) this->upward(); return this->force_rounding(EXPR)
void init() { }
template<class U> T conv_down(U const &v) { BOOST_DN(v); }
template<class U> T conv_up (U const &v) { BOOST_UP(v); }
T add_down(const T& x, const T& y) { BOOST_DN(x + y); }
T sub_down(const T& x, const T& y) { BOOST_DN(x - y); }
T mul_down(const T& x, const T& y) { BOOST_DN(x * y); }
T div_down(const T& x, const T& y) { BOOST_DN(x / y); }
T add_up (const T& x, const T& y) { BOOST_UP(x + y); }
T sub_up (const T& x, const T& y) { BOOST_UP(x - y); }
T mul_up (const T& x, const T& y) { BOOST_UP(x * y); }
T div_up (const T& x, const T& y) { BOOST_UP(x / y); }
T median(const T& x, const T& y) { BOOST_NR((x + y) / 2); }
T sqrt_down(const T& x)
{ BOOST_NUMERIC_INTERVAL_using_math(sqrt); BOOST_DN(sqrt(x)); }
T sqrt_up (const T& x)
{ BOOST_NUMERIC_INTERVAL_using_math(sqrt); BOOST_UP(sqrt(x)); }
T int_down(const T& x) { this->downward(); return to_int(x); }
T int_up (const T& x) { this->upward(); return to_int(x); }
# undef BOOST_DN
# undef BOOST_NR
# undef BOOST_UP
};
template<class T, class Rounding>
struct rounded_arith_opp: Rounding {
void init() { this->upward(); }
# define BOOST_DN(EXPR) \
this->downward(); \
T r = this->force_rounding(EXPR); \
this->upward(); \
return r
# define BOOST_NR(EXPR) \
template <class T, class Rounding> struct rounded_arith_std : Rounding
{
#define BOOST_DN(EXPR) \
this->downward(); \
return this->force_rounding(EXPR)
#define BOOST_NR(EXPR) \
this->to_nearest(); \
return this->force_rounding(EXPR)
#define BOOST_UP(EXPR) \
this->upward(); \
return this->force_rounding(EXPR)
void init() {}
template <class U> T conv_down(U const &v) { BOOST_DN(v); }
template <class U> T conv_up(U const &v) { BOOST_UP(v); }
T add_down(const T &x, const T &y) { BOOST_DN(x + y); }
T sub_down(const T &x, const T &y) { BOOST_DN(x - y); }
T mul_down(const T &x, const T &y) { BOOST_DN(x * y); }
T div_down(const T &x, const T &y) { BOOST_DN(x / y); }
T add_up(const T &x, const T &y) { BOOST_UP(x + y); }
T sub_up(const T &x, const T &y) { BOOST_UP(x - y); }
T mul_up(const T &x, const T &y) { BOOST_UP(x * y); }
T div_up(const T &x, const T &y) { BOOST_UP(x / y); }
T median(const T &x, const T &y) { BOOST_NR((x + y) / 2); }
T sqrt_down(const T &x)
{
BOOST_NUMERIC_INTERVAL_using_math(sqrt);
BOOST_DN(sqrt(x));
}
T sqrt_up(const T &x)
{
BOOST_NUMERIC_INTERVAL_using_math(sqrt);
BOOST_UP(sqrt(x));
}
T int_down(const T &x)
{
this->downward();
return to_int(x);
}
T int_up(const T &x)
{
this->upward();
return to_int(x);
}
#undef BOOST_DN
#undef BOOST_NR
#undef BOOST_UP
};
template <class T, class Rounding> struct rounded_arith_opp : Rounding
{
void init() { this->upward(); }
#define BOOST_DN(EXPR) \
this->downward(); \
T r = this->force_rounding(EXPR); \
this->upward(); \
this->upward(); \
return r
# define BOOST_UP(EXPR) return this->force_rounding(EXPR)
# define BOOST_UP_NEG(EXPR) return -this->force_rounding(EXPR)
template<class U> T conv_down(U const &v) { BOOST_UP_NEG(-v); }
template<class U> T conv_up (U const &v) { BOOST_UP(v); }
T add_down(const T& x, const T& y) { BOOST_UP_NEG((-x) - y); }
T sub_down(const T& x, const T& y) { BOOST_UP_NEG(y - x); }
T mul_down(const T& x, const T& y) { BOOST_UP_NEG(x * (-y)); }
T div_down(const T& x, const T& y) { BOOST_UP_NEG(x / (-y)); }
T add_up (const T& x, const T& y) { BOOST_UP(x + y); }
T sub_up (const T& x, const T& y) { BOOST_UP(x - y); }
T mul_up (const T& x, const T& y) { BOOST_UP(x * y); }
T div_up (const T& x, const T& y) { BOOST_UP(x / y); }
T median (const T& x, const T& y) { BOOST_NR((x + y) / 2); }
T sqrt_down(const T& x)
{ BOOST_NUMERIC_INTERVAL_using_math(sqrt); BOOST_DN(sqrt(x)); }
T sqrt_up (const T& x)
{ BOOST_NUMERIC_INTERVAL_using_math(sqrt); BOOST_UP(sqrt(x)); }
T int_down(const T& x) { return -to_int(-x); }
T int_up (const T& x) { return to_int(x); }
# undef BOOST_DN
# undef BOOST_NR
# undef BOOST_UP
# undef BOOST_UP_NEG
#define BOOST_NR(EXPR) \
this->to_nearest(); \
T r = this->force_rounding(EXPR); \
this->upward(); \
return r
#define BOOST_UP(EXPR) return this->force_rounding(EXPR)
#define BOOST_UP_NEG(EXPR) return -this->force_rounding(EXPR)
template <class U> T conv_down(U const &v) { BOOST_UP_NEG(-v); }
template <class U> T conv_up(U const &v) { BOOST_UP(v); }
T add_down(const T &x, const T &y) { BOOST_UP_NEG((-x) - y); }
T sub_down(const T &x, const T &y) { BOOST_UP_NEG(y - x); }
T mul_down(const T &x, const T &y) { BOOST_UP_NEG(x * (-y)); }
T div_down(const T &x, const T &y) { BOOST_UP_NEG(x / (-y)); }
T add_up(const T &x, const T &y) { BOOST_UP(x + y); }
T sub_up(const T &x, const T &y) { BOOST_UP(x - y); }
T mul_up(const T &x, const T &y) { BOOST_UP(x * y); }
T div_up(const T &x, const T &y) { BOOST_UP(x / y); }
T median(const T &x, const T &y) { BOOST_NR((x + y) / 2); }
T sqrt_down(const T &x)
{
BOOST_NUMERIC_INTERVAL_using_math(sqrt);
BOOST_DN(sqrt(x));
}
T sqrt_up(const T &x)
{
BOOST_NUMERIC_INTERVAL_using_math(sqrt);
BOOST_UP(sqrt(x));
}
T int_down(const T &x) { return -to_int(-x); }
T int_up(const T &x) { return to_int(x); }
#undef BOOST_DN
#undef BOOST_NR
#undef BOOST_UP
#undef BOOST_UP_NEG
};
} // namespace interval_lib

View File

@@ -10,129 +10,153 @@
#ifndef BOOST_NUMERIC_INTERVAL_ROUNDED_TRANSC_HPP
#define BOOST_NUMERIC_INTERVAL_ROUNDED_TRANSC_HPP
#include <boost/numeric/interval/rounding.hpp>
#include <boost/numeric/interval/detail/bugs.hpp>
#include <boost/config/no_tr1/cmath.hpp>
#include <boost/numeric/interval/detail/bugs.hpp>
#include <boost/numeric/interval/rounding.hpp>
namespace boost {
namespace numeric {
namespace interval_lib {
template<class T, class Rounding>
struct rounded_transc_exact: Rounding
template <class T, class Rounding> struct rounded_transc_exact : Rounding
{
# define BOOST_NUMERIC_INTERVAL_new_func(f) \
T f##_down(const T& x) { BOOST_NUMERIC_INTERVAL_using_math(f); return f(x); } \
T f##_up (const T& x) { BOOST_NUMERIC_INTERVAL_using_math(f); return f(x); }
BOOST_NUMERIC_INTERVAL_new_func(exp)
BOOST_NUMERIC_INTERVAL_new_func(log)
BOOST_NUMERIC_INTERVAL_new_func(sin)
BOOST_NUMERIC_INTERVAL_new_func(cos)
BOOST_NUMERIC_INTERVAL_new_func(tan)
BOOST_NUMERIC_INTERVAL_new_func(asin)
BOOST_NUMERIC_INTERVAL_new_func(acos)
BOOST_NUMERIC_INTERVAL_new_func(atan)
BOOST_NUMERIC_INTERVAL_new_func(sinh)
BOOST_NUMERIC_INTERVAL_new_func(cosh)
BOOST_NUMERIC_INTERVAL_new_func(tanh)
# undef BOOST_NUMERIC_INTERVAL_new_func
# define BOOST_NUMERIC_INTERVAL_new_func(f) \
T f##_down(const T& x) { BOOST_NUMERIC_INTERVAL_using_ahyp(f); return f(x); } \
T f##_up (const T& x) { BOOST_NUMERIC_INTERVAL_using_ahyp(f); return f(x); }
BOOST_NUMERIC_INTERVAL_new_func(asinh)
BOOST_NUMERIC_INTERVAL_new_func(acosh)
BOOST_NUMERIC_INTERVAL_new_func(atanh)
# undef BOOST_NUMERIC_INTERVAL_new_func
};
template<class T, class Rounding>
struct rounded_transc_std: Rounding
{
# define BOOST_NUMERIC_INTERVAL_new_func(f) \
T f##_down(const T& x) \
{ BOOST_NUMERIC_INTERVAL_using_math(f); \
this->downward(); return this->force_rounding(f(x)); } \
T f##_up (const T& x) \
{ BOOST_NUMERIC_INTERVAL_using_math(f); \
this->upward(); return this->force_rounding(f(x)); }
BOOST_NUMERIC_INTERVAL_new_func(exp)
BOOST_NUMERIC_INTERVAL_new_func(log)
BOOST_NUMERIC_INTERVAL_new_func(sin)
BOOST_NUMERIC_INTERVAL_new_func(cos)
BOOST_NUMERIC_INTERVAL_new_func(tan)
BOOST_NUMERIC_INTERVAL_new_func(asin)
BOOST_NUMERIC_INTERVAL_new_func(acos)
BOOST_NUMERIC_INTERVAL_new_func(atan)
BOOST_NUMERIC_INTERVAL_new_func(sinh)
BOOST_NUMERIC_INTERVAL_new_func(cosh)
BOOST_NUMERIC_INTERVAL_new_func(tanh)
# undef BOOST_NUMERIC_INTERVAL_new_func
# define BOOST_NUMERIC_INTERVAL_new_func(f) \
T f##_down(const T& x) \
{ BOOST_NUMERIC_INTERVAL_using_ahyp(f); \
this->downward(); return this->force_rounding(f(x)); } \
T f##_up (const T& x) \
{ BOOST_NUMERIC_INTERVAL_using_ahyp(f); \
this->upward(); return this->force_rounding(f(x)); }
BOOST_NUMERIC_INTERVAL_new_func(asinh)
BOOST_NUMERIC_INTERVAL_new_func(acosh)
BOOST_NUMERIC_INTERVAL_new_func(atanh)
# undef BOOST_NUMERIC_INTERVAL_new_func
#define BOOST_NUMERIC_INTERVAL_new_func(f) \
T f##_down(const T &x) \
{ \
BOOST_NUMERIC_INTERVAL_using_math(f); \
return f(x); \
} \
T f##_up(const T &x) \
{ \
BOOST_NUMERIC_INTERVAL_using_math(f); \
return f(x); \
}
BOOST_NUMERIC_INTERVAL_new_func(exp) BOOST_NUMERIC_INTERVAL_new_func(log) BOOST_NUMERIC_INTERVAL_new_func(sin)
BOOST_NUMERIC_INTERVAL_new_func(cos) BOOST_NUMERIC_INTERVAL_new_func(tan) BOOST_NUMERIC_INTERVAL_new_func(asin)
BOOST_NUMERIC_INTERVAL_new_func(acos) BOOST_NUMERIC_INTERVAL_new_func(atan)
BOOST_NUMERIC_INTERVAL_new_func(sinh) BOOST_NUMERIC_INTERVAL_new_func(cosh)
BOOST_NUMERIC_INTERVAL_new_func(tanh)
#undef BOOST_NUMERIC_INTERVAL_new_func
#define BOOST_NUMERIC_INTERVAL_new_func(f) \
T f##_down(const T &x) \
{ \
BOOST_NUMERIC_INTERVAL_using_ahyp(f); \
return f(x); \
} \
T f##_up(const T &x) \
{ \
BOOST_NUMERIC_INTERVAL_using_ahyp(f); \
return f(x); \
}
BOOST_NUMERIC_INTERVAL_new_func(asinh) BOOST_NUMERIC_INTERVAL_new_func(acosh)
BOOST_NUMERIC_INTERVAL_new_func(atanh)
#undef BOOST_NUMERIC_INTERVAL_new_func
};
template<class T, class Rounding>
struct rounded_transc_opp: Rounding
template <class T, class Rounding> struct rounded_transc_std : Rounding
{
# define BOOST_NUMERIC_INTERVAL_new_func(f) \
T f##_down(const T& x) \
{ BOOST_NUMERIC_INTERVAL_using_math(f); \
this->downward(); T y = this->force_rounding(f(x)); \
this->upward(); return y; } \
T f##_up (const T& x) \
{ BOOST_NUMERIC_INTERVAL_using_math(f); \
return this->force_rounding(f(x)); }
BOOST_NUMERIC_INTERVAL_new_func(exp)
BOOST_NUMERIC_INTERVAL_new_func(log)
BOOST_NUMERIC_INTERVAL_new_func(cos)
BOOST_NUMERIC_INTERVAL_new_func(acos)
BOOST_NUMERIC_INTERVAL_new_func(cosh)
# undef BOOST_NUMERIC_INTERVAL_new_func
# define BOOST_NUMERIC_INTERVAL_new_func(f) \
T f##_down(const T& x) \
{ BOOST_NUMERIC_INTERVAL_using_math(f); \
return -this->force_rounding(-f(x)); } \
T f##_up (const T& x) \
{ BOOST_NUMERIC_INTERVAL_using_math(f); \
return this->force_rounding(f(x)); }
BOOST_NUMERIC_INTERVAL_new_func(sin)
BOOST_NUMERIC_INTERVAL_new_func(tan)
BOOST_NUMERIC_INTERVAL_new_func(asin)
BOOST_NUMERIC_INTERVAL_new_func(atan)
BOOST_NUMERIC_INTERVAL_new_func(sinh)
BOOST_NUMERIC_INTERVAL_new_func(tanh)
# undef BOOST_NUMERIC_INTERVAL_new_func
# define BOOST_NUMERIC_INTERVAL_new_func(f) \
T f##_down(const T& x) \
{ BOOST_NUMERIC_INTERVAL_using_ahyp(f); \
this->downward(); T y = this->force_rounding(f(x)); \
this->upward(); return y; } \
T f##_up (const T& x) \
{ BOOST_NUMERIC_INTERVAL_using_ahyp(f); \
return this->force_rounding(f(x)); }
BOOST_NUMERIC_INTERVAL_new_func(asinh)
BOOST_NUMERIC_INTERVAL_new_func(atanh)
# undef BOOST_NUMERIC_INTERVAL_new_func
# define BOOST_NUMERIC_INTERVAL_new_func(f) \
T f##_down(const T& x) \
{ BOOST_NUMERIC_INTERVAL_using_ahyp(f); \
return -this->force_rounding(-f(x)); } \
T f##_up (const T& x) \
{ BOOST_NUMERIC_INTERVAL_using_ahyp(f); \
return this->force_rounding(f(x)); }
BOOST_NUMERIC_INTERVAL_new_func(acosh)
# undef BOOST_NUMERIC_INTERVAL_new_func
#define BOOST_NUMERIC_INTERVAL_new_func(f) \
T f##_down(const T &x) \
{ \
BOOST_NUMERIC_INTERVAL_using_math(f); \
this->downward(); \
return this->force_rounding(f(x)); \
} \
T f##_up(const T &x) \
{ \
BOOST_NUMERIC_INTERVAL_using_math(f); \
this->upward(); \
return this->force_rounding(f(x)); \
}
BOOST_NUMERIC_INTERVAL_new_func(exp) BOOST_NUMERIC_INTERVAL_new_func(log) BOOST_NUMERIC_INTERVAL_new_func(sin)
BOOST_NUMERIC_INTERVAL_new_func(cos) BOOST_NUMERIC_INTERVAL_new_func(tan) BOOST_NUMERIC_INTERVAL_new_func(asin)
BOOST_NUMERIC_INTERVAL_new_func(acos) BOOST_NUMERIC_INTERVAL_new_func(atan)
BOOST_NUMERIC_INTERVAL_new_func(sinh) BOOST_NUMERIC_INTERVAL_new_func(cosh)
BOOST_NUMERIC_INTERVAL_new_func(tanh)
#undef BOOST_NUMERIC_INTERVAL_new_func
#define BOOST_NUMERIC_INTERVAL_new_func(f) \
T f##_down(const T &x) \
{ \
BOOST_NUMERIC_INTERVAL_using_ahyp(f); \
this->downward(); \
return this->force_rounding(f(x)); \
} \
T f##_up(const T &x) \
{ \
BOOST_NUMERIC_INTERVAL_using_ahyp(f); \
this->upward(); \
return this->force_rounding(f(x)); \
}
BOOST_NUMERIC_INTERVAL_new_func(asinh) BOOST_NUMERIC_INTERVAL_new_func(acosh)
BOOST_NUMERIC_INTERVAL_new_func(atanh)
#undef BOOST_NUMERIC_INTERVAL_new_func
};
template <class T, class Rounding> struct rounded_transc_opp : Rounding
{
#define BOOST_NUMERIC_INTERVAL_new_func(f) \
T f##_down(const T &x) \
{ \
BOOST_NUMERIC_INTERVAL_using_math(f); \
this->downward(); \
T y = this->force_rounding(f(x)); \
this->upward(); \
return y; \
} \
T f##_up(const T &x) \
{ \
BOOST_NUMERIC_INTERVAL_using_math(f); \
return this->force_rounding(f(x)); \
}
BOOST_NUMERIC_INTERVAL_new_func(exp) BOOST_NUMERIC_INTERVAL_new_func(log) BOOST_NUMERIC_INTERVAL_new_func(cos)
BOOST_NUMERIC_INTERVAL_new_func(acos) BOOST_NUMERIC_INTERVAL_new_func(cosh)
#undef BOOST_NUMERIC_INTERVAL_new_func
#define BOOST_NUMERIC_INTERVAL_new_func(f) \
T f##_down(const T &x) \
{ \
BOOST_NUMERIC_INTERVAL_using_math(f); \
return -this->force_rounding(-f(x)); \
} \
T f##_up(const T &x) \
{ \
BOOST_NUMERIC_INTERVAL_using_math(f); \
return this->force_rounding(f(x)); \
}
BOOST_NUMERIC_INTERVAL_new_func(sin) BOOST_NUMERIC_INTERVAL_new_func(tan)
BOOST_NUMERIC_INTERVAL_new_func(asin) BOOST_NUMERIC_INTERVAL_new_func(atan)
BOOST_NUMERIC_INTERVAL_new_func(sinh) BOOST_NUMERIC_INTERVAL_new_func(tanh)
#undef BOOST_NUMERIC_INTERVAL_new_func
#define BOOST_NUMERIC_INTERVAL_new_func(f) \
T f##_down(const T &x) \
{ \
BOOST_NUMERIC_INTERVAL_using_ahyp(f); \
this->downward(); \
T y = this->force_rounding(f(x)); \
this->upward(); \
return y; \
} \
T f##_up(const T &x) \
{ \
BOOST_NUMERIC_INTERVAL_using_ahyp(f); \
return this->force_rounding(f(x)); \
}
BOOST_NUMERIC_INTERVAL_new_func(asinh) BOOST_NUMERIC_INTERVAL_new_func(atanh)
#undef BOOST_NUMERIC_INTERVAL_new_func
#define BOOST_NUMERIC_INTERVAL_new_func(f) \
T f##_down(const T &x) \
{ \
BOOST_NUMERIC_INTERVAL_using_ahyp(f); \
return -this->force_rounding(-f(x)); \
} \
T f##_up(const T &x) \
{ \
BOOST_NUMERIC_INTERVAL_using_ahyp(f); \
return this->force_rounding(f(x)); \
}
BOOST_NUMERIC_INTERVAL_new_func(acosh)
#undef BOOST_NUMERIC_INTERVAL_new_func
};
} // namespace interval_lib
} // namespace numeric
} // namespace boost

View File

@@ -18,17 +18,16 @@ namespace interval_lib {
* Default rounding_control class (does nothing)
*/
template<class T>
struct rounding_control
template <class T> struct rounding_control
{
typedef int rounding_mode;
static void get_rounding_mode(rounding_mode&) {}
static void set_rounding_mode(rounding_mode) {}
static void upward() {}
static void downward() {}
static void to_nearest() {}
static const T& to_int(const T& x) { return x; }
static const T& force_rounding(const T& x) { return x; }
typedef int rounding_mode;
static void get_rounding_mode(rounding_mode &) {}
static void set_rounding_mode(rounding_mode) {}
static void upward() {}
static void downward() {}
static void to_nearest() {}
static const T &to_int(const T &x) { return x; }
static const T &force_rounding(const T &x) { return x; }
};
/*
@@ -37,26 +36,19 @@ struct rounding_control
* rounded_transc_* control the rounding of the transcendental functions
*/
template<class T, class Rounding = rounding_control<T> >
struct rounded_arith_exact;
template <class T, class Rounding = rounding_control<T>> struct rounded_arith_exact;
template<class T, class Rounding = rounding_control<T> >
struct rounded_arith_std;
template <class T, class Rounding = rounding_control<T>> struct rounded_arith_std;
template<class T, class Rounding = rounding_control<T> >
struct rounded_arith_opp;
template <class T, class Rounding = rounding_control<T>> struct rounded_arith_opp;
template<class T, class Rounding>
struct rounded_transc_dummy;
template <class T, class Rounding> struct rounded_transc_dummy;
template<class T, class Rounding = rounded_arith_exact<T> >
struct rounded_transc_exact;
template <class T, class Rounding = rounded_arith_exact<T>> struct rounded_transc_exact;
template<class T, class Rounding = rounded_arith_std<T> >
struct rounded_transc_std;
template <class T, class Rounding = rounded_arith_std<T>> struct rounded_transc_std;
template<class T, class Rounding = rounded_arith_opp<T> >
struct rounded_transc_opp;
template <class T, class Rounding = rounded_arith_opp<T>> struct rounded_transc_opp;
/*
* State-saving classes: allow to set and reset rounding control
@@ -64,35 +56,33 @@ struct rounded_transc_opp;
namespace detail {
template<class Rounding>
struct save_state_unprotected: Rounding
template <class Rounding> struct save_state_unprotected : Rounding
{
typedef save_state_unprotected<Rounding> unprotected_rounding;
typedef save_state_unprotected<Rounding> unprotected_rounding;
};
} // namespace detail
template<class Rounding>
struct save_state: Rounding
template <class Rounding> struct save_state : Rounding
{
typename Rounding::rounding_mode mode;
save_state() {
this->get_rounding_mode(mode);
this->init();
}
~save_state() { this->set_rounding_mode(mode); }
typedef detail::save_state_unprotected<Rounding> unprotected_rounding;
typename Rounding::rounding_mode mode;
save_state()
{
this->get_rounding_mode(mode);
this->init();
}
~save_state() { this->set_rounding_mode(mode); }
typedef detail::save_state_unprotected<Rounding> unprotected_rounding;
};
template<class Rounding>
struct save_state_nothing: Rounding
template <class Rounding> struct save_state_nothing : Rounding
{
typedef save_state_nothing<Rounding> unprotected_rounding;
};
template <class T> struct rounded_math : save_state_nothing<rounded_arith_exact<T>>
{
typedef save_state_nothing<Rounding> unprotected_rounding;
};
template<class T>
struct rounded_math: save_state_nothing<rounded_arith_exact<T> >
{};
} // namespace interval_lib
} // namespace numeric

View File

@@ -11,219 +11,192 @@
#ifndef BOOST_NUMERIC_INTERVAL_TRANSC_HPP
#define BOOST_NUMERIC_INTERVAL_TRANSC_HPP
#include <algorithm>
#include <boost/config.hpp>
#include <boost/numeric/interval/detail/interval_prototype.hpp>
#include <boost/numeric/interval/detail/bugs.hpp>
#include <boost/numeric/interval/detail/test_input.hpp>
#include <boost/numeric/interval/rounding.hpp>
#include <boost/numeric/interval/constants.hpp>
#include <boost/numeric/interval/arith.hpp>
#include <boost/numeric/interval/arith2.hpp>
#include <algorithm>
#include <boost/numeric/interval/constants.hpp>
#include <boost/numeric/interval/detail/bugs.hpp>
#include <boost/numeric/interval/detail/interval_prototype.hpp>
#include <boost/numeric/interval/detail/test_input.hpp>
#include <boost/numeric/interval/rounding.hpp>
namespace boost {
namespace numeric {
template<class T, class Policies> inline
interval<T, Policies> exp(const interval<T, Policies>& x)
template <class T, class Policies> inline interval<T, Policies> exp(const interval<T, Policies> &x)
{
typedef interval<T, Policies> I;
if (interval_lib::detail::test_input(x))
return I::empty();
typename Policies::rounding rnd;
return I(rnd.exp_down(x.lower()), rnd.exp_up(x.upper()), true);
typedef interval<T, Policies> I;
if (interval_lib::detail::test_input(x))
return I::empty();
typename Policies::rounding rnd;
return I(rnd.exp_down(x.lower()), rnd.exp_up(x.upper()), true);
}
template<class T, class Policies> inline
interval<T, Policies> log(const interval<T, Policies>& x)
template <class T, class Policies> inline interval<T, Policies> log(const interval<T, Policies> &x)
{
typedef interval<T, Policies> I;
if (interval_lib::detail::test_input(x) ||
!interval_lib::user::is_pos(x.upper()))
return I::empty();
typename Policies::rounding rnd;
typedef typename Policies::checking checking;
T l = !interval_lib::user::is_pos(x.lower())
? checking::neg_inf() : rnd.log_down(x.lower());
return I(l, rnd.log_up(x.upper()), true);
typedef interval<T, Policies> I;
if (interval_lib::detail::test_input(x) || !interval_lib::user::is_pos(x.upper()))
return I::empty();
typename Policies::rounding rnd;
typedef typename Policies::checking checking;
T l = !interval_lib::user::is_pos(x.lower()) ? checking::neg_inf() : rnd.log_down(x.lower());
return I(l, rnd.log_up(x.upper()), true);
}
template<class T, class Policies> inline
interval<T, Policies> cos(const interval<T, Policies>& x)
template <class T, class Policies> inline interval<T, Policies> cos(const interval<T, Policies> &x)
{
if (interval_lib::detail::test_input(x))
return interval<T, Policies>::empty();
typename Policies::rounding rnd;
typedef interval<T, Policies> I;
typedef typename interval_lib::unprotect<I>::type R;
if (interval_lib::detail::test_input(x))
return interval<T, Policies>::empty();
typename Policies::rounding rnd;
typedef interval<T, Policies> I;
typedef typename interval_lib::unprotect<I>::type R;
// get lower bound within [0, pi]
const R pi2 = interval_lib::pi_twice<R>();
R tmp = fmod((const R&)x, pi2);
if (width(tmp) >= pi2.lower())
return I(static_cast<T>(-1), static_cast<T>(1), true); // we are covering a full period
if (tmp.lower() >= interval_lib::constants::pi_upper<T>())
return -cos(tmp - interval_lib::pi<R>());
T l = tmp.lower();
T u = tmp.upper();
// get lower bound within [0, pi]
const R pi2 = interval_lib::pi_twice<R>();
R tmp = fmod((const R &)x, pi2);
if (width(tmp) >= pi2.lower())
return I(static_cast<T>(-1), static_cast<T>(1), true); // we are covering a full period
if (tmp.lower() >= interval_lib::constants::pi_upper<T>())
return -cos(tmp - interval_lib::pi<R>());
T l = tmp.lower();
T u = tmp.upper();
BOOST_USING_STD_MIN();
// separate into monotone subintervals
if (u <= interval_lib::constants::pi_lower<T>())
return I(rnd.cos_down(u), rnd.cos_up(l), true);
else if (u <= pi2.lower())
return I(static_cast<T>(-1), rnd.cos_up(min BOOST_PREVENT_MACRO_SUBSTITUTION(rnd.sub_down(pi2.lower(), u), l)), true);
else
return I(static_cast<T>(-1), static_cast<T>(1), true);
BOOST_USING_STD_MIN();
// separate into monotone subintervals
if (u <= interval_lib::constants::pi_lower<T>())
return I(rnd.cos_down(u), rnd.cos_up(l), true);
else if (u <= pi2.lower())
return I(static_cast<T>(-1),
rnd.cos_up(min BOOST_PREVENT_MACRO_SUBSTITUTION(rnd.sub_down(pi2.lower(), u), l)),
true);
else
return I(static_cast<T>(-1), static_cast<T>(1), true);
}
template<class T, class Policies> inline
interval<T, Policies> sin(const interval<T, Policies>& x)
template <class T, class Policies> inline interval<T, Policies> sin(const interval<T, Policies> &x)
{
typedef interval<T, Policies> I;
if (interval_lib::detail::test_input(x))
return I::empty();
typename Policies::rounding rnd;
typedef typename interval_lib::unprotect<I>::type R;
I r = cos((const R&)x - interval_lib::pi_half<R>());
(void)&rnd;
return r;
typedef interval<T, Policies> I;
if (interval_lib::detail::test_input(x))
return I::empty();
typename Policies::rounding rnd;
typedef typename interval_lib::unprotect<I>::type R;
I r = cos((const R &)x - interval_lib::pi_half<R>());
(void)&rnd;
return r;
}
template<class T, class Policies> inline
interval<T, Policies> tan(const interval<T, Policies>& x)
template <class T, class Policies> inline interval<T, Policies> tan(const interval<T, Policies> &x)
{
typedef interval<T, Policies> I;
if (interval_lib::detail::test_input(x))
return I::empty();
typename Policies::rounding rnd;
typedef typename interval_lib::unprotect<I>::type R;
typedef interval<T, Policies> I;
if (interval_lib::detail::test_input(x))
return I::empty();
typename Policies::rounding rnd;
typedef typename interval_lib::unprotect<I>::type R;
// get lower bound within [-pi/2, pi/2]
const R pi = interval_lib::pi<R>();
R tmp = fmod((const R&)x, pi);
const T pi_half_d = interval_lib::constants::pi_half_lower<T>();
if (tmp.lower() >= pi_half_d)
tmp -= pi;
if (tmp.lower() <= -pi_half_d || tmp.upper() >= pi_half_d)
return I::whole();
return I(rnd.tan_down(tmp.lower()), rnd.tan_up(tmp.upper()), true);
// get lower bound within [-pi/2, pi/2]
const R pi = interval_lib::pi<R>();
R tmp = fmod((const R &)x, pi);
const T pi_half_d = interval_lib::constants::pi_half_lower<T>();
if (tmp.lower() >= pi_half_d)
tmp -= pi;
if (tmp.lower() <= -pi_half_d || tmp.upper() >= pi_half_d)
return I::whole();
return I(rnd.tan_down(tmp.lower()), rnd.tan_up(tmp.upper()), true);
}
template<class T, class Policies> inline
interval<T, Policies> asin(const interval<T, Policies>& x)
template <class T, class Policies> inline interval<T, Policies> asin(const interval<T, Policies> &x)
{
typedef interval<T, Policies> I;
if (interval_lib::detail::test_input(x)
|| x.upper() < static_cast<T>(-1) || x.lower() > static_cast<T>(1))
return I::empty();
typename Policies::rounding rnd;
T l = (x.lower() <= static_cast<T>(-1))
? -interval_lib::constants::pi_half_upper<T>()
: rnd.asin_down(x.lower());
T u = (x.upper() >= static_cast<T>(1) )
? interval_lib::constants::pi_half_upper<T>()
: rnd.asin_up (x.upper());
return I(l, u, true);
typedef interval<T, Policies> I;
if (interval_lib::detail::test_input(x) || x.upper() < static_cast<T>(-1) || x.lower() > static_cast<T>(1))
return I::empty();
typename Policies::rounding rnd;
T l = (x.lower() <= static_cast<T>(-1)) ? -interval_lib::constants::pi_half_upper<T>() : rnd.asin_down(x.lower());
T u = (x.upper() >= static_cast<T>(1)) ? interval_lib::constants::pi_half_upper<T>() : rnd.asin_up(x.upper());
return I(l, u, true);
}
template<class T, class Policies> inline
interval<T, Policies> acos(const interval<T, Policies>& x)
template <class T, class Policies> inline interval<T, Policies> acos(const interval<T, Policies> &x)
{
typedef interval<T, Policies> I;
if (interval_lib::detail::test_input(x)
|| x.upper() < static_cast<T>(-1) || x.lower() > static_cast<T>(1))
return I::empty();
typename Policies::rounding rnd;
T l = (x.upper() >= static_cast<T>(1) )
? static_cast<T>(0)
: rnd.acos_down(x.upper());
T u = (x.lower() <= static_cast<T>(-1))
? interval_lib::constants::pi_upper<T>()
: rnd.acos_up (x.lower());
return I(l, u, true);
typedef interval<T, Policies> I;
if (interval_lib::detail::test_input(x) || x.upper() < static_cast<T>(-1) || x.lower() > static_cast<T>(1))
return I::empty();
typename Policies::rounding rnd;
T l = (x.upper() >= static_cast<T>(1)) ? static_cast<T>(0) : rnd.acos_down(x.upper());
T u = (x.lower() <= static_cast<T>(-1)) ? interval_lib::constants::pi_upper<T>() : rnd.acos_up(x.lower());
return I(l, u, true);
}
template<class T, class Policies> inline
interval<T, Policies> atan(const interval<T, Policies>& x)
template <class T, class Policies> inline interval<T, Policies> atan(const interval<T, Policies> &x)
{
typedef interval<T, Policies> I;
if (interval_lib::detail::test_input(x))
return I::empty();
typename Policies::rounding rnd;
return I(rnd.atan_down(x.lower()), rnd.atan_up(x.upper()), true);
typedef interval<T, Policies> I;
if (interval_lib::detail::test_input(x))
return I::empty();
typename Policies::rounding rnd;
return I(rnd.atan_down(x.lower()), rnd.atan_up(x.upper()), true);
}
template<class T, class Policies> inline
interval<T, Policies> sinh(const interval<T, Policies>& x)
template <class T, class Policies> inline interval<T, Policies> sinh(const interval<T, Policies> &x)
{
typedef interval<T, Policies> I;
if (interval_lib::detail::test_input(x))
return I::empty();
typename Policies::rounding rnd;
return I(rnd.sinh_down(x.lower()), rnd.sinh_up(x.upper()), true);
typedef interval<T, Policies> I;
if (interval_lib::detail::test_input(x))
return I::empty();
typename Policies::rounding rnd;
return I(rnd.sinh_down(x.lower()), rnd.sinh_up(x.upper()), true);
}
template<class T, class Policies> inline
interval<T, Policies> cosh(const interval<T, Policies>& x)
template <class T, class Policies> inline interval<T, Policies> cosh(const interval<T, Policies> &x)
{
typedef interval<T, Policies> I;
if (interval_lib::detail::test_input(x))
return I::empty();
typename Policies::rounding rnd;
if (interval_lib::user::is_neg(x.upper()))
return I(rnd.cosh_down(x.upper()), rnd.cosh_up(x.lower()), true);
else if (!interval_lib::user::is_neg(x.lower()))
return I(rnd.cosh_down(x.lower()), rnd.cosh_up(x.upper()), true);
else
return I(static_cast<T>(0), rnd.cosh_up(-x.lower() > x.upper() ? x.lower() : x.upper()), true);
typedef interval<T, Policies> I;
if (interval_lib::detail::test_input(x))
return I::empty();
typename Policies::rounding rnd;
if (interval_lib::user::is_neg(x.upper()))
return I(rnd.cosh_down(x.upper()), rnd.cosh_up(x.lower()), true);
else if (!interval_lib::user::is_neg(x.lower()))
return I(rnd.cosh_down(x.lower()), rnd.cosh_up(x.upper()), true);
else
return I(static_cast<T>(0), rnd.cosh_up(-x.lower() > x.upper() ? x.lower() : x.upper()), true);
}
template<class T, class Policies> inline
interval<T, Policies> tanh(const interval<T, Policies>& x)
template <class T, class Policies> inline interval<T, Policies> tanh(const interval<T, Policies> &x)
{
typedef interval<T, Policies> I;
if (interval_lib::detail::test_input(x))
return I::empty();
typename Policies::rounding rnd;
return I(rnd.tanh_down(x.lower()), rnd.tanh_up(x.upper()), true);
typedef interval<T, Policies> I;
if (interval_lib::detail::test_input(x))
return I::empty();
typename Policies::rounding rnd;
return I(rnd.tanh_down(x.lower()), rnd.tanh_up(x.upper()), true);
}
template<class T, class Policies> inline
interval<T, Policies> asinh(const interval<T, Policies>& x)
template <class T, class Policies> inline interval<T, Policies> asinh(const interval<T, Policies> &x)
{
typedef interval<T, Policies> I;
if (interval_lib::detail::test_input(x))
return I::empty();
typename Policies::rounding rnd;
return I(rnd.asinh_down(x.lower()), rnd.asinh_up(x.upper()), true);
typedef interval<T, Policies> I;
if (interval_lib::detail::test_input(x))
return I::empty();
typename Policies::rounding rnd;
return I(rnd.asinh_down(x.lower()), rnd.asinh_up(x.upper()), true);
}
template<class T, class Policies> inline
interval<T, Policies> acosh(const interval<T, Policies>& x)
template <class T, class Policies> inline interval<T, Policies> acosh(const interval<T, Policies> &x)
{
typedef interval<T, Policies> I;
if (interval_lib::detail::test_input(x) || x.upper() < static_cast<T>(1))
return I::empty();
typename Policies::rounding rnd;
T l = x.lower() <= static_cast<T>(1) ? static_cast<T>(0) : rnd.acosh_down(x.lower());
return I(l, rnd.acosh_up(x.upper()), true);
typedef interval<T, Policies> I;
if (interval_lib::detail::test_input(x) || x.upper() < static_cast<T>(1))
return I::empty();
typename Policies::rounding rnd;
T l = x.lower() <= static_cast<T>(1) ? static_cast<T>(0) : rnd.acosh_down(x.lower());
return I(l, rnd.acosh_up(x.upper()), true);
}
template<class T, class Policies> inline
interval<T, Policies> atanh(const interval<T, Policies>& x)
template <class T, class Policies> inline interval<T, Policies> atanh(const interval<T, Policies> &x)
{
typedef interval<T, Policies> I;
if (interval_lib::detail::test_input(x)
|| x.upper() < static_cast<T>(-1) || x.lower() > static_cast<T>(1))
return I::empty();
typename Policies::rounding rnd;
typedef typename Policies::checking checking;
T l = (x.lower() <= static_cast<T>(-1))
? checking::neg_inf() : rnd.atanh_down(x.lower());
T u = (x.upper() >= static_cast<T>(1) )
? checking::pos_inf() : rnd.atanh_up (x.upper());
return I(l, u, true);
typedef interval<T, Policies> I;
if (interval_lib::detail::test_input(x) || x.upper() < static_cast<T>(-1) || x.lower() > static_cast<T>(1))
return I::empty();
typename Policies::rounding rnd;
typedef typename Policies::checking checking;
T l = (x.lower() <= static_cast<T>(-1)) ? checking::neg_inf() : rnd.atanh_down(x.lower());
T u = (x.upper() >= static_cast<T>(1)) ? checking::pos_inf() : rnd.atanh_up(x.upper());
return I(l, u, true);
}
} // namespace numeric

View File

@@ -11,11 +11,11 @@
#ifndef BOOST_NUMERIC_INTERVAL_UTILITY_HPP
#define BOOST_NUMERIC_INTERVAL_UTILITY_HPP
#include <algorithm>
#include <boost/config.hpp>
#include <boost/numeric/interval/detail/bugs.hpp>
#include <boost/numeric/interval/detail/interval_prototype.hpp>
#include <boost/numeric/interval/detail/test_input.hpp>
#include <boost/numeric/interval/detail/bugs.hpp>
#include <algorithm>
#include <utility>
/*
@@ -29,306 +29,296 @@ namespace numeric {
* Utility Functions
*/
template<class T, class Policies> inline
const T& lower(const interval<T, Policies>& x)
template <class T, class Policies> inline const T &lower(const interval<T, Policies> &x) { return x.lower(); }
template <class T, class Policies> inline const T &upper(const interval<T, Policies> &x) { return x.upper(); }
template <class T, class Policies> inline T checked_lower(const interval<T, Policies> &x)
{
return x.lower();
if (empty(x)) {
typedef typename Policies::checking checking;
return checking::nan();
}
return x.lower();
}
template<class T, class Policies> inline
const T& upper(const interval<T, Policies>& x)
template <class T, class Policies> inline T checked_upper(const interval<T, Policies> &x)
{
return x.upper();
if (empty(x)) {
typedef typename Policies::checking checking;
return checking::nan();
}
return x.upper();
}
template<class T, class Policies> inline
T checked_lower(const interval<T, Policies>& x)
template <class T, class Policies> inline T width(const interval<T, Policies> &x)
{
if (empty(x)) {
typedef typename Policies::checking checking;
return checking::nan();
}
return x.lower();
if (interval_lib::detail::test_input(x))
return static_cast<T>(0);
typename Policies::rounding rnd;
return rnd.sub_up(x.upper(), x.lower());
}
template<class T, class Policies> inline
T checked_upper(const interval<T, Policies>& x)
template <class T, class Policies> inline T median(const interval<T, Policies> &x)
{
if (empty(x)) {
typedef typename Policies::checking checking;
return checking::nan();
}
return x.upper();
if (interval_lib::detail::test_input(x)) {
typedef typename Policies::checking checking;
return checking::nan();
}
typename Policies::rounding rnd;
return rnd.median(x.lower(), x.upper());
}
template<class T, class Policies> inline
T width(const interval<T, Policies>& x)
template <class T, class Policies> inline interval<T, Policies> widen(const interval<T, Policies> &x, const T &v)
{
if (interval_lib::detail::test_input(x)) return static_cast<T>(0);
typename Policies::rounding rnd;
return rnd.sub_up(x.upper(), x.lower());
}
template<class T, class Policies> inline
T median(const interval<T, Policies>& x)
{
if (interval_lib::detail::test_input(x)) {
typedef typename Policies::checking checking;
return checking::nan();
}
typename Policies::rounding rnd;
return rnd.median(x.lower(), x.upper());
}
template<class T, class Policies> inline
interval<T, Policies> widen(const interval<T, Policies>& x, const T& v)
{
if (interval_lib::detail::test_input(x))
return interval<T, Policies>::empty();
typename Policies::rounding rnd;
return interval<T, Policies>(rnd.sub_down(x.lower(), v),
rnd.add_up (x.upper(), v), true);
if (interval_lib::detail::test_input(x))
return interval<T, Policies>::empty();
typename Policies::rounding rnd;
return interval<T, Policies>(rnd.sub_down(x.lower(), v), rnd.add_up(x.upper(), v), true);
}
/*
* Set-like operations
*/
template<class T, class Policies> inline
bool empty(const interval<T, Policies>& x)
template <class T, class Policies> inline bool empty(const interval<T, Policies> &x)
{
return interval_lib::detail::test_input(x);
return interval_lib::detail::test_input(x);
}
template<class T, class Policies> inline
bool zero_in(const interval<T, Policies>& x)
template <class T, class Policies> inline bool zero_in(const interval<T, Policies> &x)
{
if (interval_lib::detail::test_input(x)) return false;
return (!interval_lib::user::is_pos(x.lower())) &&
(!interval_lib::user::is_neg(x.upper()));
if (interval_lib::detail::test_input(x))
return false;
return (!interval_lib::user::is_pos(x.lower())) && (!interval_lib::user::is_neg(x.upper()));
}
template<class T, class Policies> inline
bool in_zero(const interval<T, Policies>& x) // DEPRECATED
template <class T, class Policies> inline bool in_zero(const interval<T, Policies> &x) // DEPRECATED
{
return zero_in<T, Policies>(x);
return zero_in<T, Policies>(x);
}
template<class T, class Policies> inline
bool in(const T& x, const interval<T, Policies>& y)
template <class T, class Policies> inline bool in(const T &x, const interval<T, Policies> &y)
{
if (interval_lib::detail::test_input(x, y)) return false;
return y.lower() <= x && x <= y.upper();
if (interval_lib::detail::test_input(x, y))
return false;
return y.lower() <= x && x <= y.upper();
}
template<class T, class Policies> inline
bool subset(const interval<T, Policies>& x,
const interval<T, Policies>& y)
template <class T, class Policies> inline bool subset(const interval<T, Policies> &x, const interval<T, Policies> &y)
{
if (empty(x)) return true;
return !empty(y) && y.lower() <= x.lower() && x.upper() <= y.upper();
if (empty(x))
return true;
return !empty(y) && y.lower() <= x.lower() && x.upper() <= y.upper();
}
template<class T, class Policies1, class Policies2> inline
bool proper_subset(const interval<T, Policies1>& x,
const interval<T, Policies2>& y)
template <class T, class Policies1, class Policies2>
inline bool proper_subset(const interval<T, Policies1> &x, const interval<T, Policies2> &y)
{
if (empty(y)) return false;
if (empty(x)) return true;
return y.lower() <= x.lower() && x.upper() <= y.upper() &&
(y.lower() != x.lower() || x.upper() != y.upper());
if (empty(y))
return false;
if (empty(x))
return true;
return y.lower() <= x.lower() && x.upper() <= y.upper() && (y.lower() != x.lower() || x.upper() != y.upper());
}
template<class T, class Policies1, class Policies2> inline
bool overlap(const interval<T, Policies1>& x,
const interval<T, Policies2>& y)
template <class T, class Policies1, class Policies2>
inline bool overlap(const interval<T, Policies1> &x, const interval<T, Policies2> &y)
{
if (interval_lib::detail::test_input(x, y)) return false;
return x.lower() <= y.lower() && y.lower() <= x.upper() ||
y.lower() <= x.lower() && x.lower() <= y.upper();
if (interval_lib::detail::test_input(x, y))
return false;
return x.lower() <= y.lower() && y.lower() <= x.upper() || y.lower() <= x.lower() && x.lower() <= y.upper();
}
template<class T, class Policies> inline
bool singleton(const interval<T, Policies>& x)
template <class T, class Policies> inline bool singleton(const interval<T, Policies> &x)
{
return !empty(x) && x.lower() == x.upper();
return !empty(x) && x.lower() == x.upper();
}
template<class T, class Policies1, class Policies2> inline
bool equal(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
template <class T, class Policies1, class Policies2>
inline bool equal(const interval<T, Policies1> &x, const interval<T, Policies2> &y)
{
if (empty(x)) return empty(y);
return !empty(y) && x.lower() == y.lower() && x.upper() == y.upper();
if (empty(x))
return empty(y);
return !empty(y) && x.lower() == y.lower() && x.upper() == y.upper();
}
template<class T, class Policies> inline
interval<T, Policies> intersect(const interval<T, Policies>& x,
const interval<T, Policies>& y)
template <class T, class Policies>
inline interval<T, Policies> intersect(const interval<T, Policies> &x, const interval<T, Policies> &y)
{
BOOST_USING_STD_MIN();
BOOST_USING_STD_MAX();
if (interval_lib::detail::test_input(x, y))
return interval<T, Policies>::empty();
const T& l = max BOOST_PREVENT_MACRO_SUBSTITUTION(x.lower(), y.lower());
const T& u = min BOOST_PREVENT_MACRO_SUBSTITUTION(x.upper(), y.upper());
if (l <= u) return interval<T, Policies>(l, u, true);
else return interval<T, Policies>::empty();
BOOST_USING_STD_MIN();
BOOST_USING_STD_MAX();
if (interval_lib::detail::test_input(x, y))
return interval<T, Policies>::empty();
const T &l = max BOOST_PREVENT_MACRO_SUBSTITUTION(x.lower(), y.lower());
const T &u = min BOOST_PREVENT_MACRO_SUBSTITUTION(x.upper(), y.upper());
if (l <= u)
return interval<T, Policies>(l, u, true);
else
return interval<T, Policies>::empty();
}
template<class T, class Policies> inline
interval<T, Policies> hull(const interval<T, Policies>& x,
const interval<T, Policies>& y)
template <class T, class Policies>
inline interval<T, Policies> hull(const interval<T, Policies> &x, const interval<T, Policies> &y)
{
BOOST_USING_STD_MIN();
BOOST_USING_STD_MAX();
bool bad_x = interval_lib::detail::test_input(x);
bool bad_y = interval_lib::detail::test_input(y);
if (bad_x)
if (bad_y) return interval<T, Policies>::empty();
else return y;
else
if (bad_y) return x;
return interval<T, Policies>(min BOOST_PREVENT_MACRO_SUBSTITUTION(x.lower(), y.lower()),
max BOOST_PREVENT_MACRO_SUBSTITUTION(x.upper(), y.upper()), true);
BOOST_USING_STD_MIN();
BOOST_USING_STD_MAX();
bool bad_x = interval_lib::detail::test_input(x);
bool bad_y = interval_lib::detail::test_input(y);
if (bad_x)
if (bad_y)
return interval<T, Policies>::empty();
else
return y;
else if (bad_y)
return x;
return interval<T, Policies>(min BOOST_PREVENT_MACRO_SUBSTITUTION(x.lower(), y.lower()),
max BOOST_PREVENT_MACRO_SUBSTITUTION(x.upper(), y.upper()),
true);
}
template<class T, class Policies> inline
interval<T, Policies> hull(const interval<T, Policies>& x, const T& y)
template <class T, class Policies> inline interval<T, Policies> hull(const interval<T, Policies> &x, const T &y)
{
BOOST_USING_STD_MIN();
BOOST_USING_STD_MAX();
bool bad_x = interval_lib::detail::test_input(x);
bool bad_y = interval_lib::detail::test_input<T, Policies>(y);
if (bad_y)
if (bad_x) return interval<T, Policies>::empty();
else return x;
else
if (bad_x) return interval<T, Policies>(y, y, true);
return interval<T, Policies>(min BOOST_PREVENT_MACRO_SUBSTITUTION(x.lower(), y),
max BOOST_PREVENT_MACRO_SUBSTITUTION(x.upper(), y), true);
BOOST_USING_STD_MIN();
BOOST_USING_STD_MAX();
bool bad_x = interval_lib::detail::test_input(x);
bool bad_y = interval_lib::detail::test_input<T, Policies>(y);
if (bad_y)
if (bad_x)
return interval<T, Policies>::empty();
else
return x;
else if (bad_x)
return interval<T, Policies>(y, y, true);
return interval<T, Policies>(
min BOOST_PREVENT_MACRO_SUBSTITUTION(x.lower(), y), max BOOST_PREVENT_MACRO_SUBSTITUTION(x.upper(), y), true);
}
template<class T, class Policies> inline
interval<T, Policies> hull(const T& x, const interval<T, Policies>& y)
template <class T, class Policies> inline interval<T, Policies> hull(const T &x, const interval<T, Policies> &y)
{
BOOST_USING_STD_MIN();
BOOST_USING_STD_MAX();
bool bad_x = interval_lib::detail::test_input<T, Policies>(x);
bool bad_y = interval_lib::detail::test_input(y);
if (bad_x)
if (bad_y) return interval<T, Policies>::empty();
else return y;
else
if (bad_y) return interval<T, Policies>(x, x, true);
return interval<T, Policies>(min BOOST_PREVENT_MACRO_SUBSTITUTION(x, y.lower()),
max BOOST_PREVENT_MACRO_SUBSTITUTION(x, y.upper()), true);
BOOST_USING_STD_MIN();
BOOST_USING_STD_MAX();
bool bad_x = interval_lib::detail::test_input<T, Policies>(x);
bool bad_y = interval_lib::detail::test_input(y);
if (bad_x)
if (bad_y)
return interval<T, Policies>::empty();
else
return y;
else if (bad_y)
return interval<T, Policies>(x, x, true);
return interval<T, Policies>(
min BOOST_PREVENT_MACRO_SUBSTITUTION(x, y.lower()), max BOOST_PREVENT_MACRO_SUBSTITUTION(x, y.upper()), true);
}
template<class T> inline
interval<T> hull(const T& x, const T& y)
{
return interval<T>::hull(x, y);
}
template <class T> inline interval<T> hull(const T &x, const T &y) { return interval<T>::hull(x, y); }
template<class T, class Policies> inline
std::pair<interval<T, Policies>, interval<T, Policies> >
bisect(const interval<T, Policies>& x)
template <class T, class Policies>
inline std::pair<interval<T, Policies>, interval<T, Policies>> bisect(const interval<T, Policies> &x)
{
typedef interval<T, Policies> I;
if (interval_lib::detail::test_input(x))
return std::pair<I,I>(I::empty(), I::empty());
const T m = median(x);
return std::pair<I,I>(I(x.lower(), m, true), I(m, x.upper(), true));
typedef interval<T, Policies> I;
if (interval_lib::detail::test_input(x))
return std::pair<I, I>(I::empty(), I::empty());
const T m = median(x);
return std::pair<I, I>(I(x.lower(), m, true), I(m, x.upper(), true));
}
/*
* Elementary functions
*/
template<class T, class Policies> inline
T norm(const interval<T, Policies>& x)
template <class T, class Policies> inline T norm(const interval<T, Policies> &x)
{
typedef interval<T, Policies> I;
if (interval_lib::detail::test_input(x)) {
typedef typename Policies::checking checking;
return checking::nan();
}
BOOST_USING_STD_MAX();
return max BOOST_PREVENT_MACRO_SUBSTITUTION(static_cast<T>(-x.lower()), x.upper());
typedef interval<T, Policies> I;
if (interval_lib::detail::test_input(x)) {
typedef typename Policies::checking checking;
return checking::nan();
}
BOOST_USING_STD_MAX();
return max BOOST_PREVENT_MACRO_SUBSTITUTION(static_cast<T>(-x.lower()), x.upper());
}
template<class T, class Policies> inline
interval<T, Policies> abs(const interval<T, Policies>& x)
template <class T, class Policies> inline interval<T, Policies> abs(const interval<T, Policies> &x)
{
typedef interval<T, Policies> I;
if (interval_lib::detail::test_input(x))
return I::empty();
if (!interval_lib::user::is_neg(x.lower())) return x;
if (!interval_lib::user::is_pos(x.upper())) return -x;
BOOST_USING_STD_MAX();
return I(static_cast<T>(0), max BOOST_PREVENT_MACRO_SUBSTITUTION(static_cast<T>(-x.lower()), x.upper()), true);
typedef interval<T, Policies> I;
if (interval_lib::detail::test_input(x))
return I::empty();
if (!interval_lib::user::is_neg(x.lower()))
return x;
if (!interval_lib::user::is_pos(x.upper()))
return -x;
BOOST_USING_STD_MAX();
return I(static_cast<T>(0), max BOOST_PREVENT_MACRO_SUBSTITUTION(static_cast<T>(-x.lower()), x.upper()), true);
}
template<class T, class Policies> inline
interval<T, Policies> max BOOST_PREVENT_MACRO_SUBSTITUTION (const interval<T, Policies>& x,
const interval<T, Policies>& y)
template <class T, class Policies>
inline interval<T, Policies> max BOOST_PREVENT_MACRO_SUBSTITUTION(const interval<T, Policies> &x,
const interval<T, Policies> &y)
{
typedef interval<T, Policies> I;
if (interval_lib::detail::test_input(x, y))
return I::empty();
BOOST_USING_STD_MAX();
return I(max BOOST_PREVENT_MACRO_SUBSTITUTION(x.lower(), y.lower()), max BOOST_PREVENT_MACRO_SUBSTITUTION(x.upper(), y.upper()), true);
typedef interval<T, Policies> I;
if (interval_lib::detail::test_input(x, y))
return I::empty();
BOOST_USING_STD_MAX();
return I(max BOOST_PREVENT_MACRO_SUBSTITUTION(x.lower(), y.lower()),
max BOOST_PREVENT_MACRO_SUBSTITUTION(x.upper(), y.upper()),
true);
}
template<class T, class Policies> inline
interval<T, Policies> max BOOST_PREVENT_MACRO_SUBSTITUTION (const interval<T, Policies>& x, const T& y)
template <class T, class Policies>
inline interval<T, Policies> max BOOST_PREVENT_MACRO_SUBSTITUTION(const interval<T, Policies> &x, const T &y)
{
typedef interval<T, Policies> I;
if (interval_lib::detail::test_input(x, y))
return I::empty();
BOOST_USING_STD_MAX();
return I(max BOOST_PREVENT_MACRO_SUBSTITUTION(x.lower(), y), max BOOST_PREVENT_MACRO_SUBSTITUTION(x.upper(), y), true);
typedef interval<T, Policies> I;
if (interval_lib::detail::test_input(x, y))
return I::empty();
BOOST_USING_STD_MAX();
return I(
max BOOST_PREVENT_MACRO_SUBSTITUTION(x.lower(), y), max BOOST_PREVENT_MACRO_SUBSTITUTION(x.upper(), y), true);
}
template<class T, class Policies> inline
interval<T, Policies> max BOOST_PREVENT_MACRO_SUBSTITUTION (const T& x, const interval<T, Policies>& y)
template <class T, class Policies>
inline interval<T, Policies> max BOOST_PREVENT_MACRO_SUBSTITUTION(const T &x, const interval<T, Policies> &y)
{
typedef interval<T, Policies> I;
if (interval_lib::detail::test_input(x, y))
return I::empty();
BOOST_USING_STD_MAX();
return I(max BOOST_PREVENT_MACRO_SUBSTITUTION(x, y.lower()), max BOOST_PREVENT_MACRO_SUBSTITUTION(x, y.upper()), true);
typedef interval<T, Policies> I;
if (interval_lib::detail::test_input(x, y))
return I::empty();
BOOST_USING_STD_MAX();
return I(
max BOOST_PREVENT_MACRO_SUBSTITUTION(x, y.lower()), max BOOST_PREVENT_MACRO_SUBSTITUTION(x, y.upper()), true);
}
template<class T, class Policies> inline
interval<T, Policies> min BOOST_PREVENT_MACRO_SUBSTITUTION (const interval<T, Policies>& x,
const interval<T, Policies>& y)
template <class T, class Policies>
inline interval<T, Policies> min BOOST_PREVENT_MACRO_SUBSTITUTION(const interval<T, Policies> &x,
const interval<T, Policies> &y)
{
typedef interval<T, Policies> I;
if (interval_lib::detail::test_input(x, y))
return I::empty();
BOOST_USING_STD_MIN();
return I(min BOOST_PREVENT_MACRO_SUBSTITUTION(x.lower(), y.lower()), min BOOST_PREVENT_MACRO_SUBSTITUTION(x.upper(), y.upper()), true);
typedef interval<T, Policies> I;
if (interval_lib::detail::test_input(x, y))
return I::empty();
BOOST_USING_STD_MIN();
return I(min BOOST_PREVENT_MACRO_SUBSTITUTION(x.lower(), y.lower()),
min BOOST_PREVENT_MACRO_SUBSTITUTION(x.upper(), y.upper()),
true);
}
template<class T, class Policies> inline
interval<T, Policies> min BOOST_PREVENT_MACRO_SUBSTITUTION (const interval<T, Policies>& x, const T& y)
template <class T, class Policies>
inline interval<T, Policies> min BOOST_PREVENT_MACRO_SUBSTITUTION(const interval<T, Policies> &x, const T &y)
{
typedef interval<T, Policies> I;
if (interval_lib::detail::test_input(x, y))
return I::empty();
BOOST_USING_STD_MIN();
return I(min BOOST_PREVENT_MACRO_SUBSTITUTION(x.lower(), y), min BOOST_PREVENT_MACRO_SUBSTITUTION(x.upper(), y), true);
typedef interval<T, Policies> I;
if (interval_lib::detail::test_input(x, y))
return I::empty();
BOOST_USING_STD_MIN();
return I(
min BOOST_PREVENT_MACRO_SUBSTITUTION(x.lower(), y), min BOOST_PREVENT_MACRO_SUBSTITUTION(x.upper(), y), true);
}
template<class T, class Policies> inline
interval<T, Policies> min BOOST_PREVENT_MACRO_SUBSTITUTION (const T& x, const interval<T, Policies>& y)
template <class T, class Policies>
inline interval<T, Policies> min BOOST_PREVENT_MACRO_SUBSTITUTION(const T &x, const interval<T, Policies> &y)
{
typedef interval<T, Policies> I;
if (interval_lib::detail::test_input(x, y))
return I::empty();
BOOST_USING_STD_MIN();
return I(min BOOST_PREVENT_MACRO_SUBSTITUTION(x, y.lower()), min BOOST_PREVENT_MACRO_SUBSTITUTION(x, y.upper()), true);
typedef interval<T, Policies> I;
if (interval_lib::detail::test_input(x, y))
return I::empty();
BOOST_USING_STD_MIN();
return I(
min BOOST_PREVENT_MACRO_SUBSTITUTION(x, y.lower()), min BOOST_PREVENT_MACRO_SUBSTITUTION(x, y.upper()), true);
}
} // namespace numeric