-
Notifications
You must be signed in to change notification settings - Fork 0
/
realnum.h
57 lines (37 loc) · 1.17 KB
/
realnum.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
#ifndef REALNUM_WRAPPER_H
#define REALNUM_WRAPPER_H
#if defined(REALNUM_USE_FLOAT)
#include <math.h>
typedef float real;
#define int2real(x) ((float)(x))
#define real2int(x) ((int)(x))
#define realdecimal(x) ((x) - (int)x)
#define float2real(x) (x)
#define real2float(x) (x)
#define real(x) ((float)(x))
#define fixed2real(x, N) ((float)(x) / (float)(1 << N))
#define realabs(x) (fabsf(x))
#define realround(x) (roundf(x))
#define realmul(x, y) ((x) * (y))
#define realdiv(x, y) ((x) / (y))
#define realsqrt(x) (sqrtf(x))
#elif defined(REALNUM_USE_FIXED)
#include "fixedpoint.h"
typedef fixed real;
#define int2real(x) int2fixed(x)
#define real2int(x) fixed2int(x)
#define realdecimal(x) fixdecimal(x)
#define float2real(x) float2fixed(x)
#define real2float(x) fixed2float(x)
#define real(x) fixed(x)
static inline real fixed2real(long x, int N) {
int d = FIXEDLEN - N;
return (d >= 0) ? ((BASETYPE)x << d) : ((BASETYPE)x >> -d);
}
#define realabs(x) fixabs(x)
#define realround(x) fixround(x)
#define realmul(x, y) fixmul(x, y)
#define realdiv(x, y) fixdiv(x, y)
#define realsqrt(x) fixsqrt(x)
#endif
#endif