explicit.hpp 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. /* Boost interval/compare/explicit.hpp template implementation file
  2. *
  3. * Copyright 2000 Jens Maurer
  4. * Copyright 2002 Hervé Brönnimann, Guillaume Melquiond, Sylvain Pion
  5. *
  6. * Distributed under the Boost Software License, Version 1.0.
  7. * (See accompanying file LICENSE_1_0.txt or
  8. * copy at http://www.boost.org/LICENSE_1_0.txt)
  9. */
  10. #ifndef BOOST_NUMERIC_INTERVAL_COMPARE_EXPLICIT_HPP
  11. #define BOOST_NUMERIC_INTERVAL_COMPARE_EXPLICIT_HPP
  12. #include <boost/numeric/interval/detail/interval_prototype.hpp>
  13. namespace boost {
  14. namespace numeric {
  15. namespace interval_lib {
  16. /*
  17. * Certainly... operations
  18. */
  19. template<class T, class Policies1, class Policies2> inline
  20. bool cerlt(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
  21. {
  22. return x.upper() < y.lower();
  23. }
  24. template<class T, class Policies> inline
  25. bool cerlt(const interval<T, Policies>& x, const T& y)
  26. {
  27. return x.upper() < y;
  28. }
  29. template<class T, class Policies> inline
  30. bool cerlt(const T& x, const interval<T, Policies>& y)
  31. {
  32. return x < y.lower();
  33. }
  34. template<class T, class Policies1, class Policies2> inline
  35. bool cerle(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
  36. {
  37. return x.upper() <= y.lower();
  38. }
  39. template<class T, class Policies> inline
  40. bool cerle(const interval<T, Policies>& x, const T& y)
  41. {
  42. return x.upper() <= y;
  43. }
  44. template<class T, class Policies> inline
  45. bool cerle(const T& x, const interval<T, Policies>& y)
  46. {
  47. return x <= y.lower();
  48. }
  49. template<class T, class Policies1, class Policies2> inline
  50. bool cergt(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
  51. {
  52. return x.lower() > y.upper();
  53. }
  54. template<class T, class Policies> inline
  55. bool cergt(const interval<T, Policies>& x, const T& y)
  56. {
  57. return x.lower() > y;
  58. }
  59. template<class T, class Policies> inline
  60. bool cergt(const T& x, const interval<T, Policies>& y)
  61. {
  62. return x > y.upper();
  63. }
  64. template<class T, class Policies1, class Policies2> inline
  65. bool cerge(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
  66. {
  67. return x.lower() >= y.upper();
  68. }
  69. template<class T, class Policies> inline
  70. bool cerge(const interval<T, Policies>& x, const T& y)
  71. {
  72. return x.lower() >= y;
  73. }
  74. template<class T, class Policies> inline
  75. bool cerge(const T& x, const interval<T, Policies>& y)
  76. {
  77. return x >= y.upper();
  78. }
  79. template<class T, class Policies1, class Policies2> inline
  80. bool cereq(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
  81. {
  82. return x.lower() == y.upper() && y.lower() == x.upper();
  83. }
  84. template<class T, class Policies> inline
  85. bool cereq(const interval<T, Policies>& x, const T& y)
  86. {
  87. return x.lower() == y && x.upper() == y;
  88. }
  89. template<class T, class Policies> inline
  90. bool cereq(const T& x, const interval<T, Policies>& y)
  91. {
  92. return x == y.lower() && x == y.upper();
  93. }
  94. template<class T, class Policies1, class Policies2> inline
  95. bool cerne(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
  96. {
  97. return x.upper() < y.lower() || y.upper() < x.lower();
  98. }
  99. template<class T, class Policies> inline
  100. bool cerne(const interval<T, Policies>& x, const T& y)
  101. {
  102. return x.upper() < y || y < x.lower();
  103. }
  104. template<class T, class Policies> inline
  105. bool cerne(const T& x, const interval<T, Policies>& y)
  106. {
  107. return x < y.lower() || y.upper() < x;
  108. }
  109. /*
  110. * Possibly... comparisons
  111. */
  112. template<class T, class Policies1, class Policies2> inline
  113. bool poslt(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
  114. {
  115. return x.lower() < y.upper();
  116. }
  117. template<class T, class Policies> inline
  118. bool poslt(const interval<T, Policies>& x, const T& y)
  119. {
  120. return x.lower() < y;
  121. }
  122. template<class T, class Policies> inline
  123. bool poslt(const T& x, const interval<T, Policies>& y)
  124. {
  125. return x < y.upper();
  126. }
  127. template<class T, class Policies1, class Policies2> inline
  128. bool posle(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
  129. {
  130. return x.lower() <= y.upper();
  131. }
  132. template<class T, class Policies> inline
  133. bool posle(const interval<T, Policies>& x, const T& y)
  134. {
  135. return x.lower() <= y;
  136. }
  137. template<class T, class Policies> inline
  138. bool posle(const T& x, const interval<T, Policies>& y)
  139. {
  140. return x <= y.upper();
  141. }
  142. template<class T, class Policies1, class Policies2> inline
  143. bool posgt(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
  144. {
  145. return x.upper() > y.lower();
  146. }
  147. template<class T, class Policies> inline
  148. bool posgt(const interval<T, Policies>& x, const T& y)
  149. {
  150. return x.upper() > y;
  151. }
  152. template<class T, class Policies> inline
  153. bool posgt(const T& x, const interval<T, Policies> & y)
  154. {
  155. return x > y.lower();
  156. }
  157. template<class T, class Policies1, class Policies2> inline
  158. bool posge(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
  159. {
  160. return x.upper() >= y.lower();
  161. }
  162. template<class T, class Policies> inline
  163. bool posge(const interval<T, Policies>& x, const T& y)
  164. {
  165. return x.upper() >= y;
  166. }
  167. template<class T, class Policies> inline
  168. bool posge(const T& x, const interval<T, Policies>& y)
  169. {
  170. return x >= y.lower();
  171. }
  172. template<class T, class Policies1, class Policies2> inline
  173. bool poseq(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
  174. {
  175. return x.upper() >= y.lower() && y.upper() >= x.lower();
  176. }
  177. template<class T, class Policies> inline
  178. bool poseq(const interval<T, Policies>& x, const T& y)
  179. {
  180. return x.upper() >= y && y >= x.lower();
  181. }
  182. template<class T, class Policies> inline
  183. bool poseq(const T& x, const interval<T, Policies>& y)
  184. {
  185. return x >= y.lower() && y.upper() >= x;
  186. }
  187. template<class T, class Policies1, class Policies2> inline
  188. bool posne(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
  189. {
  190. return x.upper() != y.lower() || y.upper() != x.lower();
  191. }
  192. template<class T, class Policies> inline
  193. bool posne(const interval<T, Policies>& x, const T& y)
  194. {
  195. return x.upper() != y || y != x.lower();
  196. }
  197. template<class T, class Policies> inline
  198. bool posne(const T& x, const interval<T, Policies>& y)
  199. {
  200. return x != y.lower() || y.upper() != x;
  201. }
  202. } // namespace interval_lib
  203. } // namespace numeric
  204. } //namespace boost
  205. #endif // BOOST_NUMERIC_INTERVAL_COMPARE_EXPLICIT_HPP