]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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 | ||
10 | #ifndef BOOST_NUMERIC_INTERVAL_COMPARE_TRIBOOL_HPP | |
11 | #define BOOST_NUMERIC_INTERVAL_COMPARE_TRIBOOL_HPP | |
12 | ||
13 | #include <boost/numeric/interval/detail/interval_prototype.hpp> | |
14 | #include <boost/numeric/interval/detail/test_input.hpp> | |
15 | #include <boost/logic/tribool.hpp> | |
16 | ||
17 | namespace boost { | |
18 | namespace numeric { | |
19 | namespace interval_lib { | |
20 | namespace compare { | |
21 | namespace tribool { | |
22 | ||
23 | template<class T, class Policies1, class Policies2> inline | |
24 | logic::tribool operator<(const interval<T, Policies1>& x, const interval<T, Policies2>& y) | |
25 | { | |
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; | |
30 | } | |
31 | ||
32 | template<class T, class Policies> inline | |
33 | logic::tribool operator<(const interval<T, Policies>& x, const T& y) | |
34 | { | |
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; | |
39 | } | |
40 | ||
41 | template<class T, class Policies1, class Policies2> inline | |
42 | logic::tribool operator<=(const interval<T, Policies1>& x, const interval<T, Policies2>& y) | |
43 | { | |
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; | |
48 | } | |
49 | ||
50 | template<class T, class Policies> inline | |
51 | logic::tribool operator<=(const interval<T, Policies>& x, const T& y) | |
52 | { | |
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; | |
57 | } | |
58 | ||
59 | template<class T, class Policies1, class Policies2> inline | |
60 | logic::tribool operator>(const interval<T, Policies1>& x, const interval<T, Policies2>& y) | |
61 | { | |
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; | |
66 | } | |
67 | ||
68 | template<class T, class Policies> inline | |
69 | logic::tribool operator>(const interval<T, Policies>& x, const T& y) | |
70 | { | |
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; | |
75 | } | |
76 | ||
77 | template<class T, class Policies1, class Policies2> inline | |
78 | logic::tribool operator>=(const interval<T, Policies1>& x, const interval<T, Policies2>& y) | |
79 | { | |
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; | |
84 | } | |
85 | ||
86 | template<class T, class Policies> inline | |
87 | logic::tribool operator>=(const interval<T, Policies>& x, const T& y) | |
88 | { | |
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; | |
93 | } | |
94 | ||
95 | template<class T, class Policies1, class Policies2> inline | |
96 | logic::tribool operator==(const interval<T, Policies1>& x, const interval<T, Policies2>& y) | |
97 | { | |
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; | |
102 | } | |
103 | ||
104 | template<class T, class Policies> inline | |
105 | logic::tribool operator==(const interval<T, Policies>& x, const T& y) | |
106 | { | |
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; | |
111 | } | |
112 | ||
113 | template<class T, class Policies1, class Policies2> inline | |
114 | logic::tribool operator!=(const interval<T, Policies1>& x, const interval<T, Policies2>& y) | |
115 | { | |
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; | |
120 | } | |
121 | ||
122 | template<class T, class Policies> inline | |
123 | logic::tribool operator!=(const interval<T, Policies>& x, const T& y) | |
124 | { | |
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; | |
129 | } | |
130 | ||
131 | } // namespace tribool | |
132 | } // namespace compare | |
133 | } // namespace interval_lib | |
134 | } // namespace numeric | |
135 | } // namespace boost | |
136 | ||
137 | ||
138 | #endif // BOOST_NUMERIC_INTERVAL_COMPARE_TRIBOOL_HPP |