Switched from detail::is_ to user::is_

[SVN r22286]
This commit is contained in:
Guillaume Melquiond
2004-02-16 11:59:29 +00:00
parent aa73afa074
commit db4eccd4c2
7 changed files with 92 additions and 81 deletions

View File

@@ -187,39 +187,39 @@ interval<T, Policies> operator*(const interval<T, Policies>& 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<T>(0), static_cast<T>(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<T>(0), static_cast<T>(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<T>(0), static_cast<T>(0), true);
@@ -237,9 +237,9 @@ interval<T, Policies> operator*(const T& x, const interval<T, Policies>& 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<T>(0), static_cast<T>(0), true);
else
return I(rnd.mul_down(x, yl), rnd.mul_up(x, yu), true);
@@ -256,13 +256,13 @@ interval<T, Policies> operator/(const interval<T, Policies>& x,
if (interval_lib::detail::test_input(x, y))
return interval<T, Policies>::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<T, Policies>::empty();
@@ -276,13 +276,13 @@ 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 (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<T, Policies>(x);
else
return interval_lib::detail::div_negative<T, Policies>(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<T, Policies>(x, y.upper());
else
return interval<T, Policies>::empty();
@@ -293,12 +293,12 @@ interval<T, Policies> operator/(const T& x, const interval<T, Policies>& 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::detail::is_zero(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::detail::is_neg(y))
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);

View File

@@ -36,7 +36,7 @@ interval<T, Policies> fmod(const interval<T, Policies>& x,
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.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<T, Policies> fmod(const T& x, const interval<T, Policies>& 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 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<T, Policies> division_part1(const interval<T, Policies>& 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<T, Policies> multiplicative_inverse(const interval<T, Policies>& 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<T, Policies> pow(const interval<T, Policies>& 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<T>(1));
@@ -160,14 +160,14 @@ interval<T, Policies> pow(const interval<T, Policies>& 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<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::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<T>(0)) ? static_cast<T>(0) : rnd.sqrt_down(x.lower());
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);
}
@@ -199,9 +199,9 @@ interval<T, Policies> square(const interval<T, Policies>& 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<T>(0), (-xl > xu ? rnd.mul_up(xl, xl) : rnd.mul_up(xu, xu)), true);

View File

@@ -57,7 +57,7 @@ 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) || detail::is_zero(y))
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);

View File

@@ -37,18 +37,18 @@ interval<T, Policies> div_non_zero(const interval<T, Policies>& 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<T, Policies> div_non_zero(const T& x, const interval<T, Policies>& y)
typedef interval<T, Policies> 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<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 interval<T, Policies>& 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<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))
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<T, Policies> div_positive(const interval<T, Policies>& x, const T& yu)
template<class T, class Policies> inline
interval<T, Policies> div_positive(const T& x, const T& yu)
{
// assert(yu > T(0));
// assert(::boost::numeric::interval_lib::user::is_pos(yu));
typedef interval<T, Policies> I;
if (is_zero(x)) return I(static_cast<T>(0), static_cast<T>(0), true);
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;
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<T, Policies> div_positive(const T& x, const T& yu)
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()))
// 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;
@@ -114,9 +118,9 @@ interval<T, Policies> div_negative(const interval<T, Policies>& 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<T, Policies> div_negative(const interval<T, Policies>& x, const T& yl)
template<class T, class Policies> inline
interval<T, Policies> div_negative(const T& x, const T& yl)
{
// assert(yl < T(0));
// assert(::boost::numeric::interval_lib::user::is_neg(yl));
typedef interval<T, Policies> I;
if (is_zero(x)) return I(static_cast<T>(0), static_cast<T>(0), true);
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;
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<T, Policies> div_negative(const T& x, const T& yl)
template<class T, class Policies> inline
interval<T, Policies> div_zero(const interval<T, Policies>& 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<T, Policies>::whole();
}
@@ -148,7 +154,8 @@ interval<T, Policies> div_zero(const interval<T, Policies>& x)
template<class T, class Policies> inline
interval<T, Policies> div_zero(const T& x)
{
if (is_zero(x)) return interval<T, Policies>(static_cast<T>(0), static_cast<T>(0), 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();
}
@@ -156,8 +163,8 @@ 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(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<T, Policies> I;
@@ -167,9 +174,9 @@ interval<T, Policies> div_zero_part1(const interval<T, Policies>& 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<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));
// 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;
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);

View File

@@ -21,17 +21,21 @@
namespace boost {
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_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); }
} // namespace user
namespace detail {
template<class T> inline
bool is_neg(const T& x) { return x < static_cast<T>(0); }
template<class T> inline
bool is_zero(const T& x) { return x == static_cast<T>(0); }
template<class T> inline
bool is_pos(const T& x) { return x > static_cast<T>(0); }
template<class T, class Policies> inline
bool test_input(const interval<T, Policies>& x) {
typedef typename Policies::checking checking;

View File

@@ -47,7 +47,7 @@ interval<T, Policies> log(const interval<T, Policies>& x)
return I::empty();
typename Policies::rounding rnd;
typedef typename Policies::checking checking;
T l = (x.lower() <= static_cast<T>(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<T, Policies> cosh(const interval<T, Policies>& 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<T>(0), rnd.cosh_up(-x.lower() > x.upper() ? x.lower() : x.upper()), true);

View File

@@ -262,8 +262,8 @@ 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::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<T>(0), max(-x.lower(), x.upper()), true);
}