ReactOS 0.4.15-dev-8236-g99f0937
math_helpers.h
Go to the documentation of this file.
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
15static
16__inline
17double
19{
20 return *(double*)(&x);
21}
22
23static
24__inline
27{
28 return *(UINT64*)(&x);
29}
30
31static
32__inline
33float
35{
36 return *(float*)(&x);
37}
38
39static
40__inline
43{
44 return *(UINT32*)(&x);
45}
46
47typedef struct _TESTENTRY_DBL
48{
49 unsigned long long x;
50 unsigned long long result;
52
53typedef struct _TESTENTRY_FLT
54{
55 unsigned long x;
56 unsigned long result;
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)
unsigned long long UINT64
unsigned int UINT32
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
static __inline double u64_to_dbl(UINT64 x)
Definition: math_helpers.h:18
struct _TESTENTRY_DBL TESTENTRY_DBL
static __inline UINT64 dbl_to_u64(double x)
Definition: math_helpers.h:26
struct _TESTENTRY_FLT TESTENTRY_FLT
static __inline float u32_to_flt(UINT32 x)
Definition: math_helpers.h:34
static __inline UINT32 flt_to_u32(float x)
Definition: math_helpers.h:42
unsigned long long x
Definition: math_helpers.h:49
unsigned long long result
Definition: math_helpers.h:50
unsigned long x
Definition: math_helpers.h:55
unsigned long result
Definition: math_helpers.h:56