1 /* Result supporting functions implementation: inline functions.
2    Copyright (C) 2001-2010 Roberto Bagnara <bagnara@cs.unipr.it>
3    Copyright (C) 2010-2016 BUGSENG srl (http://bugseng.com)
4 
5 This file is part of the Parma Polyhedra Library (PPL).
6 
7 The PPL is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 The PPL is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15 for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software Foundation,
19 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA.
20 
21 For the most up-to-date information see the Parma Polyhedra Library
22 site: http://bugseng.com/products/ppl/ . */
23 
24 #ifndef PPL_Result_inlines_hh
25 #define PPL_Result_inlines_hh 1
26 
27 #include "assertions.hh"
28 
29 namespace Parma_Polyhedra_Library {
30 
31 /*! \ingroup PPL_CXX_interface */
32 inline Result
operator &(Result x,Result y)33 operator&(Result x, Result y) {
34   const unsigned res = static_cast<unsigned>(x) & static_cast<unsigned>(y);
35   return static_cast<Result>(res);
36 }
37 
38 /*! \ingroup PPL_CXX_interface */
39 inline Result
operator |(Result x,Result y)40 operator|(Result x, Result y) {
41   const unsigned res = static_cast<unsigned>(x) | static_cast<unsigned>(y);
42   return static_cast<Result>(res);
43 }
44 
45 /*! \ingroup PPL_CXX_interface */
46 inline Result
operator -(Result x,Result y)47 operator-(Result x, Result y) {
48   const Result y_neg = static_cast<Result>(~static_cast<unsigned>(y));
49   return x & y_neg;
50 }
51 
52 /*! \ingroup PPL_CXX_interface */
53 inline Result_Class
result_class(Result r)54 result_class(Result r) {
55   const Result rc = r & static_cast<Result>(VC_MASK);
56   return static_cast<Result_Class>(rc);
57 }
58 
59 /*! \ingroup PPL_CXX_interface */
60 inline Result_Relation
result_relation(Result r)61 result_relation(Result r) {
62   const Result rc = r & static_cast<Result>(VR_MASK);
63   return static_cast<Result_Relation>(rc);
64 }
65 
66 /*! \ingroup PPL_CXX_interface */
67 inline Result
result_relation_class(Result r)68 result_relation_class(Result r) {
69   return r & (static_cast<Result>(VR_MASK) | static_cast<Result>(VC_MASK));
70 }
71 
72 inline int
result_overflow(Result r)73 result_overflow(Result r) {
74   switch (result_class(r)) {
75   case VC_NORMAL:
76     switch (r) {
77     case V_LT_INF:
78       return -1;
79     case V_GT_SUP:
80       return 1;
81     default:
82       break;
83     }
84     break;
85   case VC_MINUS_INFINITY:
86     return -1;
87   case VC_PLUS_INFINITY:
88     return 1;
89   default:
90     break;
91   }
92   return 0;
93 }
94 
95 inline bool
result_representable(Result r)96 result_representable(Result r) {
97   return (r & V_UNREPRESENTABLE) != V_UNREPRESENTABLE;
98 }
99 
100 } // namespace Parma_Polyhedra_Library
101 
102 #endif // !defined(PPL_Result_inlines_hh)
103