PPL  0.12.1
Result.inlines.hh
Go to the documentation of this file.
00001 /* Result supporting functions implementation: inline functions.
00002    Copyright (C) 2001-2010 Roberto Bagnara <bagnara@cs.unipr.it>
00003    Copyright (C) 2010-2012 BUGSENG srl (http://bugseng.com)
00004 
00005 This file is part of the Parma Polyhedra Library (PPL).
00006 
00007 The PPL is free software; you can redistribute it and/or modify it
00008 under the terms of the GNU General Public License as published by the
00009 Free Software Foundation; either version 3 of the License, or (at your
00010 option) any later version.
00011 
00012 The PPL is distributed in the hope that it will be useful, but WITHOUT
00013 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00015 for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with this program; if not, write to the Free Software Foundation,
00019 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA.
00020 
00021 For the most up-to-date information see the Parma Polyhedra Library
00022 site: http://bugseng.com/products/ppl/ . */
00023 
00024 #ifndef PPL_Result_inlines_hh
00025 #define PPL_Result_inlines_hh 1
00026 
00027 #include "assert.hh"
00028 
00029 namespace Parma_Polyhedra_Library {
00030 
00032 inline Result
00033 operator&(Result x, Result y) {
00034   unsigned res = static_cast<unsigned>(x) & static_cast<unsigned>(y);
00035   return static_cast<Result>(res);
00036 }
00037 
00039 inline Result
00040 operator|(Result x, Result y) {
00041   unsigned res = static_cast<unsigned>(x) | static_cast<unsigned>(y);
00042   return static_cast<Result>(res);
00043 }
00044 
00046 inline Result
00047 operator-(Result x, Result y) {
00048   Result y_neg = static_cast<Result>(~static_cast<unsigned>(y));
00049   return x & y_neg;
00050 }
00051 
00053 inline Result_Class
00054 result_class(Result r) {
00055   Result rc = r & static_cast<Result>(VC_MASK);
00056   return static_cast<Result_Class>(rc);
00057 }
00058 
00060 inline Result_Relation
00061 result_relation(Result r) {
00062   Result rc = r & static_cast<Result>(VR_MASK);
00063   return static_cast<Result_Relation>(rc);
00064 }
00065 
00067 inline Result
00068 result_relation_class(Result r) {
00069   return r & (static_cast<Result>(VR_MASK) | static_cast<Result>(VC_MASK));
00070 }
00071 
00072 inline int
00073 result_overflow(Result r) {
00074   switch (result_class(r)) {
00075   case VC_NORMAL:
00076     switch (r) {
00077     case V_LT_INF:
00078       return -1;
00079     case V_GT_SUP:
00080       return 1;
00081     default:
00082       break;
00083     }
00084     break;
00085   case VC_MINUS_INFINITY:
00086     return -1;
00087   case VC_PLUS_INFINITY:
00088     return 1;
00089   default:
00090     break;
00091   }
00092   return 0;
00093 }
00094 
00095 inline bool
00096 result_representable(Result r) {
00097   return (r & V_UNREPRESENTABLE) != V_UNREPRESENTABLE;
00098 }
00099 
00100 } // namespace Parma_Polyhedra_Library
00101 
00102 #endif // !defined(PPL_Result_inlines_hh)