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 
11 #ifndef BOOST_NUMERIC_INTERVAL_COMPARE_EXPLICIT_HPP
12 #define BOOST_NUMERIC_INTERVAL_COMPARE_EXPLICIT_HPP
13 
14 #include <boost/numeric/interval/detail/interval_prototype.hpp>
15 
16 namespace boost {
17 namespace numeric {
18 namespace interval_lib {
19 
20 /*
21  * Certainly... operations
22  */
23 
24 template<class T, class Policies1, class Policies2> inline
cerlt(const interval<T,Policies1> & x,const interval<T,Policies2> & y)25 bool cerlt(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
26 {
27   return x.upper() < y.lower();
28 }
29 
30 template<class T, class Policies> inline
cerlt(const interval<T,Policies> & x,const T & y)31 bool cerlt(const interval<T, Policies>& x, const T& y)
32 {
33   return x.upper() < y;
34 }
35 
36 template<class T, class Policies> inline
cerlt(const T & x,const interval<T,Policies> & y)37 bool cerlt(const T& x, const interval<T, Policies>& y)
38 {
39   return x < y.lower();
40 }
41 
42 template<class T, class Policies1, class Policies2> inline
cerle(const interval<T,Policies1> & x,const interval<T,Policies2> & y)43 bool cerle(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
44 {
45   return x.upper() <= y.lower();
46 }
47 
48 template<class T, class Policies> inline
cerle(const interval<T,Policies> & x,const T & y)49 bool cerle(const interval<T, Policies>& x, const T& y)
50 {
51   return x.upper() <= y;
52 }
53 
54 template<class T, class Policies> inline
cerle(const T & x,const interval<T,Policies> & y)55 bool cerle(const T& x, const interval<T, Policies>& y)
56 {
57   return x <= y.lower();
58 }
59 
60 template<class T, class Policies1, class Policies2> inline
cergt(const interval<T,Policies1> & x,const interval<T,Policies2> & y)61 bool cergt(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
62 {
63   return x.lower() > y.upper();
64 }
65 
66 template<class T, class Policies> inline
cergt(const interval<T,Policies> & x,const T & y)67 bool cergt(const interval<T, Policies>& x, const T& y)
68 {
69   return x.lower() > y;
70 }
71 
72 template<class T, class Policies> inline
cergt(const T & x,const interval<T,Policies> & y)73 bool cergt(const T& x, const interval<T, Policies>& y)
74 {
75   return x > y.upper();
76 }
77 
78 template<class T, class Policies1, class Policies2> inline
cerge(const interval<T,Policies1> & x,const interval<T,Policies2> & y)79 bool cerge(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
80 {
81   return x.lower() >= y.upper();
82 }
83 
84 template<class T, class Policies> inline
cerge(const interval<T,Policies> & x,const T & y)85 bool cerge(const interval<T, Policies>& x, const T& y)
86 {
87   return x.lower() >= y;
88 }
89 
90 template<class T, class Policies> inline
cerge(const T & x,const interval<T,Policies> & y)91 bool cerge(const T& x, const interval<T, Policies>& y)
92 {
93   return x >= y.upper();
94 }
95 
96 template<class T, class Policies1, class Policies2> inline
cereq(const interval<T,Policies1> & x,const interval<T,Policies2> & y)97 bool cereq(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
98 {
99   return x.lower() == y.upper() && y.lower() == x.upper();
100 }
101 
102 template<class T, class Policies> inline
cereq(const interval<T,Policies> & x,const T & y)103 bool cereq(const interval<T, Policies>& x, const T& y)
104 {
105   return x.lower() == y && x.upper() == y;
106 }
107 
108 template<class T, class Policies> inline
cereq(const T & x,const interval<T,Policies> & y)109 bool cereq(const T& x, const interval<T, Policies>& y)
110 {
111   return x == y.lower() && x == y.upper();
112 }
113 
114 template<class T, class Policies1, class Policies2> inline
cerne(const interval<T,Policies1> & x,const interval<T,Policies2> & y)115 bool cerne(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
116 {
117   return x.upper() < y.lower() || y.upper() < x.lower();
118 }
119 
120 template<class T, class Policies> inline
cerne(const interval<T,Policies> & x,const T & y)121 bool cerne(const interval<T, Policies>& x, const T& y)
122 {
123   return x.upper() < y || y < x.lower();
124 }
125 
126 template<class T, class Policies> inline
cerne(const T & x,const interval<T,Policies> & y)127 bool cerne(const T& x, const interval<T, Policies>& y)
128 {
129   return x < y.lower() || y.upper() < x;
130 }
131 
132 /*
133  * Possibly... comparisons
134  */
135 
136 template<class T, class Policies1, class Policies2> inline
poslt(const interval<T,Policies1> & x,const interval<T,Policies2> & y)137 bool poslt(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
138 {
139   return x.lower() < y.upper();
140 }
141 
142 template<class T, class Policies> inline
poslt(const interval<T,Policies> & x,const T & y)143 bool poslt(const interval<T, Policies>& x, const T& y)
144 {
145   return x.lower() < y;
146 }
147 
148 template<class T, class Policies> inline
poslt(const T & x,const interval<T,Policies> & y)149 bool poslt(const T& x, const interval<T, Policies>& y)
150 {
151   return x < y.upper();
152 }
153 
154 template<class T, class Policies1, class Policies2> inline
posle(const interval<T,Policies1> & x,const interval<T,Policies2> & y)155 bool posle(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
156 {
157   return x.lower() <= y.upper();
158 }
159 
160 template<class T, class Policies> inline
posle(const interval<T,Policies> & x,const T & y)161 bool posle(const interval<T, Policies>& x, const T& y)
162 {
163   return x.lower() <= y;
164 }
165 
166 template<class T, class Policies> inline
posle(const T & x,const interval<T,Policies> & y)167 bool posle(const T& x, const interval<T, Policies>& y)
168 {
169   return x <= y.upper();
170 }
171 
172 template<class T, class Policies1, class Policies2> inline
posgt(const interval<T,Policies1> & x,const interval<T,Policies2> & y)173 bool posgt(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
174 {
175   return x.upper() > y.lower();
176 }
177 
178 template<class T, class Policies> inline
posgt(const interval<T,Policies> & x,const T & y)179 bool posgt(const interval<T, Policies>& x, const T& y)
180 {
181   return x.upper() > y;
182 }
183 
184 template<class T, class Policies> inline
posgt(const T & x,const interval<T,Policies> & y)185 bool posgt(const T& x, const interval<T, Policies> & y)
186 {
187   return x > y.lower();
188 }
189 
190 template<class T, class Policies1, class Policies2> inline
posge(const interval<T,Policies1> & x,const interval<T,Policies2> & y)191 bool posge(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
192 {
193   return x.upper() >= y.lower();
194 }
195 
196 template<class T, class Policies> inline
posge(const interval<T,Policies> & x,const T & y)197 bool posge(const interval<T, Policies>& x, const T& y)
198 {
199   return x.upper() >= y;
200 }
201 
202 template<class T, class Policies> inline
posge(const T & x,const interval<T,Policies> & y)203 bool posge(const T& x, const interval<T, Policies>& y)
204 {
205   return x >= y.lower();
206 }
207 
208 template<class T, class Policies1, class Policies2> inline
poseq(const interval<T,Policies1> & x,const interval<T,Policies2> & y)209 bool poseq(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
210 {
211   return x.upper() >= y.lower() && y.upper() >= x.lower();
212 }
213 
214 template<class T, class Policies> inline
poseq(const interval<T,Policies> & x,const T & y)215 bool poseq(const interval<T, Policies>& x, const T& y)
216 {
217   return x.upper() >= y && y >= x.lower();
218 }
219 
220 template<class T, class Policies> inline
poseq(const T & x,const interval<T,Policies> & y)221 bool poseq(const T& x, const interval<T, Policies>& y)
222 {
223   return x >= y.lower() && y.upper() >= x;
224 }
225 
226 template<class T, class Policies1, class Policies2> inline
posne(const interval<T,Policies1> & x,const interval<T,Policies2> & y)227 bool posne(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
228 {
229   return x.upper() != y.lower() || y.upper() != x.lower();
230 }
231 
232 template<class T, class Policies> inline
posne(const interval<T,Policies> & x,const T & y)233 bool posne(const interval<T, Policies>& x, const T& y)
234 {
235   return x.upper() != y || y != x.lower();
236 }
237 
238 template<class T, class Policies> inline
posne(const T & x,const interval<T,Policies> & y)239 bool posne(const T& x, const interval<T, Policies>& y)
240 {
241   return x != y.lower() || y.upper() != x;
242 }
243 
244 } // namespace interval_lib
245 } // namespace numeric
246 } //namespace boost
247 
248 #endif // BOOST_NUMERIC_INTERVAL_COMPARE_EXPLICIT_HPP
249