summaryrefslogtreecommitdiff
path: root/support/dktools/dk4numco.h
blob: bc1fcdef550911d2c2f526f493383cdf9452d059 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
/**	@file	dk4numco.h	Numeric constants.

	Typically the constants from limits.h and stdint.h are used.
	This file contains fallback definitions if the files
	are not available or some definitions are missing.
*/
#ifndef DK4NUMCO_H_INCLUDED

/**	Protection against multiple inclusion.
*/
#define	DK4NUMCO_H_INCLUDED	1

#ifndef DK4CONF_H_INCLUDED
#include "dk4conf.h"
#endif

#if DK4_HAVE_LIMITS_H
#ifndef LIMITS_H_INCLUDED
#include <limits.h>
#define LIMITS_H_INCLUDED 1
#endif
#endif
#if DK4_HAVE_STDINT_H
#ifndef STDINT_H_INCLUDED
#if defined(__cplusplus) && (!defined(__STDC_LIMIT_MACROS))
/**	For legacy compilers, use macros for integer limits.
*/
#define __STDC_LIMIT_MACROS 1
#endif
#if defined(__cplusplus) && (!defined(__STDC_CONSTANT_MACROS))
/**	For legacy compilers, use macros for constants.
*/
#define __STDC_CONSTANT_MACROS 1
#endif
#include <stdint.h>
#define STDINT_H_INCLUDED 1
#endif
#endif
#if DK4_HAVE_INTTYPES_H
#ifndef INTTYPES_H_INCLUDED
#include <inttypes.h>
#define INTTYPES_H_INCLUDED 1
#endif
#endif

/**	Decision: Use fallback definitions for missing constants.
	On some systems the minimum/maximum constants are not
	defined.
	Here you can choose, whether the compiler should complain
	and bail out (0) or use a self-made definition (1).
	The default is to complain and bail out.
*/
#ifndef DK4_USE_FALLBACK_NUMERIC_LIMITS
#define	DK4_USE_FALLBACK_NUMERIC_LIMITS	0
#endif



#ifndef SIZE_MAX
#if !DK4_USE_FALLBACK_NUMERIC_LIMITS
#error "SIZE_MAX undefined! See file dk4numco.h, line 10."
#endif
#if DK4_SIZEOF_SIZE_T > 2
#if DK4_SIZEOF_SIZE_T > 4
/** Maximum size_t value. */
#define	SIZE_MAX 18446744073709551615ULL
#else
/** Maximum size_t value. */
#define SIZE_MAX 4294967295UL
#endif
#else
/** Maximum size_t value. */
#define SIZE_MAX 65535U
#endif
#endif
/* ifndef SIZE_MAX */



#ifndef SCHAR_MIN
#if !DK4_USE_FALLBACK_NUMERIC_LIMITS
#error "SCHAR_MIN undefined! See file dk4numco.h, line 10."
#endif
/** Minimum signed char value. */
#define SCHAR_MIN	(-128)
#endif
/* ifndef SCHAR_MIN */



#ifndef SCHAR_MAX
#if !DK4_USE_FALLBACK_NUMERIC_LIMITS
#error "SCHAR_MAX undefined! See file dk4numco.h, line 10."
#endif
/** Maximum signed char value. */
#define	SCHAR_MAX	127
#endif
/* ifndef SCHAR_MAX */



#ifndef UCHAR_MAX
#if !DK4_USE_FALLBACK_NUMERIC_LIMITS
#error "UCHAR_MAX undefined! See file dk4numco.h, line 10."
#endif
/** Maximum unsigned char value. */
#define	UCHAR_MAX	255
#endif
/* ifndef UCHAR_MAX */



#ifndef SHRT_MIN
#if !DK4_USE_FALLBACK_NUMERIC_LIMITS
#error "SHRT_MIN undefined! See file dk4numco.h, line 10."
#endif
/** Minimum signed short value. */
#define	SHRT_MIN	(-32768)
#endif
/* ifndef SHRT_MIN */



#ifndef SHRT_MAX
#if !DK4_USE_FALLBACK_NUMERIC_LIMITS
#error "SHRT_MAX undefined! See file dk4numco.h, line 10."
#endif
/** Maximum signed short value. */
#define	SHRT_MAX	32767
#endif
/* ifndef SHRT_MAX */



#ifndef USHRT_MAX
#if !DK4_USE_FALLBACK_NUMERIC_LIMITS
#error "USHRT_MAX undefined! See file dk4numco.h, line 10."
#endif
/** Maximum unsigned short value. */
#define	USHRT_MAX	65535
#endif
/* ifndef USHRT_MAX */



