PPL  1.2
Rounding_Dir_inlines.hh
Go to the documentation of this file.
1 /* Inline functions operating on enum Rounding_Dir values.
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_Rounding_Dir_inlines_hh
25 #define PPL_Rounding_Dir_inlines_hh 1
26 
27 #include "assertions.hh"
28 
29 namespace Parma_Polyhedra_Library {
30 
32 inline Rounding_Dir
34  const unsigned res = static_cast<unsigned>(x) & static_cast<unsigned>(y);
35  return static_cast<Rounding_Dir>(res);
36 }
37 
39 inline Rounding_Dir
41  const unsigned res = static_cast<unsigned>(x) | static_cast<unsigned>(y);
42  return static_cast<Rounding_Dir>(res);
43 }
44 
46 inline Rounding_Dir
48  return dir & ROUND_DIR_MASK;
49 }
50 
52 inline bool
54  return round_dir(dir) == ROUND_DOWN;
55 }
56 
58 inline bool
60  return round_dir(dir) == ROUND_UP;
61 }
62 
64 inline bool
66  return round_dir(dir) == ROUND_IGNORE;
67 }
68 
70 inline bool
72  return round_dir(dir) == ROUND_NOT_NEEDED;
73 }
74 
76 inline bool
78  return round_dir(dir) == ROUND_IGNORE || round_dir(dir) == ROUND_NOT_NEEDED;
79 }
80 
82 inline bool
84  return round_dir(dir) == ROUND_DIRECT;
85 }
86 
88 inline bool
90  return round_dir(dir) == ROUND_INVERSE;
91 }
92 
94 inline bool
97 }
98 
99 #if PPL_CAN_CONTROL_FPU
100 
104  switch (round_dir(dir)) {
105  case ROUND_UP:
106  return static_cast<fpu_rounding_direction_type>(PPL_FPU_UPWARD);
107  case ROUND_DOWN:
108  return static_cast<fpu_rounding_direction_type>(PPL_FPU_DOWNWARD);
109  case ROUND_IGNORE: // Fall through.
110  default:
111  PPL_UNREACHABLE;
112  return static_cast<fpu_rounding_direction_type>(PPL_FPU_UPWARD);
113  }
114 }
115 
116 #undef PPL_FPU_DOWNWARD
117 #undef PPL_FPU_TONEAREST
118 #undef PPL_FPU_TOWARDZERO
119 #undef PPL_FPU_UPWARD
120 
121 #endif
122 
124 inline Rounding_Dir
126  switch (round_dir(dir)) {
127  case ROUND_UP:
128  return ROUND_DOWN | (dir & ROUND_STRICT_RELATION);
129  case ROUND_DOWN:
130  return ROUND_UP | (dir & ROUND_STRICT_RELATION);
131  case ROUND_IGNORE:
132  return dir;
133  default:
134  PPL_UNREACHABLE;
135  return dir;
136  }
137 }
138 
139 } // namespace Parma_Polyhedra_Library
140 
141 #endif // !defined(PPL_Rounding_Dir_inlines_hh)
Rounding_Dir round_dir(Rounding_Dir dir)
#define PPL_FPU_DOWNWARD
#define PPL_FPU_UPWARD
Rounding_Dir
Rounding directions for arithmetic computations.
bool round_ignore(Rounding_Dir dir)
bool round_strict_relation(Rounding_Dir dir)
bool round_inverse(Rounding_Dir dir)
Rounding_Dir inverse(Rounding_Dir dir)
I_Result operator&(I_Result a, I_Result b)
fpu_rounding_direction_type round_fpu_dir(Rounding_Dir dir)
bool round_not_needed(Rounding_Dir dir)
I_Result operator|(I_Result a, I_Result b)
bool round_up(Rounding_Dir dir)
The entire library is confined to this namespace.
Definition: version.hh:61
bool round_direct(Rounding_Dir dir)
bool round_down(Rounding_Dir dir)
bool round_not_requested(Rounding_Dir dir)