1 /* Boost interval/compare/tribool.hpp template implementation file
3 * Copyright 2002-2003 Guillaume Melquiond
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)
10 #ifndef BOOST_NUMERIC_INTERVAL_COMPARE_TRIBOOL_HPP
11 #define BOOST_NUMERIC_INTERVAL_COMPARE_TRIBOOL_HPP
13 #include <boost/numeric/interval/detail/interval_prototype.hpp>
14 #include <boost/numeric/interval/detail/test_input.hpp>
15 #include <boost/logic/tribool.hpp>
19 namespace interval_lib {
23 template<class T, class Policies1, class Policies2> inline
24 logic::tribool operator<(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
26 if (detail::test_input(x, y)) throw comparison_error();
27 if (x.upper() < y.lower()) return true;
28 if (x.lower() >= y.upper()) return false;
29 return logic::indeterminate;
32 template<class T, class Policies> inline
33 logic::tribool operator<(const interval<T, Policies>& x, const T& y)
35 if (detail::test_input(x, y)) throw comparison_error();
36 if (x.upper() < y) return true;
37 if (x.lower() >= y) return false;
38 return logic::indeterminate;
41 template<class T, class Policies1, class Policies2> inline
42 logic::tribool operator<=(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
44 if (detail::test_input(x, y)) throw comparison_error();
45 if (x.upper() <= y.lower()) return true;
46 if (x.lower() > y.upper()) return false;
47 return logic::indeterminate;
50 template<class T, class Policies> inline
51 logic::tribool operator<=(const interval<T, Policies>& x, const T& y)
53 if (detail::test_input(x, y)) throw comparison_error();
54 if (x.upper() <= y) return true;
55 if (x.lower() > y) return false;
56 return logic::indeterminate;
59 template<class T, class Policies1, class Policies2> inline
60 logic::tribool operator>(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
62 if (detail::test_input(x, y)) throw comparison_error();
63 if (x.lower() > y.upper()) return true;
64 if (x.upper() <= y.lower()) return false;
65 return logic::indeterminate;
68 template<class T, class Policies> inline
69 logic::tribool operator>(const interval<T, Policies>& x, const T& y)
71 if (detail::test_input(x, y)) throw comparison_error();
72 if (x.lower() > y) return true;
73 if (x.upper() <= y) return false;
74 return logic::indeterminate;
77 template<class T, class Policies1, class Policies2> inline
78 logic::tribool operator>=(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
80 if (detail::test_input(x, y)) throw comparison_error();
81 if (x.lower() >= y.upper()) return true;
82 if (x.upper() < y.lower()) return false;
83 return logic::indeterminate;
86 template<class T, class Policies> inline
87 logic::tribool operator>=(const interval<T, Policies>& x, const T& y)
89 if (detail::test_input(x, y)) throw comparison_error();
90 if (x.lower() >= y) return true;
91 if (x.upper() < y) return false;
92 return logic::indeterminate;
95 template<class T, class Policies1, class Policies2> inline
96 logic::tribool operator==(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
98 if (detail::test_input(x, y)) throw comparison_error();
99 if (x.upper() == y.lower() && x.lower() == y.upper()) return true;
100 if (x.upper() < y.lower() || x.lower() > y.upper()) return false;
101 return logic::indeterminate;
104 template<class T, class Policies> inline
105 logic::tribool operator==(const interval<T, Policies>& x, const T& y)
107 if (detail::test_input(x, y)) throw comparison_error();
108 if (x.upper() == y && x.lower() == y) return true;
109 if (x.upper() < y || x.lower() > y) return false;
110 return logic::indeterminate;
113 template<class T, class Policies1, class Policies2> inline
114 logic::tribool operator!=(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
116 if (detail::test_input(x, y)) throw comparison_error();
117 if (x.upper() < y.lower() || x.lower() > y.upper()) return true;
118 if (x.upper() == y.lower() && x.lower() == y.upper()) return false;
119 return logic::indeterminate;
122 template<class T, class Policies> inline
123 logic::tribool operator!=(const interval<T, Policies>& x, const T& y)
125 if (detail::test_input(x, y)) throw comparison_error();
126 if (x.upper() < y || x.lower() > y) return true;
127 if (x.upper() == y && x.lower() == y) return false;
128 return logic::indeterminate;
131 } // namespace tribool
132 } // namespace compare
133 } // namespace interval_lib
134 } // namespace numeric
138 #endif // BOOST_NUMERIC_INTERVAL_COMPARE_TRIBOOL_HPP