Chris@16
|
1 /* Boost interval/compare/tribool.hpp template implementation file
|
Chris@16
|
2 *
|
Chris@16
|
3 * Copyright 2002-2003 Guillaume Melquiond
|
Chris@16
|
4 *
|
Chris@16
|
5 * Distributed under the Boost Software License, Version 1.0.
|
Chris@16
|
6 * (See accompanying file LICENSE_1_0.txt or
|
Chris@16
|
7 * copy at http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
8 */
|
Chris@16
|
9
|
Chris@16
|
10 #ifndef BOOST_NUMERIC_INTERVAL_COMPARE_TRIBOOL_HPP
|
Chris@16
|
11 #define BOOST_NUMERIC_INTERVAL_COMPARE_TRIBOOL_HPP
|
Chris@16
|
12
|
Chris@16
|
13 #include <boost/numeric/interval/detail/interval_prototype.hpp>
|
Chris@16
|
14 #include <boost/numeric/interval/detail/test_input.hpp>
|
Chris@16
|
15 #include <boost/logic/tribool.hpp>
|
Chris@16
|
16
|
Chris@16
|
17 namespace boost {
|
Chris@16
|
18 namespace numeric {
|
Chris@16
|
19 namespace interval_lib {
|
Chris@16
|
20 namespace compare {
|
Chris@16
|
21 namespace tribool {
|
Chris@16
|
22
|
Chris@16
|
23 template<class T, class Policies1, class Policies2> inline
|
Chris@16
|
24 logic::tribool operator<(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
|
Chris@16
|
25 {
|
Chris@16
|
26 if (detail::test_input(x, y)) throw comparison_error();
|
Chris@16
|
27 if (x.upper() < y.lower()) return true;
|
Chris@16
|
28 if (x.lower() >= y.upper()) return false;
|
Chris@16
|
29 return logic::indeterminate;
|
Chris@16
|
30 }
|
Chris@16
|
31
|
Chris@16
|
32 template<class T, class Policies> inline
|
Chris@16
|
33 logic::tribool operator<(const interval<T, Policies>& x, const T& y)
|
Chris@16
|
34 {
|
Chris@16
|
35 if (detail::test_input(x, y)) throw comparison_error();
|
Chris@16
|
36 if (x.upper() < y) return true;
|
Chris@16
|
37 if (x.lower() >= y) return false;
|
Chris@16
|
38 return logic::indeterminate;
|
Chris@16
|
39 }
|
Chris@16
|
40
|
Chris@16
|
41 template<class T, class Policies1, class Policies2> inline
|
Chris@16
|
42 logic::tribool operator<=(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
|
Chris@16
|
43 {
|
Chris@16
|
44 if (detail::test_input(x, y)) throw comparison_error();
|
Chris@16
|
45 if (x.upper() <= y.lower()) return true;
|
Chris@16
|
46 if (x.lower() > y.upper()) return false;
|
Chris@16
|
47 return logic::indeterminate;
|
Chris@16
|
48 }
|
Chris@16
|
49
|
Chris@16
|
50 template<class T, class Policies> inline
|
Chris@16
|
51 logic::tribool operator<=(const interval<T, Policies>& x, const T& y)
|
Chris@16
|
52 {
|
Chris@16
|
53 if (detail::test_input(x, y)) throw comparison_error();
|
Chris@16
|
54 if (x.upper() <= y) return true;
|
Chris@16
|
55 if (x.lower() > y) return false;
|
Chris@16
|
56 return logic::indeterminate;
|
Chris@16
|
57 }
|
Chris@16
|
58
|
Chris@16
|
59 template<class T, class Policies1, class Policies2> inline
|
Chris@16
|
60 logic::tribool operator>(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
|
Chris@16
|
61 {
|
Chris@16
|
62 if (detail::test_input(x, y)) throw comparison_error();
|
Chris@16
|
63 if (x.lower() > y.upper()) return true;
|
Chris@16
|
64 if (x.upper() <= y.lower()) return false;
|
Chris@16
|
65 return logic::indeterminate;
|
Chris@16
|
66 }
|
Chris@16
|
67
|
Chris@16
|
68 template<class T, class Policies> inline
|
Chris@16
|
69 logic::tribool operator>(const interval<T, Policies>& x, const T& y)
|
Chris@16
|
70 {
|
Chris@16
|
71 if (detail::test_input(x, y)) throw comparison_error();
|
Chris@16
|
72 if (x.lower() > y) return true;
|
Chris@16
|
73 if (x.upper() <= y) return false;
|
Chris@16
|
74 return logic::indeterminate;
|
Chris@16
|
75 }
|
Chris@16
|
76
|
Chris@16
|
77 template<class T, class Policies1, class Policies2> inline
|
Chris@16
|
78 logic::tribool operator>=(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
|
Chris@16
|
79 {
|
Chris@16
|
80 if (detail::test_input(x, y)) throw comparison_error();
|
Chris@16
|
81 if (x.lower() >= y.upper()) return true;
|
Chris@16
|
82 if (x.upper() < y.lower()) return false;
|
Chris@16
|
83 return logic::indeterminate;
|
Chris@16
|
84 }
|
Chris@16
|
85
|
Chris@16
|
86 template<class T, class Policies> inline
|
Chris@16
|
87 logic::tribool operator>=(const interval<T, Policies>& x, const T& y)
|
Chris@16
|
88 {
|
Chris@16
|
89 if (detail::test_input(x, y)) throw comparison_error();
|
Chris@16
|
90 if (x.lower() >= y) return true;
|
Chris@16
|
91 if (x.upper() < y) return false;
|
Chris@16
|
92 return logic::indeterminate;
|
Chris@16
|
93 }
|
Chris@16
|
94
|
Chris@16
|
95 template<class T, class Policies1, class Policies2> inline
|
Chris@16
|
96 logic::tribool operator==(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
|
Chris@16
|
97 {
|
Chris@16
|
98 if (detail::test_input(x, y)) throw comparison_error();
|
Chris@16
|
99 if (x.upper() == y.lower() && x.lower() == y.upper()) return true;
|
Chris@16
|
100 if (x.upper() < y.lower() || x.lower() > y.upper()) return false;
|
Chris@16
|
101 return logic::indeterminate;
|
Chris@16
|
102 }
|
Chris@16
|
103
|
Chris@16
|
104 template<class T, class Policies> inline
|
Chris@16
|
105 logic::tribool operator==(const interval<T, Policies>& x, const T& y)
|
Chris@16
|
106 {
|
Chris@16
|
107 if (detail::test_input(x, y)) throw comparison_error();
|
Chris@16
|
108 if (x.upper() == y && x.lower() == y) return true;
|
Chris@16
|
109 if (x.upper() < y || x.lower() > y) return false;
|
Chris@16
|
110 return logic::indeterminate;
|
Chris@16
|
111 }
|
Chris@16
|
112
|
Chris@16
|
113 template<class T, class Policies1, class Policies2> inline
|
Chris@16
|
114 logic::tribool operator!=(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
|
Chris@16
|
115 {
|
Chris@16
|
116 if (detail::test_input(x, y)) throw comparison_error();
|
Chris@16
|
117 if (x.upper() < y.lower() || x.lower() > y.upper()) return true;
|
Chris@16
|
118 if (x.upper() == y.lower() && x.lower() == y.upper()) return false;
|
Chris@16
|
119 return logic::indeterminate;
|
Chris@16
|
120 }
|
Chris@16
|
121
|
Chris@16
|
122 template<class T, class Policies> inline
|
Chris@16
|
123 logic::tribool operator!=(const interval<T, Policies>& x, const T& y)
|
Chris@16
|
124 {
|
Chris@16
|
125 if (detail::test_input(x, y)) throw comparison_error();
|
Chris@16
|
126 if (x.upper() < y || x.lower() > y) return true;
|
Chris@16
|
127 if (x.upper() == y && x.lower() == y) return false;
|
Chris@16
|
128 return logic::indeterminate;
|
Chris@16
|
129 }
|
Chris@16
|
130
|
Chris@16
|
131 } // namespace tribool
|
Chris@16
|
132 } // namespace compare
|
Chris@16
|
133 } // namespace interval_lib
|
Chris@16
|
134 } // namespace numeric
|
Chris@16
|
135 } // namespace boost
|
Chris@16
|
136
|
Chris@16
|
137
|
Chris@16
|
138 #endif // BOOST_NUMERIC_INTERVAL_COMPARE_TRIBOOL_HPP
|