1 /* typemax.h -- encapsulate max values for long, long long, etc. */
3 /* Copyright (C) 2001 Free Software Foundation, Inc.
5 This file is part of GNU Bash, the Bourne Again SHell.
7 Bash is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 Bash is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License along
18 with Bash; see the file COPYING. If not, write to the Free Software
19 Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
22 * NOTE: This should be included after config.h, limits.h, stdint.h, and
33 /* Nonzero if the integer type T is signed. */
35 # define TYPE_SIGNED(t) (! ((t) 0 < (t) -1))
39 # define TYPE_MINIMUM(t) ((t) (TYPE_SIGNED (t) \
40 ? ~ (t) 0 << (sizeof (t) * CHAR_BIT - 1) \
45 # define TYPE_MAXIMUM(t) ((t) (~ (t) 0 - TYPE_MINIMUM (t)))
50 # define LLONG_MAX TYPE_MAXIMUM(long long int)
51 # define LLONG_MIN TYPE_MINIMUM(long long int)
54 # define ULLONG_MAX TYPE_MAXIMUM(unsigned long long int)
59 # define ULONG_MAX ((unsigned long) ~(unsigned long) 0)
63 # define LONG_MAX ((long int) (ULONG_MAX >> 1))
64 # define LONG_MIN ((long int) (-LONG_MAX - 1L))
67 #ifndef INT_MAX /* ouch */
68 # define INT_MAX TYPE_MAXIMUM(int)
69 # define INT_MIN TYPE_MINIMUM(int)
70 # define UINT_MAX ((unsigned int) ~(unsigned int)0)
73 /* workaround for gcc bug in versions < 2.7 */
74 #if defined (HAVE_LONG_LONG) && __GNUC__ == 2 && __GNUC_MINOR__ < 7
75 static const unsigned long long int maxquad = ULLONG_MAX;
77 # define ULLONG_MAX maxquad
80 #endif /* _SH_TYPEMAX_H */