#ifndef	INT_MAX
#if !DK4_USE_FALLBACK_NUMERIC_LIMITS
#error "INT_MAX undefined! See file dk4numco.h, line 10."
#endif
#if DK4_SIZEOF_INT > 2
#if DK4_SIZEOF_INT > 4
#if DK4_SIZEOF_INT > 8
#error "Not prepared for such large int numbers!"
#else
/** Maximum signed int value. */
#define	INT_MAX 9223372036854775807
#endif
#else
/** Maximum signed int value. */
#define	INT_MAX	2147483647
#endif
#else
/** Maximum signed int value. */
#define	INT_MAX	32767
#endif
#endif
/* ifndef INT_MAX */



#ifndef INT_MIN
#if !DK4_USE_FALLBACK_NUMERIC_LIMITS
#error "INT_MIN undefined! See file dk4numco.h, line 10."
#endif
/** Minimum signed int value. */
#define	INT_MIN	(-INT_MAX - 1)
#endif
/* ifndef INT_MIN */



#ifndef UINT_MAX
#if !DK4_USE_FALLBACK_NUMERIC_LIMITS
#error "LONG_MAX undefined! See file dk4numco.h, line 10."
#endif
#if DK4_SIZEOF_INT > 2
#if DK4_SIZEOF_INT > 4
#if DK4_SIZEOF_INT > 8
#error "Not prepared for such large int numbers!"
#else
/** Maximum unsigned int value. */
#define	UINT_MAX	18446744073709551615U
#endif
#else
/** Maximum unsigned int value. */
#define	UINT_MAX	4294967295U
#endif
#else
/** Maximum unsigned int value. */
#define	UINT_MAX	65535U
#endif
#endif
/* ifndef UINT_MAX */



#ifndef LONG_MAX
#if !DK4_USE_FALLBACK_NUMERIC_LIMITS
#error "LONG_MAX undefined! See file dk4numco.h, line 10."
#endif
#if DK4_SIZEOF_LONG > 2
#if DK4_SIZEOF_LONG > 4
#if DK4_SIZEOF_LONG > 8
#error "Not prepared for such large long numbers!"
#else
/** Maximum signed long value. */
#define	LONG_MAX	9223372036854775807L
#endif
#else
/** Maximum signed long value. */
#define	LONG_MAX	2147483647L
#endif
#else
/** Maximum signed long value. */
#define	LONG_MAX	32767L
#endif
#endif
/* ifndef LONG_MAX */



#ifndef LONG_MIN
#if !DK4_USE_FALLBACK_NUMERIC_LIMITS
#error "LONG_MIN undefined! See file dk4numco.h, line 10."
#endif
/** Minimum signed long value. */
#define	LONG_MIN	(-LONG_MAX - 1L)
#endif
/* ifndef LONG_MIN */



#ifndef ULONG_MAX
#if !DK4_USE_FALLBACK_NUMERIC_LIMITS
#error "ULONG_MAX undefined! See file dk4numco.h, line 10."
#endif
#if DK4_SIZEOF_LONG > 2
#if DK4_SIZEOF_LONG > 4
#if DK4_SIZEOF_LONG > 8
#error "Not prepared for such large long numbers!"
#else
/** Maximum unsigned long value. */
#define	ULONG_MAX	18446744073709551615UL
#endif
#else
/** Maximum unsigned long value. */
#define	ULONG_MAX	4294967295UL
#endif
#else
/** Maximum unsigned long value. */
#define	ULONG_MAX	65535UL
#endif
#endif
/* ifndef ULONG_MAX */



#if DK4_HAVE_LONG_LONG



#ifndef LLONG_MAX
#if !DK4_USE_FALLBACK_NUMERIC_LIMITS
#error "LLONG_MAX undefined! See file dk4numco.h, line 10."
#endif
#if DK4_SIZEOF_LONG_LONG > 2
#if DK4_SIZEOF_LONG_LONG > 4
#if DK4_SIZEOF_LONG_LONG > 8
#error "Not prepared for such large long long numbers!"
#else
/** Maximum signed long long value. */
#define	LLONG_MAX	9223372036854775807LL
#endif
#else
/** Maximum signed long long value. */
#define	LLONG_MAX	2147483647LL
#endif
#else
/** Maximum signed long long value. */
#define	LLONG_MAX	32767LL
#endif
#endif
/* ifndef LLONG_MAX */


#ifndef LLONG_MIN
#if !DK4_USE_FALLBACK_NUMERIC_LIMITS
#error "LLONG_MIN undefined! See file dk4numco.h, line 10."
#endif
/** Minimum signed long long value. */
#define	LLONG_MIN	(-LLONG_MAX - 1LL)
#endif
/* ifndef LLONG_MIN */



