Пример #1
0
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);
}
Пример #2
0
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(x, yu), rnd.div_up(x, yl), true);
}
Пример #3
0
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);
}
Пример #4
0
template<class T, class Policies> inline
interval<T, Policies> div_zero_part2(const interval<T, Policies>& x,
                                     const interval<T, Policies>& y)
{
    // assert(y.lower() < 0 && y.upper() > 0 && (div_zero_part1(x, y, b), b));
    typename Policies::rounding rnd;
    typedef interval<T, Policies> I;
    typedef typename I::checking checking;
    const T& inf = checking::inf();
    if (is_neg(x.upper()))
        return I(rnd.div_down(x.upper(), y.lower()), inf, true);
    else
        return I(rnd.div_down(x.lower(), y.upper()), inf, true);
}
Пример #5
0
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);
}
Пример #6
0
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);
}
Пример #7
0
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;
  const T& yb = interval_lib::detail::is_neg(x) ? y.lower() : y.upper();
  T n = rnd.int_down(rnd.div_down(x, yb));
  return x - n * (const I&)y;
}
Пример #8
0
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 (is_neg(xu))
        if (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 (is_neg(xl))
        if (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 (is_neg(yu))
        return I(rnd.div_down(xu, yu), rnd.div_up(xl, yl), true);
    else
        return I(rnd.div_down(xl, yu), rnd.div_up(xu, yl), true);
}
Пример #9
0
template<class T, class Policies> inline
interval<T, Policies> div_positive(const T& x, const T& yu)
{
  // 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);
}
Пример #10
0
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 (in_zero(x)) {
    typedef typename Policies::checking checking;
    if (!detail::is_zero(x.lower()))
      if (!detail::is_zero(x.upper()))
        return I::whole();
      else
        return I(-checking::inf(), rnd.div_up(one, x.lower()), true);
    else
      if (!detail::is_zero(x.upper()))
        return I(rnd.div_down(one, x.upper()), checking::inf(), true);
      else
        return I::empty();
  } else 
    return I(rnd.div_down(one, x.upper()), rnd.div_up(one, x.lower()), true);
}
Пример #11
0
template<class T, class Policies> inline
interval<T, Policies> div_positive(const T& x, const T& yu)
{
    // assert(yu > T(0));
    typedef interval<T, Policies> I;
    if (is_zero(x)) return I(0, 0, true);
    typename Policies::rounding rnd;
    typedef typename Policies::checking checking;
    const T& inf = checking::inf();
    if (is_neg(x))
        return I(-inf, rnd.div_up(x, yu), true);
    else
        return I(rnd.div_down(x, yu), inf, true);
}
Пример #12
0
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), checking::pos_inf(), true);
}
Пример #13
0
template<class T, class Policies> inline
interval<T, Policies> div_negative(const interval<T, Policies>& x, const T& yl)
{
    // assert(yl < T(0));
    if (is_zero(x.lower()) && 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;
    const T& inf = checking::inf();
    if (is_neg(xu))
        return I(rnd.div_down(xu, yl), inf, true);
    else if (is_neg(xl))
        return I(-inf, inf, true);
    else
        return I(-inf, rnd.div_up(xl, yl), true);
}