-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshortnum.h
62 lines (51 loc) · 1.9 KB
/
shortnum.h
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
/*
* shortnum.h: Shortened numerical types for convenience
* This is free and unencumbered software released into the public domain
*/
#ifndef SHORTNUM_H
#define SHORTNUM_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
/* Support for custom prefixes */
#ifndef SHORTNUM_SIGNED_PREFIX
#define SHORTNUM_SIGNED_PREFIX s
#endif
#ifndef SHORTNUM_UNSIGNED_PREFIX
#define SHORTNUM_UNSIGNED_PREFIX u
#endif
#ifndef SHORTNUM_FLOAT_PREFIX
#define SHORTNUM_FLOAT_PREFIX f
#endif
/* Internal macros required for custom prefix support*/
#define __SHORTNUM_EVAL(__prefix, __bitsize) __prefix##__bitsize
#define __SHORTNUM_COMBINE(__prefix, __bitsize) __SHORTNUM_EVAL(__prefix, __bitsize)
#define __SHORTNUM_PREPEND_SIGNED(__bitsize) __SHORTNUM_COMBINE(SHORTNUM_SIGNED_PREFIX, __bitsize)
#define __SHORTNUM_PREPEND_UNSIGNED(__bitsize) __SHORTNUM_COMBINE(SHORTNUM_UNSIGNED_PREFIX, __bitsize)
#define __SHORTNUM_PREPEND_FLOAT(__bitsize) __SHORTNUM_COMBINE(SHORTNUM_FLOAT_PREFIX, __bitsize)
typedef int8_t __SHORTNUM_PREPEND_SIGNED(8);
typedef int16_t __SHORTNUM_PREPEND_SIGNED(16);
typedef int32_t __SHORTNUM_PREPEND_SIGNED(32);
typedef int64_t __SHORTNUM_PREPEND_SIGNED(64);
typedef uint8_t __SHORTNUM_PREPEND_UNSIGNED(8);
typedef uint16_t __SHORTNUM_PREPEND_UNSIGNED(16);
typedef uint32_t __SHORTNUM_PREPEND_UNSIGNED(32);
typedef uint64_t __SHORTNUM_PREPEND_UNSIGNED(64);
/* Allow user to define their own floating point types */
#ifndef SHORTNUM_CUSTOM_FLOAT
typedef float __SHORTNUM_PREPEND_FLOAT(32);
typedef double __SHORTNUM_PREPEND_FLOAT(64);
#endif
/* Might be useful to keep internal macros if user wishes to define their own types */
#ifndef SHORTNUM_KEEP_INTERNAL_MACROS
#undef __SHORTNUM_EVAL
#undef __SHORTNUM_COMBINE
#undef __SHORTNUM_PREPEND_SIGNED
#undef __SHORTNUM_PREPEND_UNSIGNED
#undef __SHORTNUM_PREPEND_FLOAT
#endif
#ifdef __cplusplus
}
#endif
#endif /* SHORTNUM_H */