ReactOS 0.4.16-dev-1643-gf0ba726
round.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS API tests
3 * LICENSE: MIT (https://spdx.org/licenses/MIT)
4 * PURPOSE: Tests for round / roundf
5 * COPYRIGHT: Copyright 2021 Timo Kreuzer <timo.kreuzer@reactos.org>
6 */
7
8#if !defined(_CRTBLD) && !defined(_M_IX86)
9#define _CRTBLD // we don't want inline roundf!
10#endif
11#include "math_helpers.h"
12
14{
15 /* Special values */
16 { 0x0000000000000000 /* 0.000000000000000e+000 */, 0x0000000000000000 /* 0.000000000000000e+000 */ },
17 { 0x0000000000000001 /* 0.000000000000000e+000 */, 0x0000000000000000 /* 0.000000000000000e+000 */ },
18 { 0x000fffffffffffff /* 0.000000000000000e+000 */, 0x0000000000000000 /* 0.000000000000000e+000 */ },
19 { 0x8000000000000000 /* -0.000000000000000e+000 */, 0x8000000000000000 /* -0.000000000000000e+000 */ },
20 { 0x8000000000000001 /* -0.000000000000000e+000 */, 0x8000000000000000 /* -0.000000000000000e+000 */ },
21 { 0x800fffffffffffff /* -0.000000000000000e+000 */, 0x8000000000000000 /* -0.000000000000000e+000 */ },
22 { 0x7ff0000000000000 /* 1.#INF00000000000e+000 */, 0x7ff0000000000000 /* 1.#INF00000000000e+000 */ },
23#ifdef _M_IX86
24 { 0x7ff0000000000001 /* 1.#QNAN0000000000e+000 */, 0x7ff8000000000001 /* 1.#QNAN0000000000e+000 */ },
25 { 0x7ff7ffffffffffff /* 1.#QNAN0000000000e+000 */, 0x7fffffffffffffff /* 1.#QNAN0000000000e+000 */ },
26#else
27 { 0x7ff0000000000001 /* 1.#QNAN0000000000e+000 */, 0x7ff0000000000001 /* 1.#SNAN0000000000e+000 */ },
28 { 0x7ff7ffffffffffff /* 1.#QNAN0000000000e+000 */, 0x7ff7ffffffffffff /* 1.#SNAN0000000000e+000 */ },
29#endif
30 { 0x7ff8000000000000 /* 1.#QNAN0000000000e+000 */, 0x7ff8000000000000 /* 1.#QNAN0000000000e+000 */ },
31 { 0x7ff8000000000001 /* 1.#QNAN0000000000e+000 */, 0x7ff8000000000001 /* 1.#QNAN0000000000e+000 */ },
32 { 0x7fffffffffffffff /* 1.#QNAN0000000000e+000 */, 0x7fffffffffffffff /* 1.#QNAN0000000000e+000 */ },
33 { 0xfff0000000000000 /* -1.#INF00000000000e+000 */, 0xfff0000000000000 /* -1.#INF00000000000e+000 */ },
34#ifdef _M_IX86
35 { 0xfff0000000000001 /* -1.#QNAN0000000000e+000 */, 0xfff8000000000001 /* -1.#QNAN0000000000e+000 */ },
36 { 0xfff7ffffffffffff /* -1.#QNAN0000000000e+000 */, 0xffffffffffffffff /* -1.#QNAN0000000000e+000 */ },
37#else
38 { 0xfff0000000000001 /* -1.#QNAN0000000000e+000 */, 0xfff0000000000001 /* -1.#SNAN0000000000e+000 */ },
39 { 0xfff7ffffffffffff /* -1.#QNAN0000000000e+000 */, 0xfff7ffffffffffff /* -1.#SNAN0000000000e+000 */ },
40#endif
41 { 0xfff8000000000000 /* -1.#IND00000000000e+000 */, 0xfff8000000000000 /* -1.#IND00000000000e+000 */ },
42 { 0xfff8000000000001 /* -1.#QNAN0000000000e+000 */, 0xfff8000000000001 /* -1.#QNAN0000000000e+000 */ },
43 { 0xffffffffffffffff /* -1.#QNAN0000000000e+000 */, 0xffffffffffffffff /* -1.#QNAN0000000000e+000 */ },
44
45 /* Some random doubles */
46 { 0x386580c747a3402b /* 5.055340589883462e-037 */, 0x0000000000000000 /* 0.000000000000000e+000 */ },
47 { 0xb74298e6627fb9ed /* -1.667860443847725e-042 */, 0x8000000000000000 /* -0.000000000000000e+000 */ },
48 { 0x0ef25f06e414aa2d /* 1.128498317470960e-236 */, 0x0000000000000000 /* 0.000000000000000e+000 */ },
49 { 0x24002a37167638b5 /* 2.780001692929186e-135 */, 0x0000000000000000 /* 0.000000000000000e+000 */ },
50 { 0x44258d1be62a0d22 /* 1.987747995999515e+020 */, 0x44258d1be62a0d22 /* 1.987747995999515e+020 */ },
51 { 0x9ed4e46a65aad464 /* -3.715074250469020e-160 */, 0x8000000000000000 /* -0.000000000000000e+000 */ },
52 { 0xc5afcd6f4ae4bf41 /* -4.921195330852160e+027 */, 0xc5afcd6f4ae4bf41 /* -4.921195330852160e+027 */ },
53 { 0x330fac896cbb01d2 /* 9.624395081137827e-063 */, 0x0000000000000000 /* 0.000000000000000e+000 */ },
54 { 0xc18026ab4c845405 /* -3.387120956461338e+007 */, 0xc18026ab50000000 /* -3.387121000000000e+007 */ },
55 { 0x2f42a7dc898a741a /* 4.916804395045249e-081 */, 0x0000000000000000 /* 0.000000000000000e+000 */ },
56};
57
58
59void Test_round(void)
60{
61 int i;
62
63 for (i = 0; i < _countof(s_round_tests); i++)
64 {
65 double x = u64_to_dbl(s_round_tests[i].x);
66 double z = round(x);
68 }
69}
70
72{
73 /* Special values */
74 { 0x00000000 /* 0.000000 */, 0x00000000 /* 0.000000 */ },
75 { 0x00000001 /* 0.000000 */, 0x00000000 /* 0.000000 */ },
76 { 0x007FFFFF /* 0.000000 */, 0x00000000 /* 0.000000 */ },
77 { 0x80000000 /* -0.000000 */, 0x80000000 /* -0.000000 */ },
78 { 0x80000001 /* -0.000000 */, 0x80000000 /* -0.000000 */ },
79 { 0x807FFFFF /* -0.000000 */, 0x80000000 /* -0.000000 */ },
80 { 0x7f800000 /* 1.#INF00 */, 0x7f800000 /* 1.#INF00 */ },
81#ifdef _M_IX86
82 { 0x7f800001 /* 1.#SNAN0 */, 0x7fc00001 /* 1.#QNAN0 */ },
83 { 0x7fBFffff /* 1.#SNAN0 */, 0x7fffffff /* 1.#QNAN0 */ },
84#else
85 { 0x7f800001 /* 1.#SNAN0 */, 0x7f800001 /* 1.#SNAN0 */ },
86 { 0x7fBFffff /* 1.#SNAN0 */, 0x7fbfffff /* 1.#SNAN0 */ },
87#endif
88 { 0x7fC00000 /* 1.#QNAN0 */, 0x7fc00000 /* 1.#QNAN0 */ },
89 { 0x7fC80001 /* 1.#QNAN0 */, 0x7fc80001 /* 1.#QNAN0 */ },
90 { 0x7fFfffff /* 1.#QNAN0 */, 0x7fffffff /* 1.#QNAN0 */ },
91 { 0xff800000 /* -1.#INF00 */, 0xff800000 /* -1.#INF00 */ },
92#ifdef _M_IX86
93 { 0xff800001 /* -1.#SNAN0 */, 0xffc00001 /* -1.#QNAN0 */ },
94 { 0xffBfffff /* -1.#SNAN0 */, 0xffffffff /* -1.#QNAN0 */ },
95#else
96 { 0xff800001 /* -1.#SNAN0 */, 0xff800001 /* -1.#SNAN0 */ },
97 { 0xffBfffff /* -1.#SNAN0 */, 0xffbfffff /* -1.#SNAN0 */ },
98#endif
99 { 0xffC00000 /* -1.#IND00 */, 0xffc00000 /* -1.#IND00 */ },
100 { 0xfff80001 /* -1.#QNAN0 */, 0xfff80001 /* -1.#QNAN0 */ },
101 { 0xffffffff /* -1.#QNAN0 */, 0xffffffff /* -1.#QNAN0 */ },
102
103 /* Some random floats */
104 { 0x386580c7 /* 5.471779e-005 */, 0x00000000 /* 0.000000e+000 */ },
105 { 0x47a3402b /* 8.358434e+004 */, 0x47a34000 /* 8.358400e+004 */ },
106 { 0xb74298e6 /* -1.159890e-005 */, 0x80000000 /* -0.000000e+000 */ },
107 { 0x627fb9ed /* 1.179329e+021 */, 0x627fb9ed /* 1.179329e+021 */ },
108 { 0x0ef25f06 /* 5.974911e-030 */, 0x00000000 /* 0.000000e+000 */ },
109 { 0xe414aa2d /* -1.096952e+022 */, 0xe414aa2d /* -1.096952e+022 */ },
110 { 0x24002a37 /* 2.779133e-017 */, 0x00000000 /* 0.000000e+000 */ },
111 { 0x167638b5 /* 1.988962e-025 */, 0x00000000 /* 0.000000e+000 */ },
112 { 0x44258d1b /* 6.622048e+002 */, 0x44258000 /* 6.620000e+002 */ },
113 { 0xe62a0d22 /* -2.007611e+023 */, 0xe62a0d22 /* -2.007611e+023 */ },
114};
115
116void Test_roundf(void)
117{
118 int i;
119
120 for (i = 0; i < _countof(s_roundf_tests); i++)
121 {
122 float x = u32_to_flt(s_roundf_tests[i].x);
123 float z = roundf(x);
125 }
126}
127
129{
130 Test_round();
131 Test_roundf();
132}
#define START_TEST(x)
Definition: atltest.h:75
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLuint64EXT * result
Definition: glext.h:11304
GLdouble GLdouble z
Definition: glext.h:5874
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
_Check_return_ __CRT_INLINE float roundf(_In_ float x)
Definition: math.h:295
#define ok_eq_dbl_exact(func, ullx, z, ullexp)
Definition: math_helpers.h:184
static __inline double u64_to_dbl(UINT64 x)
Definition: math_helpers.h:25
static __inline float u32_to_flt(UINT32 x)
Definition: math_helpers.h:41
#define ok_eq_flt_exact(func, ux, z, uexp)
Definition: math_helpers.h:194
void Test_roundf(void)
Definition: round.c:116
static TESTENTRY_FLT s_roundf_tests[]
Definition: round.c:71
void Test_round(void)
Definition: round.c:59
static TESTENTRY_DBL s_round_tests[]
Definition: round.c:13
#define round(x)
Definition: opentype.c:47
#define _countof(array)
Definition: sndvol32.h:70