Mercurial > hg > dmlib
annotate tests/fptest.c @ 1432:a9516570cc26
Improve build, so that we can build the tools and tests with minimal
depencies (e.g. without libSDL linking when possible.) And this also on
Win32 MinGW.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 22 Nov 2017 01:33:21 +0200 |
parents | 5e1d67f33dec |
children | 61246926756a |
rev | line source |
---|---|
1432
a9516570cc26
Improve build, so that we can build the tools and tests with minimal
Matti Hamalainen <ccr@tnsp.org>
parents:
1147
diff
changeset
|
1 #include "dmtool.h" |
0 | 2 #include "dmlib.h" |
3 #include <stdio.h> | |
4 | |
5 #define FP_DW_SIZE 8 | |
6 #define FP_W0_SIZE 4 | |
7 | |
36
f3407a58e01e
Change DMFixedPoint types and appropriate JSS functions back to using signed
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
8 void check(const char *str, DMFixedPoint v, Sint64 dw) |
0 | 9 { |
10 DMFixedPoint *q = (DMFixedPoint *) &dw; | |
11 | |
809
eba3b87f3f84
Add some separate macros for 64/32 precision fixed point types.
Matti Hamalainen <ccr@tnsp.org>
parents:
653
diff
changeset
|
12 printf("%-15s = ", str); FP_PRINTF64(v); printf("\n"); |
eba3b87f3f84
Add some separate macros for 64/32 precision fixed point types.
Matti Hamalainen <ccr@tnsp.org>
parents:
653
diff
changeset
|
13 printf("should be = "); FP_PRINTF64((*q)); printf("\n"); |
0 | 14 |
15 if (v.dw != dw) | |
16 { | |
17 printf("ERROR! A test value differs from expected!\n"); | |
18 exit(1); | |
19 } | |
20 } | |
21 | |
22 int main(int argc, char *argv[]) | |
23 { | |
24 int i; | |
25 DMFixedPoint a, b, delta; | |
26 char *s; | |
27 | |
28 (void) argc; | |
29 (void) argv; | |
30 | |
31 // Check host characteristics | |
32 switch (SDL_BYTEORDER) | |
33 { | |
34 case SDL_BIG_ENDIAN: s = "big endian"; break; | |
35 case SDL_LIL_ENDIAN: s = "little endian"; break; | |
36 default: s = "unknown?"; break; | |
37 } | |
38 | |
39 printf( | |
40 "SDL byte order = %s (%d)\n\n", s, SDL_BYTEORDER); | |
41 | |
42 printf( | |
1147
5e1d67f33dec
Use DM_PRI* format specifiers here.
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
43 "sizeof(DMFixedPoint) = %" DM_PRId64 " bytes\n" |
5e1d67f33dec
Use DM_PRI* format specifiers here.
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
44 "sizeof(DMFixedPoint.dw) = %" DM_PRId64 " bytes (should be %d)\n" |
5e1d67f33dec
Use DM_PRI* format specifiers here.
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
45 "sizeof(DMFixedPoint.w[0]) = %" DM_PRId64 " bytes (should be %d)\n", |
0 | 46 sizeof(a), sizeof(a.dw), FP_DW_SIZE, |
47 sizeof(a.w[0]), FP_W0_SIZE); | |
48 | |
49 if (sizeof(a.dw) != FP_DW_SIZE || sizeof(a.w[0]) != FP_W0_SIZE) | |
50 { | |
51 printf("ERROR! Some type sizes DO NOT MATCH!\n"); | |
52 return -1; | |
53 } | |
54 | |
55 // TEST #1 | |
56 printf("\nTEST #1: set initial values\n"); | |
57 FP_SETHL(a, 55, 0); | |
58 check("a", a, 0x0000003700000000ULL); | |
59 | |
60 FP_CONV(b, 178); | |
61 check("b", b, 0x00000000000000b2ULL); | |
62 | |
63 FP_DIV_R(delta, a, b); | |
64 check("delta", delta, 0x000000004f19e33cULL); | |
65 | |
66 // Test #2 | |
67 printf("\nTEST #2: 50 x (a + delta)\n"); | |
68 for (i = 0; i < 50; i++) | |
69 { | |
70 FP_ADD(a, delta); | |
71 } | |
72 check("a end", a, 0x00000046730e61b8ULL); | |
73 | |
74 | |
75 // Test #3 | |
76 printf("\nTEST #3: 50 x (a - delta)\n"); | |
77 for (i = 0; i < 50; i++) | |
78 { | |
79 FP_SUB(a, delta); | |
80 } | |
81 check("a end", a, 0x0000003700000000ULL); | |
82 | |
83 // Test #4 | |
84 printf("\nTEST #4: 5 x (a * delta)\n"); | |
85 for (i = 0; i < 5; i++) | |
86 { | |
87 FP_MUL(a, delta); | |
88 } | |
89 check("a end", a, 0xd644e40000000000ULL); | |
90 | |
91 // Test #5 | |
92 printf("\nTEST #4: 2 x (a / delta)\n"); | |
93 for (i = 0; i < 2; i++) | |
94 { | |
95 FP_DIV(a, delta); | |
96 } | |
97 check("a end", a, 8ULL); | |
98 | |
99 return 0; | |
100 } |