1 /*
2 * PROJECT: ReactOS api tests
3 * LICENSE: MIT (https://spdx.org/licenses/MIT)
4 * PURPOSE: Helpers for testing math functions
5 * COPYRIGHT: Copyright 2021 Timo Kreuzer <timo.kreuzer@reactos.org>
6 */
7
8 #pragma once
9
10 #define _USE_MATH_DEFINES
11 #include <math.h>
12 #include <float.h>
13 #include <apitest.h>
14
15 static
16 __inline
17 double
u64_to_dbl(UINT64 x)18 u64_to_dbl(UINT64 x)
19 {
20 return *(double*)(&x);
21 }
22
23 static
24 __inline
25 UINT64
dbl_to_u64(double x)26 dbl_to_u64(double x)
27 {
28 return *(UINT64*)(&x);
29 }
30
31 static
32 __inline
33 float
u32_to_flt(UINT32 x)34 u32_to_flt(UINT32 x)
35 {
36 return *(float*)(&x);
37 }
38
39 static
40 __inline
41 UINT32
flt_to_u32(float x)42 flt_to_u32(float x)
43 {
44 return *(UINT32*)(&x);
45 }
46
47 typedef struct _TESTENTRY_DBL
48 {
49 unsigned long long x;
50 unsigned long long result;
51 } TESTENTRY_DBL;
52
53 typedef struct _TESTENTRY_FLT
54 {
55 unsigned long x;
56 unsigned long result;
57 } TESTENTRY_FLT;
58
59 #define ok_eq_dbl_exact_(file, line, func, ullx, z, ullexp) \
60 { \
61 double x = u64_to_dbl(ullx); \
62 unsigned long long ullz = dbl_to_u64(z); \
63 double exp = u64_to_dbl(ullexp); \
64 ok_(file, line)(ullz == ullexp, "Wrong value for '%s(%f)' [0x%016llx], expected: %f [0x%016llx], got: %f [0x%016llx]\n", \
65 func, x, ullx, exp, ullexp, z, ullz); \
66 }
67 #define ok_eq_dbl_exact(func, ullx, z, ullexp) ok_eq_dbl_exact_(__FILE__, __LINE__, func, ullx, z, ullexp)
68
69 #define ok_eq_flt_exact_(file, line, func, ux, z, uexp) \
70 { \
71 float x = u32_to_flt(ux); \
72 unsigned int uz = flt_to_u32(z); \
73 float exp = u32_to_flt(uexp); \
74 ok_(file, line)(uz == uexp, "Wrong value for '%s(%f)' [0x%08x], expected: %f [0x%08x], got: %f [0x%08x]\n", \
75 func, x, ux, exp, uexp, z, uz); \
76 }
77 #define ok_eq_flt_exact(func, ux, z, uexp) ok_eq_flt_exact_(__FILE__, __LINE__, func, ux, z, uexp)
78