1 /*
2 * PROJECT: ReactOS API tests
3 * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4 * PURPOSE: Tests for __i64tod/u64tod/i64tos/u64tos on ARM
5 * COPYRIGHT: Copyright 2021 Stanislav Motylkov <x86corez@gmail.com>
6 */
7
8 #include <apitest.h>
9
10 typedef struct _I64TOD_TEST_DATA
11 {
12 long long given;
13 union
14 {
15 double value;
16 unsigned long long raw;
17 } expected;
18 } I64TOD_TEST_DATA;
19
20 typedef struct _U64TOD_TEST_DATA
21 {
22 unsigned long long given;
23 union
24 {
25 double value;
26 unsigned long long raw;
27 } expected;
28 } U64TOD_TEST_DATA;
29
30 typedef struct _I64TOS_TEST_DATA
31 {
32 long long given;
33 union
34 {
35 float value;
36 unsigned int raw;
37 } expected;
38 } I64TOS_TEST_DATA;
39
40 typedef struct _U64TOS_TEST_DATA
41 {
42 unsigned long long given;
43 union
44 {
45 float value;
46 unsigned int raw;
47 } expected;
48 } U64TOS_TEST_DATA;
49
START_TEST(__64tof)50 START_TEST(__64tof)
51 {
52 I64TOD_TEST_DATA i64tod[] =
53 {
54 { 1383034209LL, 1383034209.0 }, /* test 32bit number */
55 { -1383034209LL, -1383034209.0 }, /* test negative 32bit number */
56 { 354056757614LL, 354056757614.0 }, /* test 64bit int */
57 { -354056757614LL, -354056757614.0 }, /* test negative 64bit int */
58 { 18446744073709550000LL, -1616.0 }, /* test 20bit in float */
59 { 0x8000000000000000LL, -9223372036854775800.0 }, /* test big 64bit int */
60 { 0xFFFFFFFFFFFFFFFFLL, -1.0 }, /* test -1 */
61 { 0LL, +0.0 }, /* test 0 */
62 };
63 U64TOD_TEST_DATA u64tod[] =
64 {
65 { 1383034209ULL, 1383034209.0 }, /* test 32bit number */
66 { 354056757614ULL, 354056757614.0 }, /* test 64bit int */
67 { 18445937028656326656ULL, 18445937028656326656.0 }, /* test unsigned 64bit */
68 { 18446744073709550000ULL, 18446744073709550000.0 }, /* test 20bit in float */
69 { 18446744073709551615ULL, 18446744073709552000.0 }, /* test big 64bit number */
70 { 0ULL, +0.0 }, /* test 0 */
71 };
72 I64TOS_TEST_DATA i64tos[] =
73 {
74 { 1383034LL, 1383034.0f }, /* test 32bit number */
75 { -1383034LL, -1383034.0f }, /* test negative 32bit number */
76 { 354056765440LL, 354056765440.0f }, /* test 64bit int */
77 { -354056765440LL, -354056765440.0f }, /* test negative 64bit int */
78 { 18446744073709550000LL, -1616.0f }, /* test 20bit in float */
79 { 0x8000000000000000LL, -9223372036854775800.0f }, /* test big 64bit int */
80 { 0xFFFFFFFFFFFFFFFFLL, -1.0f }, /* test -1 */
81 { 0LL, +0.0f }, /* test 0 */
82 };
83 U64TOS_TEST_DATA u64tos[] =
84 {
85 { 1383034ULL, 1383034.0f }, /* test 32bit number */
86 { 354056765440ULL, 354056765440.0f }, /* test 64bit int */
87 { 18445937032174764032ULL, 18445937032174764032.0f }, /* test unsigned 64bit */
88 { 18446744073709550000ULL, 18446744073709550000.0f }, /* test 20bit in float */
89 { 18446744073709551615ULL, 18446744073709552000.0f }, /* test big 64bit number */
90 { 0ULL, +0.0f }, /* test 0 */
91 };
92
93 unsigned int i;
94
95 for (i = 0; i < _countof(i64tod); ++i)
96 {
97 double actual;
98
99 actual = (double)i64tod[i].given;
100 ok(actual == i64tod[i].expected.value, "(i64tod) %d: Expected %lf, but %lld -> %lf\n",
101 i, i64tod[i].expected.value, i64tod[i].given, actual);
102 }
103
104 for (i = 0; i < _countof(u64tod); ++i)
105 {
106 double actual;
107
108 actual = (double)u64tod[i].given;
109 ok(actual == u64tod[i].expected.value, "(u64tod) %d: Expected %lf, but %llu -> %lf\n",
110 i, u64tod[i].expected.value, u64tod[i].given, actual);
111 }
112
113 for (i = 0; i < _countof(i64tos); ++i)
114 {
115 float actual;
116
117 actual = (float)i64tos[i].given;
118 ok(actual == i64tos[i].expected.value, "(i64tos) %d: Expected %f, but %lld -> %f\n",
119 i, i64tos[i].expected.value, i64tos[i].given, actual);
120 }
121
122 for (i = 0; i < _countof(u64tos); ++i)
123 {
124 float actual;
125
126 actual = (float)u64tos[i].given;
127 ok(actual == u64tos[i].expected.value, "(u64tos) %d: Expected %f, but %llu -> %f\n",
128 i, u64tos[i].expected.value, u64tos[i].given, actual);
129 }
130 }
131