1 /* Result enum and supporting function declarations.
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_defs_hh
25 #define PPL_Result_defs_hh 1
26 
27 namespace Parma_Polyhedra_Library {
28 
29 enum Result_Class {
30   //! \hideinitializer Representable number result class.
31   VC_NORMAL = 0U << 4,
32 
33   //! \hideinitializer Negative infinity result class.
34   VC_MINUS_INFINITY = 1U << 4,
35 
36   //! \hideinitializer Positive infinity result class.
37   VC_PLUS_INFINITY = 2U << 4,
38 
39   //! \hideinitializer Not a number result class.
40   VC_NAN = 3U << 4,
41 
42   VC_MASK = VC_NAN
43 };
44 
45 // This must be kept in sync with Relation_Symbol
46 enum Result_Relation {
47   //! \hideinitializer No values satisfies the relation.
48   VR_EMPTY = 0U,
49 
50   //! \hideinitializer Equal. This need to be accompanied by a value.
51   VR_EQ = 1U,
52 
53   //! \hideinitializer Less than. This need to be accompanied by a value.
54   VR_LT = 2U,
55 
56   //! \hideinitializer Greater than. This need to be accompanied by a value.
57   VR_GT = 4U,
58 
59   //! \hideinitializer Not equal. This need to be accompanied by a value.
60   VR_NE = VR_LT | VR_GT,
61 
62   //! \hideinitializer Less or equal. This need to be accompanied by a value.
63   VR_LE = VR_EQ | VR_LT,
64 
65   //! \hideinitializer Greater or equal. This need to be accompanied by a value.
66   VR_GE = VR_EQ | VR_GT,
67 
68   //! \hideinitializer All values satisfy the relation.
69   VR_LGE = VR_LT | VR_EQ | VR_GT,
70 
71   VR_MASK = VR_LGE
72 };
73 
74 //! Possible outcomes of a checked arithmetic computation.
75 /*! \ingroup PPL_CXX_interface */
76 enum Result {
77   //! \hideinitializer The exact result is not comparable.
78   V_EMPTY = VR_EMPTY,
79 
80   //! \hideinitializer The computed result is exact.
81   V_EQ = static_cast<unsigned>(VR_EQ),
82 
83   //! \hideinitializer The computed result is inexact and rounded up.
84   V_LT = static_cast<unsigned>(VR_LT),
85 
86   //! \hideinitializer The computed result is inexact and rounded down.
87   V_GT = static_cast<unsigned>(VR_GT),
88 
89   //! \hideinitializer The computed result is inexact.
90   V_NE = VR_NE,
91 
92   //! \hideinitializer The computed result may be inexact and rounded up.
93   V_LE = VR_LE,
94 
95   //! \hideinitializer The computed result may be inexact and rounded down.
96   V_GE = VR_GE,
97 
98   //! \hideinitializer The computed result may be inexact.
99   V_LGE = VR_LGE,
100 
101   //! \hideinitializer The exact result is a number out of finite bounds.
102   V_OVERFLOW = 1U << 6,
103 
104   //! \hideinitializer A negative integer overflow occurred (rounding up).
105   V_LT_INF = V_LT | V_OVERFLOW,
106 
107   //! \hideinitializer A positive integer overflow occurred (rounding down).
108   V_GT_SUP = V_GT | V_OVERFLOW,
109 
110   //! \hideinitializer A positive integer overflow occurred (rounding up).
111   V_LT_PLUS_INFINITY = V_LT | static_cast<unsigned>(VC_PLUS_INFINITY),
112 
113   //! \hideinitializer A negative integer overflow occurred (rounding down).
114   V_GT_MINUS_INFINITY = V_GT | static_cast<unsigned>(VC_MINUS_INFINITY),
115 
116   //! \hideinitializer Negative infinity result.
117   V_EQ_MINUS_INFINITY = V_EQ | static_cast<unsigned>(VC_MINUS_INFINITY),
118 
119   //! \hideinitializer Positive infinity result.
120   V_EQ_PLUS_INFINITY = V_EQ | static_cast<unsigned>(VC_PLUS_INFINITY),
121 
122   //! \hideinitializer Not a number result.
123   V_NAN = static_cast<unsigned>(VC_NAN),
124 
125   //! \hideinitializer Converting from unknown string.
126   V_CVT_STR_UNK = V_NAN | (1U << 8),
127 
128   //! \hideinitializer Dividing by zero.
129   V_DIV_ZERO = V_NAN | (2U << 8),
130 
131   //! \hideinitializer Adding two infinities having opposite signs.
132   V_INF_ADD_INF = V_NAN | (3U << 8),
133 
134   //! \hideinitializer Dividing two infinities.
135   V_INF_DIV_INF = V_NAN | (4U << 8),
136 
137   //! \hideinitializer Taking the modulus of an infinity.
138   V_INF_MOD = V_NAN | (5U << 8),
139 
140   //! \hideinitializer Multiplying an infinity by zero.
141   V_INF_MUL_ZERO = V_NAN | (6U << 8),
142 
143   //! \hideinitializer Subtracting two infinities having the same sign.
144   V_INF_SUB_INF = V_NAN | (7U << 8),
145 
146   //! \hideinitializer Computing a remainder modulo zero.
147   V_MOD_ZERO = V_NAN | (8U << 8),
148 
149   //! \hideinitializer Taking the square root of a negative number.
150   V_SQRT_NEG = V_NAN | (9U << 8),
151 
152   //! \hideinitializer Unknown result due to intermediate negative overflow.
153   V_UNKNOWN_NEG_OVERFLOW = V_NAN | (10U << 8),
154 
155   //! \hideinitializer Unknown result due to intermediate positive overflow.
156   V_UNKNOWN_POS_OVERFLOW = V_NAN | (11U << 8),
157 
158   //! \hideinitializer The computed result is not representable.
159   V_UNREPRESENTABLE = 1U << 7
160 
161 };
162 
163 //! \name Functions Inspecting and/or Combining Result Values
164 //@{
165 
166 /*! \ingroup PPL_CXX_interface */
167 Result operator&(Result x, Result y);
168 
169 /*! \ingroup PPL_CXX_interface */
170 Result operator|(Result x, Result y);
171 
172 /*! \ingroup PPL_CXX_interface */
173 Result operator-(Result x, Result y);
174 
175 /*! \ingroup PPL_CXX_interface \brief
176   Extracts the value class part of \p r (representable number,
177   unrepresentable minus/plus infinity or nan).
178 */
179 Result_Class result_class(Result r);
180 
181 /*! \ingroup PPL_CXX_interface \brief
182   Extracts the relation part of \p r.
183 */
184 Result_Relation result_relation(Result r);
185 
186 /*! \ingroup PPL_CXX_interface */
187 Result result_relation_class(Result r);
188 
189 //@} // Functions Inspecting and/or Combining Result Values
190 
191 } // namespace Parma_Polyhedra_Library
192 
193 #include "Result_inlines.hh"
194 
195 #endif // !defined(PPL_Result_defs_hh)
196