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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
#include "test.h"
#include "fixpt.h"
#include "util.c"
#include "fixpt.c"
static void check_common(void)
{
/* Check conversion functions */
CHECK(float_to_fixpt(1.0f) == int_to_fixpt(1));
CHECK(float_to_fixpt(5.0f) == int_to_fixpt(5));
CHECK(float_to_fixpt(10.0f) == int_to_fixpt(10));
CHECK(float_to_fixpt(1023.0f) == int_to_fixpt(1023));
CHECK(float_to_fixpt(-1.0f) == int_to_fixpt(-1));
CHECK(float_to_fixpt(-99.0f) == int_to_fixpt(-99));
CHECK(float_to_fixpt(-1023.0f) == int_to_fixpt(-1023));
CHECK(fixpt_to_int(int_to_fixpt(6)) == 6);
CHECK(fixpt_to_float(float_to_fixpt(6.0f)) == 6.0f);
CHECK(fixpt_to_float(float_to_fixpt(6.5f)) == 6.5f);
CHECK(fixpt_to_float(float_to_fixpt(6.5f)) != 6.0f);
CHECK(fixpt_to_float(float_to_fixpt(-6.0f)) == -6.0f);
/* Check rounding of conversion functions */
CHECK(fixpt_to_int(float_to_fixpt(5.4f)) == 5);
CHECK(fixpt_to_int(float_to_fixpt(5.5f)) == 6);
CHECK(fixpt_to_int(float_to_fixpt(5.6f)) == 6);
CHECK(fixpt_to_int(float_to_fixpt(-5.4f)) == -5);
CHECK(fixpt_to_int(float_to_fixpt(-5.5f)) == -6);
CHECK(fixpt_to_int(float_to_fixpt(-5.6f)) == -6);
CHECK(fixpt_to_int(float_to_fixpt(0.4f)) == 0);
CHECK(fixpt_to_int(float_to_fixpt(0.5f)) == 1);
CHECK(fixpt_to_int(float_to_fixpt(0.6f)) == 1);
CHECK(fixpt_to_int(float_to_fixpt(-0.4f)) == 0);
CHECK(fixpt_to_int(float_to_fixpt(-0.5f)) == -1);
CHECK(fixpt_to_int(float_to_fixpt(-0.6f)) == -1);
/* Check decimal functions */
CHECK(fixpt_get_int_part(float_to_fixpt(0.0f)) == 0);
CHECK(fixpt_get_int_part(float_to_fixpt(1.0f)) == 1);
CHECK(fixpt_get_int_part(float_to_fixpt(1.5f)) == 1);
CHECK(fixpt_get_int_part(float_to_fixpt(2.5f)) == 2);
CHECK(fixpt_get_int_part(float_to_fixpt(-1.0f)) == -1);
CHECK(fixpt_get_int_part(float_to_fixpt(-1.5f)) == -1);
CHECK(fixpt_get_int_part(float_to_fixpt(-2.5f)) == -2);
CHECK(fixpt_get_dec_fract(float_to_fixpt(1.25f), 2) == 25);
CHECK(fixpt_get_dec_fract(float_to_fixpt(-1.25f), 2) == 25);
CHECK(fixpt_get_dec_fract(float_to_fixpt(1.25f), 1) == 3);
CHECK(fixpt_get_dec_fract(float_to_fixpt(1.225f), 1) == 2);
CHECK(fixpt_get_dec_fract(float_to_fixpt(-1.25f), 1) == 3);
CHECK(fixpt_get_dec_fract(float_to_fixpt(-1.225f), 1) == 2);
CHECK(fixpt_get_dec_fract(float_to_fixpt(1.125f), 1) == 1);
CHECK(fixpt_get_dec_fract(float_to_fixpt(1.125f), 2) == 13);
CHECK(fixpt_get_dec_fract(float_to_fixpt(1.125f), 3) == 125);
CHECK(fixpt_get_dec_fract(float_to_fixpt(-1.125f), 1) == 1);
CHECK(fixpt_get_dec_fract(float_to_fixpt(-1.125f), 2) == 13);
CHECK(fixpt_get_dec_fract(float_to_fixpt(-1.125f), 3) == 125);
CHECK(fixpt_get_dec_fract(float_to_fixpt(1.0f), 2) == 0);
CHECK(fixpt_get_dec_fract(float_to_fixpt(-1.0f), 2) == 0);
CHECK(fixpt_get_dec_fract(float_to_fixpt(0.0f), 2) == 0);
}
int main(void)
{
check_common();
return 0;
}
|