]> git.lizzy.rs Git - dragonstd.git/blob - number.h
Fix typo in README.md
[dragonstd.git] / number.h
1 #ifndef _DRAGONTYPE_NUMBER_H_
2 #define _DRAGONTYPE_NUMBER_H_
3
4 #include <stdint.h>
5 #include <stdbool.h>
6 #include <stddef.h>
7
8 bool read_full(int fd, char *buffer, size_t size);
9
10 #define DEFRW(type) \
11         bool read_ ## type(int fd, type *ptr); \
12         bool write_ ## type(int fd, type val);
13
14 #define DEFBOX(type) \
15         typedef struct {v ## type min; v ## type max;} aabb ## type;
16
17 #define DEFVEC(type) \
18         typedef struct {type x, y;} v2 ## type; \
19         DEFRW(v2 ## type) \
20         DEFBOX(2 ## type) \
21         bool v2 ## type ## _equals(v2 ## type a, v2 ## type b); \
22         v2 ## type v2 ## type ## _add(v2 ## type a, v2 ## type b); \
23         typedef struct {type x, y, z;} v3 ## type; \
24         DEFRW(v3 ## type) \
25         DEFBOX(3 ## type) \
26         bool v3 ## type ## _equals(v3 ## type a, v3 ## type b); \
27         v3 ## type v3 ## type ## _add(v3 ## type a, v3 ## type b); \
28         typedef struct {type x, y, z, w;} v4 ## type; \
29         DEFRW(v4 ## type) \
30         DEFBOX(4 ## type) \
31         bool v4 ## type ## _equals(v4 ## type a, v4 ## type b); \
32         v4 ## type v4 ## type ## _add(v4 ## type a, v4 ## type b);
33
34 #define DEFTYP(from, to) \
35         typedef from to; \
36         DEFRW(to) \
37         DEFVEC(to)
38
39 #define DEFTYPES(bits) \
40         DEFTYP(int ## bits ## _t, s ## bits) \
41         DEFTYP(uint ## bits ## _t, u ## bits)
42
43 DEFTYPES(8)
44 DEFTYPES(16)
45 DEFTYPES(32)
46 DEFTYPES(64)
47
48 typedef float f32;
49 typedef double f64;
50
51 DEFTYP(float, f32)
52 DEFTYP(double, f64)
53
54 #undef DEFRW
55 #undef DEFBOX
56 #undef DEFVEC
57 #undef DEFTYP
58 #undef DEFTYPES
59
60 #endif