diff --git a/include/boost/numeric/interval/arith.hpp b/include/boost/numeric/interval/arith.hpp index d2284c8..7028c4c 100644 --- a/include/boost/numeric/interval/arith.hpp +++ b/include/boost/numeric/interval/arith.hpp @@ -187,39 +187,39 @@ interval operator*(const interval& x, const T& yl = y.lower(); const T& yu = y.upper(); - if (interval_lib::detail::is_neg(xl)) - if (interval_lib::detail::is_pos(xu)) - if (interval_lib::detail::is_neg(yl)) - if (interval_lib::detail::is_pos(yu)) // M * M + 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(rnd.mul_down(xl, yu), rnd.mul_down(xu, yl)), max(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::detail::is_pos(yu)) // M * P + 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(0), static_cast(0), true); else - if (interval_lib::detail::is_neg(yl)) - if (interval_lib::detail::is_pos(yu)) // N * M + 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::detail::is_pos(yu)) // N * P + 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(0), static_cast(0), true); else - if (interval_lib::detail::is_pos(xu)) - if (interval_lib::detail::is_neg(yl)) - if (interval_lib::detail::is_pos(yu)) // P * M + 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::detail::is_pos(yu)) // P * P + 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(0), static_cast(0), true); @@ -237,9 +237,9 @@ interval operator*(const T& x, const interval& y) const T& yl = y.lower(); const T& yu = y.upper(); // x is supposed not to be infinite - if (interval_lib::detail::is_neg(x)) + if (interval_lib::user::is_neg(x)) return I(rnd.mul_down(x, yu), rnd.mul_up(x, yl), true); - else if (interval_lib::detail::is_zero(x)) + else if (interval_lib::user::is_zero(x)) return I(static_cast(0), static_cast(0), true); else return I(rnd.mul_down(x, yl), rnd.mul_up(x, yu), true); @@ -256,13 +256,13 @@ interval operator/(const interval& x, if (interval_lib::detail::test_input(x, y)) return interval::empty(); if (in_zero(y)) - if (!interval_lib::detail::is_zero(y.lower())) - if (!interval_lib::detail::is_zero(y.upper())) + 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::detail::is_zero(y.upper())) + if (!interval_lib::user::is_zero(y.upper())) return interval_lib::detail::div_positive(x, y.upper()); else return interval::empty(); @@ -276,13 +276,13 @@ interval operator/(const T& x, const interval& y) if (interval_lib::detail::test_input(x, y)) return interval::empty(); if (in_zero(y)) - if (!interval_lib::detail::is_zero(y.lower())) - if (!interval_lib::detail::is_zero(y.upper())) + 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::detail::is_zero(y.upper())) + if (!interval_lib::user::is_zero(y.upper())) return interval_lib::detail::div_positive(x, y.upper()); else return interval::empty(); @@ -293,12 +293,12 @@ interval operator/(const T& x, const interval& y) template inline interval operator/(const interval& x, const T& y) { - if (interval_lib::detail::test_input(x, y) || interval_lib::detail::is_zero(y)) + if (interval_lib::detail::test_input(x, y) || interval_lib::user::is_zero(y)) return interval::empty(); typename Policies::rounding rnd; const T& xl = x.lower(); const T& xu = x.upper(); - if (interval_lib::detail::is_neg(y)) + if (interval_lib::user::is_neg(y)) return interval(rnd.div_down(xu, y), rnd.div_up(xl, y), true); else return interval(rnd.div_down(xl, y), rnd.div_up(xu, y), true); diff --git a/include/boost/numeric/interval/arith2.hpp b/include/boost/numeric/interval/arith2.hpp index 3486095..7b1632b 100644 --- a/include/boost/numeric/interval/arith2.hpp +++ b/include/boost/numeric/interval/arith2.hpp @@ -36,7 +36,7 @@ interval fmod(const interval& x, return interval::empty(); typename Policies::rounding rnd; typedef typename interval_lib::unprotect >::type I; - const T& yb = interval_lib::detail::is_neg(x.lower()) ? y.lower() : y.upper(); + 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; } @@ -59,7 +59,7 @@ interval fmod(const T& x, const interval& y) return interval::empty(); typename Policies::rounding rnd; typedef typename interval_lib::unprotect >::type I; - const T& yb = interval_lib::detail::is_neg(x) ? y.lower() : y.upper(); + 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; } @@ -75,13 +75,13 @@ interval division_part1(const interval& x, if (detail::test_input(x, y)) return I::empty(); if (in_zero(y)) - if (!detail::is_zero(y.lower())) - if (!detail::is_zero(y.upper())) + 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 (!detail::is_zero(y.upper())) + if (!user::is_zero(y.upper())) return detail::div_positive(x, y.upper()); else return I::empty(); @@ -107,13 +107,13 @@ interval multiplicative_inverse(const interval& x) 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())) + if (!user::is_zero(x.lower())) + if (!user::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())) + if (!user::is_zero(x.upper())) return I(rnd.div_down(one, x.upper()), checking::inf(), true); else return I::empty(); @@ -150,8 +150,8 @@ interval pow(const interval& x, int pwr) return I::empty(); if (pwr == 0) - if (interval_lib::detail::is_zero(x.lower()) - && interval_lib::detail::is_zero(x.upper())) + if (interval_lib::user::is_zero(x.lower()) + && interval_lib::user::is_zero(x.upper())) return I::empty(); else return I(static_cast(1)); @@ -160,14 +160,14 @@ interval pow(const interval& x, int pwr) typename Policies::rounding rnd; - if (interval_lib::detail::is_neg(x.upper())) { // [-2,-1] + if (interval_lib::user::is_neg(x.upper())) { // [-2,-1] T yl = pow_aux(-x.upper(), pwr, rnd); T yu = pow_aux(-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::detail::is_neg(x.lower())) { // [-1,1] + } else if (interval_lib::user::is_neg(x.lower())) { // [-1,1] if (pwr & 1) { // [-1,1]^1 return I(-pow_aux(-x.lower(), pwr, rnd), pow_aux(x.upper(), pwr, rnd), true); } else { // [-1,1]^2 @@ -183,10 +183,10 @@ template inline interval sqrt(const interval& x) { typedef interval I; - if (interval_lib::detail::test_input(x) || interval_lib::detail::is_neg(x.upper())) + if (interval_lib::detail::test_input(x) || interval_lib::user::is_neg(x.upper())) return I::empty(); typename Policies::rounding rnd; - T l = (x.lower() <= static_cast(0)) ? static_cast(0) : rnd.sqrt_down(x.lower()); + T l = !interval_lib::user::is_pos(x.lower()) ? static_cast(0) : rnd.sqrt_down(x.lower()); return I(l, rnd.sqrt_up(x.upper()), true); } @@ -199,9 +199,9 @@ interval square(const interval& x) typename Policies::rounding rnd; const T& xl = x.lower(); const T& xu = x.upper(); - if (interval_lib::detail::is_neg(xu)) + if (interval_lib::user::is_neg(xu)) return I(rnd.mul_down(xu, xu), rnd.mul_up(xl, xl), true); - else if (interval_lib::detail::is_pos(x.lower())) + 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(0), (-xl > xu ? rnd.mul_up(xl, xl) : rnd.mul_up(xu, xu)), true); diff --git a/include/boost/numeric/interval/arith3.hpp b/include/boost/numeric/interval/arith3.hpp index 6fbf82f..5069b45 100644 --- a/include/boost/numeric/interval/arith3.hpp +++ b/include/boost/numeric/interval/arith3.hpp @@ -57,7 +57,7 @@ template 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(x, y) || detail::is_zero(y)) + if (detail::test_input(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); diff --git a/include/boost/numeric/interval/detail/division.hpp b/include/boost/numeric/interval/detail/division.hpp index f36f586..dcd4eb5 100644 --- a/include/boost/numeric/interval/detail/division.hpp +++ b/include/boost/numeric/interval/detail/division.hpp @@ -37,18 +37,18 @@ interval div_non_zero(const interval& x, const T& xu = x.upper(); const T& yl = y.lower(); const T& yu = y.upper(); - if (is_neg(xu)) - if (is_neg(yu)) + 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 (is_neg(xl)) - if (is_neg(yu)) + 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 (is_neg(yu)) + 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, yu), rnd.div_up(xu, yl), true); @@ -62,7 +62,7 @@ interval div_non_zero(const T& x, const interval& y) typedef interval I; const T& yl = y.lower(); const T& yu = y.upper(); - if (is_neg(x)) + 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); @@ -71,17 +71,19 @@ interval div_non_zero(const T& x, const interval& y) template inline interval div_positive(const interval& x, const T& yu) { - // assert(yu > T(0)); - if (is_zero(x.lower()) && is_zero(x.upper())) return x; + // 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 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)) + if (::boost::numeric::interval_lib::user::is_neg(xu)) return I(-inf, rnd.div_up(xu, yu), true); - else if (is_neg(xl)) + else if (::boost::numeric::interval_lib::user::is_neg(xl)) return I(-inf, inf, true); else return I(rnd.div_down(xl, yu), inf, true); @@ -90,13 +92,14 @@ interval div_positive(const interval& x, const T& yu) template inline interval div_positive(const T& x, const T& yu) { - // assert(yu > T(0)); + // assert(::boost::numeric::interval_lib::user::is_pos(yu)); typedef interval I; - if (is_zero(x)) return I(static_cast(0), static_cast(0), true); + if (::boost::numeric::interval_lib::user::is_zero(x)) + return I(static_cast(0), static_cast(0), true); typename Policies::rounding rnd; typedef typename Policies::checking checking; const T& inf = checking::inf(); - if (is_neg(x)) + if (::boost::numeric::interval_lib::user::is_neg(x)) return I(-inf, rnd.div_up(x, yu), true); else return I(rnd.div_down(x, yu), inf, true); @@ -105,8 +108,9 @@ interval div_positive(const T& x, const T& yu) template inline interval div_negative(const interval& x, const T& yl) { - // assert(yl < T(0)); - if (is_zero(x.lower()) && is_zero(x.upper())) + // 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 I; @@ -114,9 +118,9 @@ interval div_negative(const interval& x, const T& yl) const T& xu = x.upper(); typedef typename Policies::checking checking; const T& inf = checking::inf(); - if (is_neg(xu)) + if (::boost::numeric::interval_lib::user::is_neg(xu)) return I(rnd.div_down(xu, yl), inf, true); - else if (is_neg(xl)) + else if (::boost::numeric::interval_lib::user::is_neg(xl)) return I(-inf, inf, true); else return I(-inf, rnd.div_up(xl, yl), true); @@ -125,13 +129,14 @@ interval div_negative(const interval& x, const T& yl) template inline interval div_negative(const T& x, const T& yl) { - // assert(yl < T(0)); + // assert(::boost::numeric::interval_lib::user::is_neg(yl)); typedef interval I; - if (is_zero(x)) return I(static_cast(0), static_cast(0), true); + if (::boost::numeric::interval_lib::user::is_zero(x)) + return I(static_cast(0), static_cast(0), true); typename Policies::rounding rnd; typedef typename Policies::checking checking; const T& inf = checking::inf(); - if (is_neg(x)) + if (::boost::numeric::interval_lib::user::is_neg(x)) return I(rnd.div_down(x, yl), inf, true); else return I(-inf, rnd.div_up(x, yl), true); @@ -140,7 +145,8 @@ interval div_negative(const T& x, const T& yl) template inline interval div_zero(const interval& x) { - if (is_zero(x.lower()) && is_zero(x.upper())) + if (::boost::numeric::interval_lib::user::is_zero(x.lower()) && + ::boost::numeric::interval_lib::user::is_zero(x.upper())) return x; else return interval::whole(); } @@ -148,7 +154,8 @@ interval div_zero(const interval& x) template inline interval div_zero(const T& x) { - if (is_zero(x)) return interval(static_cast(0), static_cast(0), true); + if (::boost::numeric::interval_lib::user::is_zero(x)) + return interval(static_cast(0), static_cast(0), true); else return interval::whole(); } @@ -156,8 +163,8 @@ template inline interval div_zero_part1(const interval& x, const interval& y, bool& b) { - // assert(y.lower() < 0 && y.upper() > 0); - if (is_zero(x.lower()) && is_zero(x.upper())) + // 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 I; @@ -167,9 +174,9 @@ interval div_zero_part1(const interval& x, const T& yu = y.upper(); typedef typename Policies::checking checking; const T& inf = checking::inf(); - if (is_neg(xu)) + if (::boost::numeric::interval_lib::user::is_neg(xu)) { b = true; return I(-inf, rnd.div_up(xu, yu), true); } - else if (is_neg(xl)) + else if (::boost::numeric::interval_lib::user::is_neg(xl)) { b = false; return I(-inf, inf, true); } else { b = true; return I(-inf, rnd.div_up(xl, yl), true); } @@ -179,12 +186,12 @@ template inline interval div_zero_part2(const interval& x, const interval& y) { - // assert(y.lower() < 0 && y.upper() > 0 && (div_zero_part1(x, y, b), b)); + // 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 I; typedef typename Policies::checking checking; const T& inf = checking::inf(); - if (is_neg(x.upper())) + if (::boost::numeric::interval_lib::user::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); diff --git a/include/boost/numeric/interval/detail/test_input.hpp b/include/boost/numeric/interval/detail/test_input.hpp index bd454f4..07b1096 100644 --- a/include/boost/numeric/interval/detail/test_input.hpp +++ b/include/boost/numeric/interval/detail/test_input.hpp @@ -21,17 +21,21 @@ namespace boost { namespace numeric { namespace interval_lib { +namespace user { + +template inline +bool is_zero(T const &v) { return v == static_cast(0); } + +template inline +bool is_neg (T const &v) { return v < static_cast(0); } + +template inline +bool is_pos (T const &v) { return v > static_cast(0); } + +} // namespace user + namespace detail { -template inline -bool is_neg(const T& x) { return x < static_cast(0); } - -template inline -bool is_zero(const T& x) { return x == static_cast(0); } - -template inline -bool is_pos(const T& x) { return x > static_cast(0); } - template inline bool test_input(const interval& x) { typedef typename Policies::checking checking; diff --git a/include/boost/numeric/interval/transc.hpp b/include/boost/numeric/interval/transc.hpp index ca08ccc..85521f8 100644 --- a/include/boost/numeric/interval/transc.hpp +++ b/include/boost/numeric/interval/transc.hpp @@ -47,7 +47,7 @@ interval log(const interval& x) return I::empty(); typename Policies::rounding rnd; typedef typename Policies::checking checking; - T l = (x.lower() <= static_cast(0)) + T l = !interval_lib::user::is_pos(x.lower()) ? -checking::inf() : rnd.log_down(x.lower()); return I(l, rnd.log_up(x.upper()), true); } @@ -176,9 +176,9 @@ interval cosh(const interval& x) if (interval_lib::detail::test_input(x)) return I::empty(); typename Policies::rounding rnd; - if (interval_lib::detail::is_neg(x.upper())) + 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::detail::is_neg(x.lower())) + 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(0), rnd.cosh_up(-x.lower() > x.upper() ? x.lower() : x.upper()), true); diff --git a/include/boost/numeric/interval/utility.hpp b/include/boost/numeric/interval/utility.hpp index 97b1e2d..95355aa 100644 --- a/include/boost/numeric/interval/utility.hpp +++ b/include/boost/numeric/interval/utility.hpp @@ -262,8 +262,8 @@ interval abs(const interval& x) typedef interval I; if (interval_lib::detail::test_input(x)) return I::empty(); - if (!interval_lib::detail::is_neg(x.lower())) return x; - if (interval_lib::detail::is_neg(x.upper())) return -x; + if (!interval_lib::user::is_neg(x.lower())) return x; + if (!interval_lib::user::is_pos(x.upper())) return -x; return I(static_cast(0), max(-x.lower(), x.upper()), true); }