test_input.hpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /* Boost interval/detail/test_input.hpp file
  2. *
  3. * Copyright 2002 Hervé Brönnimann, Guillaume Melquiond, Sylvain Pion
  4. *
  5. * Distributed under the Boost Software License, Version 1.0.
  6. * (See accompanying file LICENSE_1_0.txt or
  7. * copy at http://www.boost.org/LICENSE_1_0.txt)
  8. */
  9. #ifndef BOOST_NUMERIC_INTERVAL_DETAIL_TEST_INPUT_HPP
  10. #define BOOST_NUMERIC_INTERVAL_DETAIL_TEST_INPUT_HPP
  11. #include <boost/numeric/interval/detail/interval_prototype.hpp>
  12. namespace boost {
  13. namespace numeric {
  14. namespace interval_lib {
  15. namespace user {
  16. template<class T> inline
  17. bool is_zero(T const &v) { return v == static_cast<T>(0); }
  18. template<class T> inline
  19. bool is_neg (T const &v) { return v < static_cast<T>(0); }
  20. template<class T> inline
  21. bool is_pos (T const &v) { return v > static_cast<T>(0); }
  22. } // namespace user
  23. namespace detail {
  24. template<class T, class Policies> inline
  25. bool test_input(const interval<T, Policies>& x) {
  26. typedef typename Policies::checking checking;
  27. return checking::is_empty(x.lower(), x.upper());
  28. }
  29. template<class T, class Policies1, class Policies2> inline
  30. bool test_input(const interval<T, Policies1>& x, const interval<T, Policies2>& y) {
  31. typedef typename Policies1::checking checking1;
  32. typedef typename Policies2::checking checking2;
  33. return checking1::is_empty(x.lower(), x.upper()) ||
  34. checking2::is_empty(y.lower(), y.upper());
  35. }
  36. template<class T, class Policies> inline
  37. bool test_input(const T& x, const interval<T, Policies>& y) {
  38. typedef typename Policies::checking checking;
  39. return checking::is_nan(x) || checking::is_empty(y.lower(), y.upper());
  40. }
  41. template<class T, class Policies> inline
  42. bool test_input(const interval<T, Policies>& x, const T& y) {
  43. typedef typename Policies::checking checking;
  44. return checking::is_empty(x.lower(), x.upper()) || checking::is_nan(y);
  45. }
  46. template<class T, class Policies> inline
  47. bool test_input(const T& x) {
  48. typedef typename Policies::checking checking;
  49. return checking::is_nan(x);
  50. }
  51. template<class T, class Policies> inline
  52. bool test_input(const T& x, const T& y) {
  53. typedef typename Policies::checking checking;
  54. return checking::is_nan(x) || checking::is_nan(y);
  55. }
  56. } // namespace detail
  57. } // namespace interval_lib
  58. } // namespace numeric
  59. } // namespace boost
  60. #endif // BOOST_NUMERIC_INTERVAL_DETAIL_TEST_INPUT_HPP