ReactOS 0.4.15-dev-8191-gbc6c731
fabs.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 fabs / fabsf
5 * COPYRIGHT: Copyright 2021 Timo Kreuzer <timo.kreuzer@reactos.org>
6 */
7
8/* Don't use the inline fabsf, unless required */
9#if !defined(_CRTBLD) && defined(_M_ARM)
10#define _CRTBLD
11#endif
12#include "math_helpers.h"
13
14#ifdef _MSC_VER
15#pragma function(fabs)
16// fabsf is not available as an intrinsic
17#endif
18
20{
21 /* Special values */
22 { 0x7FF0000000000000ull /* INF */, 0x7FF0000000000000ull /* INF */ },
23#ifndef _M_IX86
24 { 0x7FF0000000000001ull /* NAN(SNAN) */, 0x7FF0000000000001ull /* NAN(SNAN) */ },
25 { 0x7FF7FFFFFFFFFFFFull /* NAN(SNAN) */, 0x7FF7FFFFFFFFFFFFull /* NAN(SNAN) */ },
26#else
27 { 0x7FF0000000000001ull /* NAN(SNAN) */, 0x7FF8000000000001ull /* NAN */ },
28 { 0x7FF7FFFFFFFFFFFFull /* NAN(SNAN) */, 0x7FFFFFFFFFFFFFFFull /* NAN */ },
29#endif
30 { 0x7FF8000000000000ull /* NAN */, 0x7FF8000000000000ull /* NAN */ },
31 { 0x7FF8000000000001ull /* NAN */, 0x7FF8000000000001ull /* NAN */ },
32 { 0x7FFFFFFFFFFFFFFFull /* NAN */, 0x7FFFFFFFFFFFFFFFull /* NAN */ },
33 { 0xFFF0000000000000ull /* -INF */, 0x7FF0000000000000ull /* INF */ },
34#ifndef _M_IX86
35 { 0xFFF0000000000001ull /* -NAN(SNAN) */, 0xFFF0000000000001ull /* NAN(SNAN) */ },
36 { 0xFFF7FFFFFFFFFFFFull /* -NAN(SNAN) */, 0xFFF7FFFFFFFFFFFFull /* NAN(SNAN) */ },
37#else
38 { 0xFFF0000000000001ull /* -NAN(SNAN) */, 0xFFF8000000000001ull /* -NAN */ },
39 { 0xFFF7FFFFFFFFFFFFull /* -NAN(SNAN) */, 0xFFFFFFFFFFFFFFFFull /* -NAN */ },
40#endif
41 { 0xFFF8000000000000ull /* -NAN(IND) */, 0xFFF8000000000000ull /* -NAN(IND) */ },
42 { 0xFFF8000000000001ull /* -NAN */, 0xFFF8000000000001ull /* -NAN */ },
43 { 0xFFFFFFFFFFFFFFFFull /* -NAN */, 0xFFFFFFFFFFFFFFFFull /* -NAN */ },
44
45 /* Some random floats */
46 { 0x0000000000000000 /* 0.000000000000000e+000 */, 0x0000000000000000 /* 0.000000000000000e+000 */ },
47 { 0x8000000000000000 /* -0.000000000000000e+000 */, 0x0000000000000000 /* 0.000000000000000e+000 */ },
48 { 0x0123456789abcdef /* 3.512700564088504e-303 */, 0x0123456789abcdef /* 3.512700564088504e-303 */ },
49 { 0x8123456789abcdef /* -3.512700564088504e-303 */, 0x0123456789abcdef /* 3.512700564088504e-303 */ },
50 { 0x472ad8b31f506c9e /* 6.969745516432332e+034 */, 0x472ad8b31f506c9e /* 6.969745516432332e+034 */ },
51 { 0xc72ad8b31f506c9e /* -6.969745516432332e+034 */, 0x472ad8b31f506c9e /* 6.969745516432332e+034 */ },
52 { 0x1d289e506fa47cb3 /* 3.261613668384938e-168 */, 0x1d289e506fa47cb3 /* 3.261613668384938e-168 */ },
53 { 0x9d289e506fa47cb3 /* -3.261613668384938e-168 */, 0x1d289e506fa47cb3 /* 3.261613668384938e-168 */ },
54};
55
56
57void Test_fabs(void)
58{
59 int i;
60
61 for (i = 0; i < _countof(s_fabs_tests); i++)
62 {
63 double x = u64_to_dbl(s_fabs_tests[i].x);
64 double z = fabs(x);
66 }
67}
68
70{
71 /* Special values */
72 { 0x7F800000 /* INF */, 0x7F800000 /* INF */ },
73 { 0x7F800001 /* NAN(SNAN) */, 0x7FC00001 /* NAN */ },
74 { 0x7FBFFFFF /* NAN(SNAN) */, 0x7FFFFFFF /* NAN */ },
75 { 0x7FC00000 /* NAN */, 0x7FC00000 /* NAN */ },
76 { 0x7FC00001 /* NAN */, 0x7FC00001 /* NAN */ },
77 { 0x7FCFFFFF /* NAN */, 0x7FCFFFFF /* NAN */ },
78 { 0xFF800000 /* -INF */, 0x7F800000 /* INF */ },
79 { 0xFF800001 /* -NAN(SNAN) */, 0xFFC00001 /* -NAN */ },
80 { 0xFFBFFFFF /* -NAN(SNAN) */, 0xFFFFFFFF /* -NAN */ },
81 { 0xFFC00000 /* -NAN(IND) */, 0xFFC00000 /* -NAN */ },
82 { 0xFFC00001 /* -NAN */, 0xFFC00001 /* -NAN */ },
83 { 0xFFCFFFFF /* -NAN */, 0xFFCFFFFF /* -NAN */ },
84
85 /* Some random floats */
86 { 0x00000000 /* 0.000000e+000 */, 0x00000000 /* 0.000000e+000 */ },
87 { 0x80000000 /* -0.000000e+000 */, 0x00000000 /* 0.000000e+000 */ },
88 { 0x01234567 /* 2.998817e-038 */, 0x01234567 /* 2.998817e-038 */ },
89 { 0x81234567 /* -2.998817e-038 */, 0x01234567 /* 2.998817e-038 */ },
90 { 0x472ad8b3 /* 4.373670e+004 */, 0x472ad8b3 /* 4.373670e+004 */ },
91 { 0xc72ad8b3 /* -4.373670e+004 */, 0x472ad8b3 /* 4.373670e+004 */ },
92 { 0x1d289e50 /* 2.231646e-021 */, 0x1d289e50 /* 2.231646e-021 */ },
93 { 0x9d289e50 /* -2.231646e-021 */, 0x1d289e50 /* 2.231646e-021 */ },
94};
95
96void Test_fabsf(void)
97{
98 int i;
99
100 for (i = 0; i < _countof(s_fabsf_tests); i++)
101 {
102 float x = u32_to_flt(s_fabsf_tests[i].x);
103 float z = fabsf(x);
105 }
106}
107
109{
110 Test_fabs();
111 Test_fabsf();
112}
#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 __CRTDECL fabsf(_In_ float x)
Definition: math.h:179
_Check_return_ _CRT_JIT_INTRINSIC double __cdecl fabs(_In_ double x)
Definition: fabs.c:17
#define ok_eq_dbl_exact(func, ullx, z, ullexp)
Definition: math_helpers.h:67
static __inline double u64_to_dbl(UINT64 x)
Definition: math_helpers.h:18
static __inline float u32_to_flt(UINT32 x)
Definition: math_helpers.h:34
#define ok_eq_flt_exact(func, ux, z, uexp)
Definition: math_helpers.h:77
static TESTENTRY_FLT s_fabsf_tests[]
Definition: fabs.c:69
static TESTENTRY_DBL s_fabs_tests[]
Definition: fabs.c:19
void Test_fabs(void)
Definition: fabs.c:57
void Test_fabsf(void)
Definition: fabs.c:96
#define _countof(array)
Definition: sndvol32.h:70