Skip to content

Commit b3dff9d

Browse files
committed
[CRT_APITEST] Add tests for _finite(f)
1 parent 39e534b commit b3dff9d

File tree

6 files changed

+134
-0
lines changed

6 files changed

+134
-0
lines changed
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
/*
2+
* PROJECT: ReactOS API tests
3+
* LICENSE: MIT (https://spdx.org/licenses/MIT)
4+
* PURPOSE: Tests for _finite / _finitef
5+
* COPYRIGHT: Copyright 2025 Timo Kreuzer <[email protected]>
6+
*/
7+
8+
#if !defined(_CRTBLD) && !defined(_M_IX86)
9+
#define _CRTBLD // we don't want inline _finitef!
10+
#endif
11+
#include "math_helpers.h"
12+
13+
static TESTENTRY_DBL_INT s_finite_tests[] =
14+
{
15+
/* Special values */
16+
{ 0x0000000000000000 /* 0.000000000000000e+000 */, 1 },
17+
{ 0x0000000000000001 /* 0.000000000000000e+000 */, 1 },
18+
{ 0x000fffffffffffff /* 0.000000000000000e+000 */, 1 },
19+
{ 0x8000000000000000 /* -0.000000000000000e+000 */, 1 },
20+
{ 0x8000000000000001 /* -0.000000000000000e+000 */, 1 },
21+
{ 0x800fffffffffffff /* -0.000000000000000e+000 */, 1 },
22+
{ 0x7ff0000000000000 /* 1.#INF00000000000e+000 */, 0 },
23+
{ 0x7ff0000000000001 /* 1.#QNAN0000000000e+000 */, 0 },
24+
{ 0x7ff7ffffffffffff /* 1.#QNAN0000000000e+000 */, 0 },
25+
{ 0x7ff8000000000000 /* 1.#QNAN0000000000e+000 */, 0 },
26+
{ 0x7ff8000000000001 /* 1.#QNAN0000000000e+000 */, 0 },
27+
{ 0x7fffffffffffffff /* 1.#QNAN0000000000e+000 */, 0 },
28+
{ 0xfff0000000000000 /* -1.#INF00000000000e+000 */, 0 },
29+
{ 0xfff0000000000001 /* -1.#QNAN0000000000e+000 */, 0 },
30+
{ 0xfff7ffffffffffff /* -1.#QNAN0000000000e+000 */, 0 },
31+
{ 0xfff8000000000000 /* -1.#IND00000000000e+000 */, 0 },
32+
{ 0xfff8000000000001 /* -1.#QNAN0000000000e+000 */, 0 },
33+
{ 0xffffffffffffffff /* -1.#QNAN0000000000e+000 */, 0 },
34+
35+
/* Some random doubles */
36+
{ 0x386580c747a3402b /* 5.055340589883462e-037 */, 1 },
37+
{ 0xb74298e6627fb9ed /* -1.667860443847725e-042 */, 1 },
38+
{ 0x0ef25f06e414aa2d /* 1.128498317470960e-236 */, 1 },
39+
{ 0x24002a37167638b5 /* 2.780001692929186e-135 */, 1 },
40+
{ 0x44258d1be62a0d22 /* 1.987747995999515e+020 */, 1 },
41+
{ 0x9ed4e46a65aad464 /* -3.715074250469020e-160 */, 1 },
42+
{ 0xc5afcd6f4ae4bf41 /* -4.921195330852160e+027 */, 1 },
43+
{ 0x330fac896cbb01d2 /* 9.624395081137827e-063 */, 1 },
44+
{ 0xc18026ab4c845405 /* -3.387120956461338e+007 */, 1 },
45+
{ 0x2f42a7dc898a741a /* 4.916804395045249e-081 */, 1 },
46+
};
47+
48+
49+
void Test__finite(void)
50+
{
51+
int i;
52+
53+
for (i = 0; i < _countof(s_finite_tests); i++)
54+
{
55+
double x = u64_to_dbl(s_finite_tests[i].x);
56+
int r = _finite(x);
57+
ok(r == s_finite_tests[i].result, "Wrong result for %f [0x%016I64x]. Expected %d, got %d\n", x, s_finite_tests[i].x, s_finite_tests[i].result, r);
58+
}
59+
}
60+
61+
#ifndef _M_IX86
62+
static TESTENTRY_FLT s_finitef_tests[] =
63+
{
64+
/* Special values */
65+
{ 0x00000000 /* 0.000000 */, 1 },
66+
{ 0x00000001 /* 0.000000 */, 1 },
67+
{ 0x007FFFFF /* 0.000000 */, 1 },
68+
{ 0x80000000 /* -0.000000 */, 1 },
69+
{ 0x80000001 /* -0.000000 */, 1 },
70+
{ 0x807FFFFF /* -0.000000 */, 1 },
71+
{ 0x7f800000 /* 1.#INF00 */, 0 },
72+
{ 0x7f800001 /* 1.#SNAN0 */, 0 },
73+
{ 0x7fBFffff /* 1.#SNAN0 */, 0 },
74+
{ 0x7fC00000 /* 1.#QNAN0 */, 0 },
75+
{ 0x7fC80001 /* 1.#QNAN0 */, 0 },
76+
{ 0x7fFfffff /* 1.#QNAN0 */, 0 },
77+
{ 0xff800000 /* -1.#INF00 */, 0 },
78+
{ 0xff800001 /* -1.#SNAN0 */, 0 },
79+
{ 0xffBfffff /* -1.#SNAN0 */, 0 },
80+
{ 0xffC00000 /* -1.#IND00 */, 0 },
81+
{ 0xfff80001 /* -1.#QNAN0 */, 0 },
82+
{ 0xffffffff /* -1.#QNAN0 */, 0 },
83+
84+
/* Some random floats */
85+
{ 0x386580c7 /* 5.471779e-005 */, 1 },
86+
{ 0x47a3402b /* 8.358434e+004 */, 1 },
87+
{ 0xb74298e6 /* -1.159890e-005 */, 1 },
88+
{ 0x627fb9ed /* 1.179329e+021 */, 1 },
89+
{ 0x0ef25f06 /* 5.974911e-030 */, 1 },
90+
{ 0xe414aa2d /* -1.096952e+022 */, 1 },
91+
{ 0x24002a37 /* 2.779133e-017 */, 1 },
92+
{ 0x167638b5 /* 1.988962e-025 */, 1 },
93+
{ 0x44258d1b /* 6.622048e+002 */, 1 },
94+
{ 0xe62a0d22 /* -2.007611e+023 */, 1 },
95+
};
96+
97+
void Test__finitef(void)
98+
{
99+
int i;
100+
101+
for (i = 0; i < _countof(s_finitef_tests); i++)
102+
{
103+
float x = u32_to_flt(s_finitef_tests[i].x);
104+
int r = _finitef(x);
105+
ok(r == s_finitef_tests[i].result, "Wrong result for %f [0x%08lx]. Expected %d, got %d\n", x, s_finitef_tests[i].x, s_finitef_tests[i].result, r);
106+
}
107+
}
108+
#endif // !_MIX86
109+
110+
START_TEST(_finite)
111+
{
112+
Test__finite();
113+
#ifndef _M_IX86
114+
Test__finitef();
115+
#endif // !_MIX86
116+
}

