limits.in.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /* A GNU-like <limits.h>.
  2. Copyright 2016-2017 Free Software Foundation, Inc.
  3. This program is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public License
  5. as published by the Free Software Foundation; either version 2, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public License
  12. along with this program; if not, see <http://www.gnu.org/licenses/>. */
  13. #ifndef _@GUARD_PREFIX@_LIMITS_H
  14. #if __GNUC__ >= 3
  15. @PRAGMA_SYSTEM_HEADER@
  16. #endif
  17. @PRAGMA_COLUMNS@
  18. /* The include_next requires a split double-inclusion guard. */
  19. #@INCLUDE_NEXT@ @NEXT_LIMITS_H@
  20. #ifndef _@GUARD_PREFIX@_LIMITS_H
  21. #define _@GUARD_PREFIX@_LIMITS_H
  22. /* The number of usable bits in an unsigned or signed integer type
  23. with minimum value MIN and maximum value MAX, as an int expression
  24. suitable in #if. Cover all known practical hosts. This
  25. implementation exploits the fact that MAX is 1 less than a power of
  26. 2, and merely counts the number of 1 bits in MAX; "COBn" means
  27. "count the number of 1 bits in the low-order n bits"). */
  28. #define _GL_INTEGER_WIDTH(min, max) (((min) < 0) + _GL_COB128 (max))
  29. #define _GL_COB128(n) (_GL_COB64 ((n) >> 31 >> 31 >> 2) + _GL_COB64 (n))
  30. #define _GL_COB64(n) (_GL_COB32 ((n) >> 31 >> 1) + _GL_COB32 (n))
  31. #define _GL_COB32(n) (_GL_COB16 ((n) >> 16) + _GL_COB16 (n))
  32. #define _GL_COB16(n) (_GL_COB8 ((n) >> 8) + _GL_COB8 (n))
  33. #define _GL_COB8(n) (_GL_COB4 ((n) >> 4) + _GL_COB4 (n))
  34. #define _GL_COB4(n) (!!((n) & 8) + !!((n) & 4) + !!((n) & 2) + !!((n) & 1))
  35. /* Macros specified by ISO/IEC TS 18661-1:2014. */
  36. #if (! defined ULLONG_WIDTH \
  37. && (defined _GNU_SOURCE || defined __STDC_WANT_IEC_60559_BFP_EXT__))
  38. # define CHAR_WIDTH _GL_INTEGER_WIDTH (CHAR_MIN, CHAR_MAX)
  39. # define SCHAR_WIDTH _GL_INTEGER_WIDTH (SCHAR_MIN, SCHAR_MAX)
  40. # define UCHAR_WIDTH _GL_INTEGER_WIDTH (0, UCHAR_MAX)
  41. # define SHRT_WIDTH _GL_INTEGER_WIDTH (SHRT_MIN, SHRT_MAX)
  42. # define USHRT_WIDTH _GL_INTEGER_WIDTH (0, USHRT_MAX)
  43. # define INT_WIDTH _GL_INTEGER_WIDTH (INT_MIN, INT_MAX)
  44. # define UINT_WIDTH _GL_INTEGER_WIDTH (0, UINT_MAX)
  45. # define LONG_WIDTH _GL_INTEGER_WIDTH (LONG_MIN, LONG_MAX)
  46. # define ULONG_WIDTH _GL_INTEGER_WIDTH (0, ULONG_MAX)
  47. # define LLONG_WIDTH _GL_INTEGER_WIDTH (LLONG_MIN, LLONG_MAX)
  48. # define ULLONG_WIDTH _GL_INTEGER_WIDTH (0, ULLONG_MAX)
  49. #endif /* !ULLONG_WIDTH && (_GNU_SOURCE || __STDC_WANT_IEC_60559_BFP_EXT__) */
  50. #endif /* _@GUARD_PREFIX@_LIMITS_H */
  51. #endif /* _@GUARD_PREFIX@_LIMITS_H */