libutil

C Utility Library
git clone http://git.omkov.net/libutil
Log | Tree | Refs | README | LICENCE | Download

libutil/src/util.h (74 lines, 1.5 KiB) -rw-r--r-- file download

8a5f06f Jamozed 2022-02-09 20:04:50
0
// util/util.h, version 1.0.1
359885d Jamozed 2021-12-08 13:58:05
1
// Utility header file from libutil
359885d Jamozed 2021-12-08 13:58:05
2
// Copyright (C) 2021, Jakob Wakeling
7f427d9 Jamozed 2022-03-06 12:55:13
3
// MIT Licence
359885d Jamozed 2021-12-08 13:58:05
4
359885d Jamozed 2021-12-08 13:58:05
5
#ifndef UTIL_UTIL_H_KP8NS9DC
359885d Jamozed 2021-12-08 13:58:05
6
#define UTIL_UTIL_H_KP8NS9DC
8a5f06f Jamozed 2022-02-09 20:04:50
7
8a5f06f Jamozed 2022-02-09 20:04:50
8
#ifdef __cplusplus
8a5f06f Jamozed 2022-02-09 20:04:50
9
extern "C" {
8a5f06f Jamozed 2022-02-09 20:04:50
10
#endif
359885d Jamozed 2021-12-08 13:58:05
11
359885d Jamozed 2021-12-08 13:58:05
12
#include <assert.h>
359885d Jamozed 2021-12-08 13:58:05
13
#include <float.h>
359885d Jamozed 2021-12-08 13:58:05
14
#include <stdbool.h>
359885d Jamozed 2021-12-08 13:58:05
15
#include <stddef.h>
359885d Jamozed 2021-12-08 13:58:05
16
#include <stdint.h>
359885d Jamozed 2021-12-08 13:58:05
17
359885d Jamozed 2021-12-08 13:58:05
18
/* Type Definitions */
359885d Jamozed 2021-12-08 13:58:05
19
typedef uint8_t   u8;
359885d Jamozed 2021-12-08 13:58:05
20
typedef uint16_t  u16;
359885d Jamozed 2021-12-08 13:58:05
21
typedef uint32_t  u32;
359885d Jamozed 2021-12-08 13:58:05
22
typedef uint64_t  u64;
359885d Jamozed 2021-12-08 13:58:05
23
typedef uintptr_t UINT;
359885d Jamozed 2021-12-08 13:58:05
24
359885d Jamozed 2021-12-08 13:58:05
25
typedef int8_t   s8;
359885d Jamozed 2021-12-08 13:58:05
26
typedef int16_t  s16;
359885d Jamozed 2021-12-08 13:58:05
27
typedef int32_t  s32;
359885d Jamozed 2021-12-08 13:58:05
28
typedef int64_t  s64;
359885d Jamozed 2021-12-08 13:58:05
29
typedef intptr_t sint;
359885d Jamozed 2021-12-08 13:58:05
30
359885d Jamozed 2021-12-08 13:58:05
31
typedef float       f32;
359885d Jamozed 2021-12-08 13:58:05
32
typedef double      f64;
359885d Jamozed 2021-12-08 13:58:05
33
typedef long double f128;
359885d Jamozed 2021-12-08 13:58:05
34
359885d Jamozed 2021-12-08 13:58:05
35
/* Type Limits */
359885d Jamozed 2021-12-08 13:58:05
36
#define U8_MIN   UINT8_MIN
359885d Jamozed 2021-12-08 13:58:05
37
#define U8_MAX   UINT8_MAX
359885d Jamozed 2021-12-08 13:58:05
38
#define U16_MIN  UINT16_MIN
359885d Jamozed 2021-12-08 13:58:05
39
#define U16_MAX  UINT16_MAX
359885d Jamozed 2021-12-08 13:58:05
40
#define U32_MIN  UINT32_MIN
359885d Jamozed 2021-12-08 13:58:05
41
#define U32_MAX  UINT32_MAX
359885d Jamozed 2021-12-08 13:58:05
42
#define U64_MIN  UINT64_MIN
359885d Jamozed 2021-12-08 13:58:05
43
#define U64_MAX  UINT64_MAX
359885d Jamozed 2021-12-08 13:58:05
44
#define UINT_MIN UINTPTR_MIN
359885d Jamozed 2021-12-08 13:58:05
45
#define UINT_MAX UINTPTR_MAX
359885d Jamozed 2021-12-08 13:58:05
46
359885d Jamozed 2021-12-08 13:58:05
47
#define S8_MIN   INT8_MIN
359885d Jamozed 2021-12-08 13:58:05
48
#define S8_MAX   INT8_MAX
359885d Jamozed 2021-12-08 13:58:05
49
#define S16_MIN  INT16_MIN
359885d Jamozed 2021-12-08 13:58:05
50
#define S16_MAX  INT16_MAX
359885d Jamozed 2021-12-08 13:58:05
51
#define S32_MIN  INT32_MIN
359885d Jamozed 2021-12-08 13:58:05
52
#define S32_MAX  INT32_MAX
359885d Jamozed 2021-12-08 13:58:05
53
#define S64_MIN  INT64_MIN
359885d Jamozed 2021-12-08 13:58:05
54
#define S64_MAX  INT64_MAX
359885d Jamozed 2021-12-08 13:58:05
55
#define SINT_MIN INTPTR_MIN
359885d Jamozed 2021-12-08 13:58:05
56
#define SINT_MAX INTPTR_MAX
359885d Jamozed 2021-12-08 13:58:05
57
359885d Jamozed 2021-12-08 13:58:05
58
#define F32_MIN  FLT_MIN
359885d Jamozed 2021-12-08 13:58:05
59
#define F32_MAX  FLT_MAX
359885d Jamozed 2021-12-08 13:58:05
60
#define F64_MIN  DBL_MIN
359885d Jamozed 2021-12-08 13:58:05
61
#define F64_MAX  DBL_MAX
359885d Jamozed 2021-12-08 13:58:05
62
#define F128_MIN LDBL_MIN
359885d Jamozed 2021-12-08 13:58:05
63
#define F128_MAX LDBL_MAX
359885d Jamozed 2021-12-08 13:58:05
64
359885d Jamozed 2021-12-08 13:58:05
65
/* Miscellaneous */
359885d Jamozed 2021-12-08 13:58:05
66
#define BIT(x) (1 << (x))
8a5f06f Jamozed 2022-02-09 20:04:50
67
8a5f06f Jamozed 2022-02-09 20:04:50
68
#ifdef __cplusplus
8a5f06f Jamozed 2022-02-09 20:04:50
69
} // extern "C"
8a5f06f Jamozed 2022-02-09 20:04:50
70
#endif
359885d Jamozed 2021-12-08 13:58:05
71
359885d Jamozed 2021-12-08 13:58:05
72
#endif // UTIL_UTIL_H_KP8NS9DC
73