modules/rostests/apitests/crt/math_helpers.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,18 @@ typedef struct _TESTENTRY_FLT
6363
unsigned long result;
6464
} TESTENTRY_FLT;
6565

66+
typedef struct _TESTENTRY_DBL_INT
67+
{
68+
unsigned long long x;
69+
int result;
70+
} TESTENTRY_DBL_INT;
71+
72+
typedef struct _TESTENTRY_FLT_INT
73+
{
74+
unsigned long x;
75+
int result;
76+
} TESTENTRY_FLT_INT;
77+
6678
typedef struct _PRECISE_VALUE
6779
{
6880
double rounded;

modules/rostests/apitests/msvcrt/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ endif()
88

99
list(APPEND SOURCE_CRT_TESTS
1010
../crt/fpcontrol.c
11+
../crt/_finite.c
1112
../crt/_mbsncmp.c
1213
../crt/_mbsstr.c
1314
../crt/_snprintf.c

modules/rostests/apitests/msvcrt/testlist.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#define STANDALONE
44
#include <apitest.h>
55

6+
extern void func__finite(void);
67
extern void func__mbsncmp(void);
78
extern void func__mbsstr(void);
89
extern void func__snprintf(void);
@@ -57,6 +58,7 @@ extern void func_splitpath(void);
5758

5859
const struct test winetest_testlist[] =
5960
{
61+
{ "_finite", func__finite },
6062
{ "_mbsncmp", func__mbsncmp },
6163
{ "_mbsstr", func__mbsstr },
6264
{ "_snprintf", func__snprintf },

modules/rostests/apitests/ucrtbase/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ add_definitions(
1111
)
1212

1313
list(APPEND SOURCE
14+
../crt/_finite.c
1415
../crt/acos.c
1516
../crt/asin.c
1617
../crt/atan.c

modules/rostests/apitests/ucrtbase/testlist.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#define STANDALONE
44
#include <wine/test.h>
55

6+
extern void func__finite(void);
67
extern void func_acos(void);
78
extern void func_asin(void);
89
extern void func_atan(void);
@@ -19,6 +20,7 @@ extern void func_tan(void);
1920

2021
const struct test winetest_testlist[] =
2122
{
23+
{ "_finite", func__finite },
2224
{ "acos", func_acos },
2325
{ "asin", func_asin },
2426
{ "atan", func_atan },

0 commit comments

Comments
 (0)