-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathutil.h
47 lines (35 loc) · 1.01 KB
/
util.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
#ifndef UTIL_H_
#define UTIL_H_
typedef union _un16 {
uint16_t u;
int16_t i;
uint8_t b[2];
} un16;
typedef union _un32 {
uint32_t u;
int32_t i;
uint16_t w[2];
uint8_t b[4];
} un32;
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
#define OUT 1
#define IN 0
#define MIN(x,y) ((x) < (y) ? (x) : (y))
#define MAX(x,y) ((x) > (y) ? (x) : (y))
#define ABS(x) ((x) < 0 ? -(x) : (x))
#define CLAMP(x,mn,mx) {if (x <= (mn)) x = (mn); else if (x >= (mx)) x = (mx);}
#define CORE(x,t) {if (ABS(x) <= (t)) x = 0;}
#define MCORE(x,t) {if (x > (t)) x -= (t); else if (x < -(t)) x += (t); else x = 0;}
#define CORRECT(x,mx,mn) (((float)(x-mn)/(float)(mx-mn)) - 0.5f)
#define M_PI 3.1415927f
#define RAD2DEG(r) ((r)*57.29577951f)
#define DEG2RAD(d) ((d)*0.017453292f)
#define _180_DIV_PI 57.295779f
#define PI_DIV_180 0.017453292f
#define NOP() { asm volatile ("nop"); }
#endif