Lines Matching +full:max +full:- +full:counts
1 /* intprops.h -- properties of integer types
3 Copyright (C) 2001-2018 Free Software Foundation, Inc.
28 /* Act like _GL_INT_CONVERT (E, -V) but work around a bug in IRIX 6.5 cc; see
29 <https://lists.gnu.org/r/bug-gnulib/2011-05/msg00406.html>. */
30 #define _GL_INT_NEGATE_CONVERT(e, v) (0 * (e) - (v))
35 /* True if the arithmetic type T is an integer type. bool counts as
40 #define TYPE_SIGNED(t) (! ((t) 0 < (t) -1))
50 Padding bits are not supported; this is checked at compile-time below. */
57 ? (t) -1 \
58 : ((((t) 1 << (TYPE_WIDTH (t) - 2)) - 1) * 2 + 1)))
71 (((_GL_INT_CONVERT (e, 1) << (TYPE_WIDTH ((e) + 0) - 2)) - 1) * 2 + 1)
82 This assumption is tested by the intprops-tests module. */
116 (INT_BITS_STRLEN_BOUND (TYPE_WIDTH (t) - _GL_SIGNED_TYPE_OR_EXPR (t)) \
129 implementation-defined behavior. Their implementations are simple
146 by zero, for bad shift counts, or for shifting negative numbers.
150 arguments (including the MIN and MAX arguments) must be of the same
152 must have minimum value MIN and maximum MAX. Unsigned types should
155 These macros are tuned for constant MIN and MAX. For commutative
158 /* Return 1 if A + B would overflow in [MIN,MAX] arithmetic.
160 #define INT_ADD_RANGE_OVERFLOW(a, b, min, max) \ argument
162 ? (a) < (min) - (b) \
163 : (max) - (b) < (a))
165 /* Return 1 if A - B would overflow in [MIN,MAX] arithmetic.
167 #define INT_SUBTRACT_RANGE_OVERFLOW(a, b, min, max) \ argument
169 ? (max) + (b) < (a) \
172 /* Return 1 if - A would overflow in [MIN,MAX] arithmetic.
174 #define INT_NEGATE_RANGE_OVERFLOW(a, min, max) \ argument
176 ? (a) < - (max) \
179 /* Return 1 if A * B would overflow in [MIN,MAX] arithmetic.
182 <https://lists.gnu.org/r/bug-gnulib/2011-05/msg00401.html>. */
183 #define INT_MULTIPLY_RANGE_OVERFLOW(a, b, min, max) \ argument
186 ? (a) < (max) / (b) \
187 : (b) == -1 \
194 : (max) / (b) < (a)))
196 /* Return 1 if A / B would overflow in [MIN,MAX] arithmetic.
198 #define INT_DIVIDE_RANGE_OVERFLOW(a, b, min, max) \ argument
199 ((min) < 0 && (b) == -1 && (a) < - (max))
201 /* Return 1 if A % B would overflow in [MIN,MAX] arithmetic.
203 Mathematically, % should never overflow, but on x86-like hosts
204 INT_MIN % -1 traps, and the C standard permits this, so treat this
206 #define INT_REMAINDER_RANGE_OVERFLOW(a, b, min, max) \ argument
207 INT_DIVIDE_RANGE_OVERFLOW (a, b, min, max)
209 /* Return 1 if A << B would overflow in [MIN,MAX] arithmetic.
210 See above for restrictions. Here, MIN and MAX are for A only, and B need
214 implementation-defined behavior, but do not check these other
216 #define INT_LEFT_SHIFT_RANGE_OVERFLOW(a, b, min, max) \ argument
219 : (max) >> (b) < (a))
221 /* True if __builtin_add_overflow (A, B, P) works when P is non-null. */
233 (e.g., A and B) have the same type as MIN and MAX. Instead, they assume
236 # define _GL_ADD_OVERFLOW(a, b, min, max) \ argument
238 # define _GL_SUBTRACT_OVERFLOW(a, b, min, max) \ argument
239 __builtin_sub_overflow_p (a, b, (__typeof__ ((a) - (b))) 0)
240 # define _GL_MULTIPLY_OVERFLOW(a, b, min, max) \ argument
243 # define _GL_ADD_OVERFLOW(a, b, min, max) \ argument
244 ((min) < 0 ? INT_ADD_RANGE_OVERFLOW (a, b, min, max) \
248 # define _GL_SUBTRACT_OVERFLOW(a, b, min, max) \ argument
249 ((min) < 0 ? INT_SUBTRACT_RANGE_OVERFLOW (a, b, min, max) \
251 : (b) < 0 ? (a) - (b) <= (a) \
253 # define _GL_MULTIPLY_OVERFLOW(a, b, min, max) \ argument
255 || INT_MULTIPLY_RANGE_OVERFLOW (a, b, min, max))
257 #define _GL_DIVIDE_OVERFLOW(a, b, min, max) \ argument
258 ((min) < 0 ? (b) == _GL_INT_NEGATE_CONVERT (min, 1) && (a) < - (max) \
259 : (a) < 0 ? (b) <= (a) + (b) - 1 \
261 #define _GL_REMAINDER_OVERFLOW(a, b, min, max) \ argument
262 ((min) < 0 ? (b) == _GL_INT_NEGATE_CONVERT (min, 1) && (a) < - (max) \
263 : (a) < 0 ? (a) % (b) != ((max) - (b) + 1) % (b) \
264 : (b) < 0 && ! _GL_UNSIGNED_NEG_MULTIPLE (a, b, max))
267 A is unsigned, B is negative, and MAX is the maximum value of A's
269 -B == 0) suffices, but things get tricky if -B would overflow. */
270 #define _GL_UNSIGNED_NEG_MULTIPLE(a, b, max) \ argument
271 (((b) < -_GL_SIGNED_INT_MAXIMUM (b) \
272 ? (_GL_SIGNED_INT_MAXIMUM (b) == (max) \
275 : (a) % - (b)) \
282 The INT_<op>_WRAPV macros also store the low-order bits of the answer.
304 by zero, for bad shift counts, or for shifting negative numbers.
310 +, binary -, and *. The result type must be signed.
314 Return 1 if the integer expressions A * B, A - B, -A, A * B, A / B,
338 where OP_RESULT_OVERFLOW (A, B, MIN, MAX) does the actual test,
339 assuming MIN and MAX are the minimum and maximum for the result type.
346 /* Store the low-order bits of A + B, A - B, A * B, respectively, into *R.
351 _GL_INT_OP_WRAPV (a, b, r, -, __builtin_sub_overflow, INT_SUBTRACT_OVERFLOW)
358 For now, assume all versions of GCC-like compilers generate bogus
367 /* Store the low-order bits of A <op> B into *R, where OP specifies
418 /* Store the low-order bits of A <op> B into *R, where the operation
433 /* Return the low-order bits of A <op> B, where the operation is given
438 Assume that converting UT to T yields the low-order bits, as is
439 done in all known two's-complement C compilers. E.g., see:
440 https://gcc.gnu.org/onlinedocs/gcc/Integers-implementation.html
443 implementation-defined result or signal for values outside T's
446 https://lists.gnu.org/r/bug-gnulib/2017-04/msg00049.html