aimstil  5.0.5
fuzzy_logic.tpp
Go to the documentation of this file.
1 
2 namespace til { namespace fuzzy
3 {
4 
5  //---------------------------------------------------------------------------
6 
7  template < typename T >
8  inline
9  boost::logic::tribool
10  is_positive(T x, T delta)
11  {
12  assert(delta >= 0);
13  if (x >= delta) return true;
14  else if (x <= -delta) return false;
15  //else return boost::logic::tribool(boost::logic::indeterminate);
16  else return boost::logic::indeterminate;
17  }
18 
19  //---------------------------------------------------------------------------
20 
21  template < typename T >
22  inline
23  boost::logic::tribool
24  same_sign(T x, T y, T delta)
25  {
26  // NB: I am not sure that this solution is actually much worse than what could be
27  // achieved by explicit checking, regarding the number of tests to make.
28  return fuzzy::is_positive(x, delta) == fuzzy::is_positive(y, delta);
29  }
30 
31  //---------------------------------------------------------------------------
32 
33 }} // namespace til::fuzzy
34