source: NonGTP/Boost/boost/numeric/interval/compare/tribool.hpp @ 857

Revision 857, 4.6 KB checked in by igarcia, 19 years ago (diff)
Line 
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
17namespace boost {
18namespace numeric {
19namespace interval_lib {
20namespace compare {
21namespace tribool {
22
23template<class T, class Policies1, class Policies2> inline
24logic::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
32template<class T, class Policies> inline
33logic::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
41template<class T, class Policies1, class Policies2> inline
42logic::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
50template<class T, class Policies> inline
51logic::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
59template<class T, class Policies1, class Policies2> inline
60logic::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
68template<class T, class Policies> inline
69logic::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
77template<class T, class Policies1, class Policies2> inline
78logic::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
86template<class T, class Policies> inline
87logic::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
95template<class T, class Policies1, class Policies2> inline
96logic::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
104template<class T, class Policies> inline
105logic::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
113template<class T, class Policies1, class Policies2> inline
114logic::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
122template<class T, class Policies> inline
123logic::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
Note: See TracBrowser for help on using the repository browser.