#ifndef ULLONG_MAX
#if !DK4_USE_FALLBACK_NUMERIC_LIMITS
#error "ULLONG_MAX undefined! See file dk4numco.h, line 10."
#endif
#if DK4_SIZEOF_LONG_LONG > 2
#if DK4_SIZEOF_LONG_LONG > 4
#if DK4_SIZEOF_LONG_LONG > 8
#error "Not prepared for such large long long numbers!"
#else
/** Maximum unsigned long long value. */
#define	ULLONG_MAX	18446744073709551615ULL
#endif
#else
/** Maximum unsigned long long value. */
#define	ULLONG_MAX	4294967295ULL
#endif
#else
/** Maximum unsigned long long value. */
#define	ULLONG_MAX	65535ULL
#endif
#endif
/* ifndef ULLONG_MAX */



#endif
/* if DK4_HAVE_LONG_LONG */




#if DK4_HAVE_INTMAX_T


#ifndef INTMAX_MAX
#if !DK4_USE_FALLBACK_NUMERIC_LIMITS
#error "INTMAX_MAX undefined! See file dk4numco.h, line 10."
#endif
#if DK4_SIZEOF_INTMAX_T == DK4_SIZEOF_INT
/** Maximum intmax_t value. */
#define	INTMAX_MAX	(INT_MAX)
#else
#if DK4_SIZEOF_INTMAX_T == DK4_SIZEOF_LONG
/** Maximum intmax_t value. */
#define	INTMAX_MAX	(LONG_MAX)
#else
#if DK4_HAVE_LONG_LONG
#if DK4_SIZEOF_INTMAX_T == DK4_SIZEOF_LONG_LONG
/** Maximum intmax_t value. */
#define	INTMAX_MAX	(LLONG_MAX)
#else
#error "Not prepared for such large intmax_t numbers!"
#endif
#else
#error "Not prepared for such large intmax_t numbers!"
#endif
#endif
#endif
#endif
/* ifndef INTMAX_MAX */



#ifndef INTMAX_MIN
#if !DK4_USE_FALLBACK_NUMERIC_LIMITS
#error "INTMAX_MIN undefined! See file dk4numco.h, line 10."
#endif
/** Minimum intmax_t value. */
#define	INTMAX_MIN	(-(INTMAX_MAX) - (intmax_t)1)
#endif
/* ifndef INTMAX_MIN */



#ifndef UINTMAX_MAX
#if !DK4_USE_FALLBACK_NUMERIC_LIMITS
#error "UINTMAX_MAX undefined! See file dk4numco.h, line 10."
#endif
#if DK4_SIZEOF_INTMAX_T == DK4_SIZEOF_INT
/** Maximum uintmax_t value. */
#define	UINTMAX_MAX	(UINT_MAX)
#else
#if DK4_SIZEOF_INTMAX_T == DK4_SIZEOF_LONG
/** Maximum uintmax_t value. */
#define	UINTMAX_MAX	(ULONG_MAX)
#else
#if DK4_HAVE_LONG_LONG
#if DK4_SIZEOF_INTMAX_T == DK4_SIZEOF_LONG_LONG
/** Maximum uintmax_t value. */
#define	UINTMAX_MAX	(ULLONG_MAX)
#else
#error "Not prepared for such large uintmax_t numbers!"
#endif
#else
#error "Not prepared for such large uintmax_t numbers!"
#endif
#endif
#endif
#endif
/* ifndef UINTMAX_MAX */



#endif
/* if DK4_HAVE_INTMAX_T */



#if DK4_HAVE_INTMAX_T
/**	Maximum dk4_um_t value.
*/
#define	DK4_UM_MAX	(UINTMAX_MAX)
/**	Maximum dk4_im_t value.
*/
#define	DK4_IM_MAX	(INTMAX_MAX)
/**	Minimum dk4_im_t value.
*/
#define	DK4_IM_MIN	(INTMAX_MIN)
#else
#if DK4_HAVE_LONG_LONG
/**	Maximum dk4_um_t value.
*/
#define	DK4_UM_MAX	(ULLONG_MAX)
/**	Maximum dk4_im_t value.
*/
#define	DK4_IM_MAX	(LLONG_MAX)
/**	Minimum dk4_im_t value.
*/
#define	DK4_IM_MIN	(LLONG_MIN)
#else
/**	Maximum dk4_um_t value.
*/
#define	DK4_UM_MAX	(ULONG_MAX)
/**	Maximum dk4_im_t value.
*/
#define	DK4_IM_MAX	(LONG_MAX)
/**	Minimum dk4_im_t value.
*/
#define	DK4_IM_MIN	(LONG_MIN)
#endif
#endif

#endif
/* ifndef DK4NUMCO_H_INCLUDED */