tribool.hpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /* Boost interval/compare/tribool.hpp template implementation file
  2. *
  3. * Copyright 2002-2003 Guillaume Melquiond
  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_COMPARE_TRIBOOL_HPP
  10. #define BOOST_NUMERIC_INTERVAL_COMPARE_TRIBOOL_HPP
  11. #include <boost/numeric/interval/detail/interval_prototype.hpp>
  12. #include <boost/numeric/interval/detail/test_input.hpp>
  13. #include <boost/logic/tribool.hpp>
  14. namespace boost {
  15. namespace numeric {
  16. namespace interval_lib {
  17. namespace compare {
  18. namespace tribool {
  19. template<class T, class Policies1, class Policies2> inline
  20. logic::tribool operator<(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
  21. {
  22. if (detail::test_input(x, y)) throw comparison_error();
  23. if (x.upper() < y.lower()) return true;
  24. if (x.lower() >= y.upper()) return false;
  25. return logic::indeterminate;
  26. }
  27. template<class T, class Policies> inline
  28. logic::tribool operator<(const interval<T, Policies>& x, const T& y)
  29. {
  30. if (detail::test_input(x, y)) throw comparison_error();
  31. if (x.upper() < y) return true;
  32. if (x.lower() >= y) return false;
  33. return logic::indeterminate;
  34. }
  35. template<class T, class Policies1, class Policies2> inline
  36. logic::tribool operator<=(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
  37. {
  38. if (detail::test_input(x, y)) throw comparison_error();
  39. if (x.upper() <= y.lower()) return true;
  40. if (x.lower() > y.upper()) return false;
  41. return logic::indeterminate;
  42. }
  43. template<class T, class Policies> inline
  44. logic::tribool operator<=(const interval<T, Policies>& x, const T& y)
  45. {
  46. if (detail::test_input(x, y)) throw comparison_error();
  47. if (x.upper() <= y) return true;
  48. if (x.lower() > y) return false;
  49. return logic::indeterminate;
  50. }
  51. template<class T, class Policies1, class Policies2> inline
  52. logic::tribool operator>(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
  53. {
  54. if (detail::test_input(x, y)) throw comparison_error();
  55. if (x.lower() > y.upper()) return true;
  56. if (x.upper() <= y.lower()) return false;
  57. return logic::indeterminate;
  58. }
  59. template<class T, class Policies> inline
  60. logic::tribool operator>(const interval<T, Policies>& x, const T& y)
  61. {
  62. if (detail::test_input(x, y)) throw comparison_error();
  63. if (x.lower() > y) return true;
  64. if (x.upper() <= y) return false;
  65. return logic::indeterminate;
  66. }
  67. template<class T, class Policies1, class Policies2> inline
  68. logic::tribool operator>=(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
  69. {
  70. if (detail::test_input(x, y)) throw comparison_error();
  71. if (x.lower() >= y.upper()) return true;
  72. if (x.upper() < y.lower()) return false;
  73. return logic::indeterminate;
  74. }
  75. template<class T, class Policies> inline
  76. logic::tribool operator>=(const interval<T, Policies>& x, const T& y)
  77. {
  78. if (detail::test_input(x, y)) throw comparison_error();
  79. if (x.lower() >= y) return true;
  80. if (x.upper() < y) return false;
  81. return logic::indeterminate;
  82. }
  83. template<class T, class Policies1, class Policies2> inline
  84. logic::tribool operator==(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
  85. {
  86. if (detail::test_input(x, y)) throw comparison_error();
  87. if (x.upper() == y.lower() && x.lower() == y.upper()) return true;
  88. if (x.upper() < y.lower() || x.lower() > y.upper()) return false;
  89. return logic::indeterminate;
  90. }
  91. template<class T, class Policies> inline
  92. logic::tribool operator==(const interval<T, Policies>& x, const T& y)
  93. {
  94. if (detail::test_input(x, y)) throw comparison_error();
  95. if (x.upper() == y && x.lower() == y) return true;
  96. if (x.upper() < y || x.lower() > y) return false;
  97. return logic::indeterminate;
  98. }
  99. template<class T, class Policies1, class Policies2> inline
  100. logic::tribool operator!=(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
  101. {
  102. if (detail::test_input(x, y)) throw comparison_error();
  103. if (x.upper() < y.lower() || x.lower() > y.upper()) return true;
  104. if (x.upper() == y.lower() && x.lower() == y.upper()) return false;
  105. return logic::indeterminate;
  106. }
  107. template<class T, class Policies> inline
  108. logic::tribool operator!=(const interval<T, Policies>& x, const T& y)
  109. {
  110. if (detail::test_input(x, y)) throw comparison_error();
  111. if (x.upper() < y || x.lower() > y) return true;
  112. if (x.upper() == y && x.lower() == y) return false;
  113. return logic::indeterminate;
  114. }
  115. } // namespace tribool
  116. } // namespace compare
  117. } // namespace interval_lib
  118. } // namespace numeric
  119. } // namespace boost
  120. #endif // BOOST_NUMERIC_INTERVAL_COMPARE_TRIBOOL_HPP