-
Notifications
You must be signed in to change notification settings - Fork 2
/
real.h
56 lines (52 loc) · 1.45 KB
/
real.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
#ifndef REAL_H
#define REAL_H
#ifdef USE_F16
#include "float16.h"
typedef short real_t;
#define real_gt(a,b) f16_gt((a),(b))
#define real_div(a,b) f16_div((a),(b))
#define real_mul(a,b) f16_mul((a),(b))
#define real_add(a,b) f16_add((a),(b))
#define real_sub(a,b) f16_sub((a),(b))
#define real_one f16_one
#define real_from_int(a) f16_from_int((a))
#define real_int(a) f16_int((a))
#define real_neg(a) f16_neg((a))
#define real_name "float16"
#elif defined USE_FIXED
typedef short real_t;
#define real_add(a,b) ((a)+(b))
#define real_sub(a,b) ((a)-(b))
#define real_neg(a) (-(a))
#define real_gt(a,b) ((a) > (b))
#ifdef USE_FIXED88
#include "fixed8_math.h"
#define real_div(a,b) ((short)(((long)(a)<<8)/b))
#define real_mul(a,b) fixed8_mpl((a),(b))
#define real_one 256
#define real_from_int(a) ((a)<<8)
#define real_int(a) ((a)>>8)
#define real_name "fixed 8:8"
#else
#include "fixed12_math.h"
#define real_div(a,b) ((short)((long)((a)<<12)/b))
#define real_mul(a,b) fixed12_mpl((a),(b))
#define real_one 4096
#define real_from_int(a) ((a)<<12)
#define real_int(a) ((a)>>12)
#define real_name "fixed 4:12"
#endif
#elif defined USE_FLOAT
typedef float real_t;
#define real_div(a,b) ((a)/(b))
#define real_mul(a,b) ((a)*(b))
#define real_add(a,b) ((a)+(b))
#define real_sub(a,b) ((a)-(b))
#define real_gt(a,b) ((a) > (b))
#define real_one 1.0f
#define real_from_int(a) ((float)(a))
#define real_int(a) ((int)(a)
#define real_neg(a) (-(a))
#define real_name "float32"
#endif
#endif