1 #ifndef _H_INCLUDED2 #define _H_INCLUDED
3
4 #include
5 #include
6 #include
7 #include
8 #include
9 #include
10 #include
11 #include
12
13 #define DEBUG
14 #define USE_WINDOWS
15
16 /*********************************************/
17 #if defined(USE_WINDOWS)
18 #define DIR_SEPERATOR ‘\\‘
19 #else
20 #define DIR_SEPERATOR ‘/‘
21 #endif
22 /*********************************************/
23
24 /*********************************************/
25 #if LONG_MAX >> 31 > 0
26 #define WORD_BYTES 8 /* 64-bit */
27 #elif INT_MAX >> 15 > 0
28 #define WORD_BYTES 4 /* 32-bit */
29 #else
30 #define WORD_BYTES 2 /* 16-bit */
31 #endif
32 /*********************************************/
33
34 /*********************************************/
35 #if WORD_BYTES == 8
36
37 typedef signed longintx;38 typedef unsigned longuintx;39 typedef signed intint32;40 typedef unsigned intuint32;41
42 #elif WORD_BYTES == 4
43
44 typedef signed intintx;45 typedef unsigned intuintx;46 typedef signed intint32;47 typedef unsigned intuint32;48
49 #else
50
51 typedef signed intintx;52 typedef unsigned intuintx;53 typedef signed longint32;54 typedef unsigned longuint32;55
56 #endif /* WORD_BYTES */
57 /*********************************************/
58
59 /*********************************************/
60 #define REAL_TYPE_FLOAT 1
61 #define REAL_TYPE_DOUBLE 2
62 #define REAL_TYPE_LONGDOUBLE 3
63 /*********************************************/
64
65 /*********************************************/
66 #ifndef REAL_TYPE67
68 #if WORD_BYTES == 8
69 #define REAL_BYTES 8
70 #define REAL_TYPE REAL_TYPE_DOUBLE
71 #else
72 #define REAL_BYTES 4
73 #define REAL_TYPE REAL_TYPE_FLOAT
74 #endif /* WORD_BYTES */
75
76 #endif /* REAL_TYPE */
77 /*********************************************/
78
79 /*********************************************/
80 #if REAL_TYPE == REAL_TYPE_FLOAT
81
82 typedef floatreal;83 #define REAL_FORMAT "%.7g"
84 #define real_limit(n) FLT_##n
85 #define math_op(op) op##f
86 #define math_s2r(s,p) (strtof((s),(p)))
87
88 #elif REAL_TYPE == REAL_TYPE_DOUBLE
89
90 typedef doublereal;91 #define REAL_FORMAT "%.14g"
92 #define real_limit(n) DBL_##n
93 #define math_op(op) op##d
94 #define math_s2r(s,p) (strtod((s),(p)))
95
96 #elif REAL_TYPE == REAL_TYPE_LONGDOUBLE
97
98 #define REAL_FORMAT "%.19g"
99 #define real_limit(n) LDBL_##n
100 #define math_op(op) op##l
101 #define math_s2r(s,p) (strtold((s),(p)))
102
103 #else
104
105 #error "numeric float type not defined"
106
107 #endif
108 /*********************************************/
109
110 /*********************************************/
111 typedef signed shortint16;112 typedef unsigned shortuint16;113 typedef signed charint8;114 typedef unsigned charuint8;115 typedef unsigned char byte;116 typedef unsigned charboolean;117 typedef void *Pointer;118 typedef char *Chars;119 typedef FILE *File;120 /*********************************************/
121
122 /*********************************************/
123 #define bitsof(t) (sizeof(t)<<3)
124 #define cast_type(t, x) ((t)(x))
125 #define cast_intx(x) ((intx)(x))
126 #define cast_uintx(x) ((uintx)(x))
127 #define cast_int32(x) ((int32)(x))
128 #define cast_uint32(x) ((uint32)(x))
129 #define cast_int16(x) ((int16)(x))
130 #define cast_uint16(x) ((uint16)(x))
131 #define cast_int8(x) ((int8)(x))
132 #define cast_uint8(x) ((uint8)(x))
133 #define cast_byte(x) ((byte)(x))
134 #define cast_boolean(x) ((boolean)(!!(x)))
135 #define cast_void(x) ((void)(x))
136 #define cast_Chars(x) ((Chars)(x))
137 #define cast_Pointer(x) ((Pointer)(x))
138 #define struct_new(t) ((t)calloc(1, sizeof_type(t)))
139 #define struct_alloc(t) ((t)malloc(sizeof_type(t)))
140 #define array_size(a) (sizeof(a)/sizeof(*(a)))
141 #define math_max(x, y) ((x) > (y) ? (x) : (y))
142 #define math_min(x, y) ((x) < (y) ? (x) : (y))
143 #define math_swap(x, y) ((x) ^= (y) ^= (x) ^= (y))
144 #define math_abs(x) ((x) < 0 ? -(x) : (x))
145 #define math_sign(x) ((x) < 0 ? -1 : ((x) ? 1 : 0))
146 #define math_r2i(r, i) ((i = (r)) == (r))
147 #define math_pow2(n) (1 << (n))
148 /*********************************************/
149
150 /*********************************************/
151 #ifdef DEBUG152 #define debug_assert(c) ((c)||printf("debug>> assertion failed: %s, #%d, "#c"\n",__FILE__,__LINE__))
153 #else
154 #define debug_assert(c) ((void)0)
155 #endif
156 /*********************************************/
157
158 #endif