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