limits.in.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /* A GNU-like <limits.h>.
  2. Copyright 2016-2023 Free Software Foundation, Inc.
  3. This file is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU Lesser General Public License as
  5. published by the Free Software Foundation; either version 2.1 of the
  6. License, or (at your option) any later version.
  7. This file 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 <https://www.gnu.org/licenses/>. */
  13. #if __GNUC__ >= 3
  14. @PRAGMA_SYSTEM_HEADER@
  15. #endif
  16. @PRAGMA_COLUMNS@
  17. #if defined _GL_ALREADY_INCLUDING_LIMITS_H
  18. /* Special invocation convention:
  19. On Haiku/x86_64, we have a sequence of nested includes
  20. <limits.h> -> <syslimits.h> -> <limits.h>.
  21. In this situation, LONG_MAX and INT_MAX are not yet defined,
  22. therefore we should not attempt to define LONG_BIT. */
  23. #@INCLUDE_NEXT@ @NEXT_LIMITS_H@
  24. #else
  25. /* Normal invocation convention. */
  26. #ifndef _@GUARD_PREFIX@_LIMITS_H
  27. # define _GL_ALREADY_INCLUDING_LIMITS_H
  28. /* The include_next requires a split double-inclusion guard. */
  29. # @INCLUDE_NEXT@ @NEXT_LIMITS_H@
  30. # undef _GL_ALREADY_INCLUDING_LIMITS_H
  31. #ifndef _@GUARD_PREFIX@_LIMITS_H
  32. #define _@GUARD_PREFIX@_LIMITS_H
  33. #ifndef LLONG_MIN
  34. # if defined LONG_LONG_MIN /* HP-UX 11.31 */
  35. # define LLONG_MIN LONG_LONG_MIN
  36. # elif defined LONGLONG_MIN /* IRIX 6.5 */
  37. # define LLONG_MIN LONGLONG_MIN
  38. # elif defined __GNUC__
  39. # define LLONG_MIN (- __LONG_LONG_MAX__ - 1LL)
  40. # endif
  41. #endif
  42. #ifndef LLONG_MAX
  43. # if defined LONG_LONG_MAX /* HP-UX 11.31 */
  44. # define LLONG_MAX LONG_LONG_MAX
  45. # elif defined LONGLONG_MAX /* IRIX 6.5 */
  46. # define LLONG_MAX LONGLONG_MAX
  47. # elif defined __GNUC__
  48. # define LLONG_MAX __LONG_LONG_MAX__
  49. # endif
  50. #endif
  51. #ifndef ULLONG_MAX
  52. # if defined ULONG_LONG_MAX /* HP-UX 11.31 */
  53. # define ULLONG_MAX ULONG_LONG_MAX
  54. # elif defined ULONGLONG_MAX /* IRIX 6.5 */
  55. # define ULLONG_MAX ULONGLONG_MAX
  56. # elif defined __GNUC__
  57. # define ULLONG_MAX (__LONG_LONG_MAX__ * 2ULL + 1ULL)
  58. # endif
  59. #endif
  60. /* The number of usable bits in an unsigned or signed integer type
  61. with minimum value MIN and maximum value MAX, as an int expression
  62. suitable in #if. Cover all known practical hosts. This
  63. implementation exploits the fact that MAX is 1 less than a power of
  64. 2, and merely counts the number of 1 bits in MAX; "COBn" means
  65. "count the number of 1 bits in the low-order n bits"). */
  66. #define _GL_INTEGER_WIDTH(min, max) (((min) < 0) + _GL_COB128 (max))
  67. #define _GL_COB128(n) (_GL_COB64 ((n) >> 31 >> 31 >> 2) + _GL_COB64 (n))
  68. #define _GL_COB64(n) (_GL_COB32 ((n) >> 31 >> 1) + _GL_COB32 (n))
  69. #define _GL_COB32(n) (_GL_COB16 ((n) >> 16) + _GL_COB16 (n))
  70. #define _GL_COB16(n) (_GL_COB8 ((n) >> 8) + _GL_COB8 (n))
  71. #define _GL_COB8(n) (_GL_COB4 ((n) >> 4) + _GL_COB4 (n))
  72. #define _GL_COB4(n) (!!((n) & 8) + !!((n) & 4) + !!((n) & 2) + !!((n) & 1))
  73. #ifndef WORD_BIT
  74. /* Assume 'int' is 32 bits wide. */
  75. # define WORD_BIT 32
  76. #endif
  77. #ifndef LONG_BIT
  78. /* Assume 'long' is 32 or 64 bits wide. */
  79. # if LONG_MAX == INT_MAX
  80. # define LONG_BIT 32
  81. # else
  82. # define LONG_BIT 64
  83. # endif
  84. #endif
  85. /* Macros specified by C23 and by ISO/IEC TS 18661-1:2014. */
  86. #if (! defined ULLONG_WIDTH \
  87. && (defined _GNU_SOURCE || defined __STDC_WANT_IEC_60559_BFP_EXT__ \
  88. || (defined __STDC_VERSION__ && 201710 < __STDC_VERSION__)))
  89. # define CHAR_WIDTH _GL_INTEGER_WIDTH (CHAR_MIN, CHAR_MAX)
  90. # define SCHAR_WIDTH _GL_INTEGER_WIDTH (SCHAR_MIN, SCHAR_MAX)
  91. # define UCHAR_WIDTH _GL_INTEGER_WIDTH (0, UCHAR_MAX)
  92. # define SHRT_WIDTH _GL_INTEGER_WIDTH (SHRT_MIN, SHRT_MAX)
  93. # define USHRT_WIDTH _GL_INTEGER_WIDTH (0, USHRT_MAX)
  94. # define INT_WIDTH _GL_INTEGER_WIDTH (INT_MIN, INT_MAX)
  95. # define UINT_WIDTH _GL_INTEGER_WIDTH (0, UINT_MAX)
  96. # define LONG_WIDTH _GL_INTEGER_WIDTH (LONG_MIN, LONG_MAX)
  97. # define ULONG_WIDTH _GL_INTEGER_WIDTH (0, ULONG_MAX)
  98. # define LLONG_WIDTH _GL_INTEGER_WIDTH (LLONG_MIN, LLONG_MAX)
  99. # define ULLONG_WIDTH _GL_INTEGER_WIDTH (0, ULLONG_MAX)
  100. #endif
  101. /* Macros specified by C23. */
  102. #if (! defined BOOL_WIDTH \
  103. && (defined _GNU_SOURCE \
  104. || (defined __STDC_VERSION__ && 201710 < __STDC_VERSION__)))
  105. # define BOOL_MAX 1
  106. # define BOOL_WIDTH 1
  107. #endif
  108. #endif /* _@GUARD_PREFIX@_LIMITS_H */
  109. #endif /* _@GUARD_PREFIX@_LIMITS_H */
  110. #endif