1 /*
2  * Copyright (c) 2008-2014 Travis Geiselbrecht
3  *
4  * Use of this source code is governed by a MIT-style
5  * license that can be found in the LICENSE file or at
6  * https://opensource.org/licenses/MIT
7  */
8 #pragma once
9 
10 #include <limits.h> // for ULONG_MAX
11 
12 typedef unsigned char      uint8_t;
13 typedef unsigned short     uint16_t;
14 typedef unsigned int       uint32_t;
15 typedef unsigned long long uint64_t;
16 typedef signed char        int8_t;
17 typedef short              int16_t;
18 typedef int                int32_t;
19 typedef long long          int64_t;
20 
21 #define INT8_MIN    CHAR_MIN
22 #define INT16_MIN   SHRT_MIN
23 #define INT32_MIN   INT_MIN
24 
25 #if defined(LLONG_MIN)
26 #define INT64_MIN   LLONG_MIN
27 #elif defined(__LONG_LONG_MAX__)
28 #define INT64_MIN (-__LONG_LONG_MAX__-1LL)
29 #endif
30 
31 #define INT8_MAX    CHAR_MAX
32 #define INT16_MAX   SHRT_MAX
33 #define INT32_MAX   INT_MAX
34 
35 #if defined(LLONG_MAX)
36 #define INT64_MAX   LLONG_MAX
37 #elif defined(__LONG_LONG_MAX__)
38 #define INT64_MAX  __LONG_LONG_MAX__
39 #endif
40 
41 #define UINT8_MAX   UCHAR_MAX
42 #define UINT16_MAX  USHRT_MAX
43 #define UINT32_MAX  UINT_MAX
44 
45 #if defined(ULLONG_MAX)
46 #define UINT64_MAX  ULLONG_MAX
47 #elif defined(__LONG_LONG_MAX__)
48 #define UINT64_MAX (__LONG_LONG_MAX__*2ULL + 1ULL)
49 #endif
50 
51 typedef int8_t int_least8_t;
52 typedef int16_t int_least16_t;
53 typedef int32_t int_least32_t;
54 typedef int64_t int_least64_t;
55 typedef uint8_t uint_least8_t;
56 typedef uint16_t uint_least16_t;
57 typedef uint32_t uint_least32_t;
58 typedef uint64_t uint_least64_t;
59 
60 #define INT_LEAST8_MIN  INT8_MIN
61 #define INT_LEAST16_MIN INT16_MIN
62 #define INT_LEAST32_MIN INT32_MIN
63 #define INT_LEAST64_MIN INT64_MIN
64 #define INT_LEAST8_MAX  INT8_MAX
65 #define INT_LEAST16_MAX INT16_MAX
66 #define INT_LEAST32_MAX INT32_MAX
67 #define INT_LEAST64_MAX INT64_MAX
68 
69 #define UINT_LEAST8_MAX  UINT8_MAX
70 #define UINT_LEAST16_MAX UINT16_MAX
71 #define UINT_LEAST32_MAX UINT32_MAX
72 #define UINT_LEAST64_MAX UINT64_MAX
73 
74 typedef int8_t int_fast8_t;
75 typedef int16_t int_fast16_t;
76 typedef int32_t int_fast32_t;
77 typedef int64_t int_fast64_t;
78 typedef uint8_t uint_fast8_t;
79 typedef uint16_t uint_fast16_t;
80 typedef uint32_t uint_fast32_t;
81 typedef uint64_t uint_fast64_t;
82 
83 #define INT_FAST8_MIN  INT8_MIN
84 #define INT_FAST16_MIN INT16_MIN
85 #define INT_FAST32_MIN INT32_MIN
86 #define INT_FAST64_MIN INT64_MIN
87 #define INT_FAST8_MAX  INT8_MAX
88 #define INT_FAST16_MAX INT16_MAX
89 #define INT_FAST32_MAX INT32_MAX
90 #define INT_FAST64_MAX INT64_MAX
91 
92 #define UINT_FAST8_MAX  UINT8_MAX
93 #define UINT_FAST16_MAX UINT16_MAX
94 #define UINT_FAST32_MAX UINT32_MAX
95 #define UINT_FAST64_MAX UINT64_MAX
96 
97 typedef long intptr_t;
98 typedef unsigned long uintptr_t;
99 
100 #define INTPTR_MIN        LONG_MIN
101 #define INTPTR_MAX        LONG_MAX
102 #define UINTPTR_MAX       ULONG_MAX
103 
104 typedef long long intmax_t;
105 typedef unsigned long long uintmax_t;
106 
107 #define INTMAX_MAX        LLONG_MAX
108 #define INTMAX_MIN        LLONG_MIN
109 #define UINTMAX_MAX       ULLONG_MAX
110 
111 #define SIZE_MAX ULONG_MAX
112 
113 #define INT8_C(c)         (c)
114 #define INT16_C(c)        (c)
115 #define INT32_C(c)        (c)
116 #define INT64_C(c)        (c ## LL)
117 
118 #define UINT8_C(c)        (c)
119 #define UINT16_C(c)       (c)
120 #define UINT32_C(c)       (c ## U)
121 #define UINT64_C(c)       (c ## ULL)
122 
123 #define INTMAX_C(c)       INT64_C(c)
124 #define UINTMAX_C(c)      UINT64_C(c)
125 
126