ReactOS 0.4.16-dev-1946-g52006dd
math_helpers.h File Reference
#include <math.h>
#include <float.h>
#include <stdint.h>
#include <apitest.h>
Include dependency graph for math_helpers.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _TESTENTRY_DBL
 
struct  _TESTENTRY_FLT
 
struct  _TESTENTRY_DBL_INT
 
struct  _TESTENTRY_FLT_INT
 
struct  _PRECISE_VALUE
 
struct  _TESTENTRY_DBL_APPROX
 

Macros

#define _USE_MATH_DEFINES
 
#define __ATTRIBUTE_SSE2__
 
#define ok_eq_dbl_exact_(file, line, func, ullx, z, ullexp)
 
#define ok_eq_dbl_exact(func, ullx, z, ullexp)   ok_eq_dbl_exact_(__FILE__, __LINE__, func, ullx, z, ullexp)
 
#define ok_eq_flt_exact_(file, line, func, ux, z, uexp)
 
#define ok_eq_flt_exact(func, ux, z, uexp)   ok_eq_flt_exact_(__FILE__, __LINE__, func, ux, z, uexp)
 

Typedefs

typedef struct _TESTENTRY_DBL TESTENTRY_DBL
 
typedef struct _TESTENTRY_FLT TESTENTRY_FLT
 
typedef struct _TESTENTRY_DBL_INT TESTENTRY_DBL_INT
 
typedef struct _TESTENTRY_FLT_INT TESTENTRY_FLT_INT
 
typedef struct _PRECISE_VALUE PRECISE_VALUE
 
typedef struct _TESTENTRY_DBL_APPROX TESTENTRY_DBL_APPROX
 

Functions

static __inline double u64_to_dbl (UINT64 x)
 
static __inline UINT64 dbl_to_u64 (double x)
 
static __inline float u32_to_flt (UINT32 x)
 
static __inline UINT32 flt_to_u32 (float x)
 
static int64_t double_to_int64_lex (double d)
 
static int float_to_int_lex (float f)
 
static __inline int64_t ulp_error_dbl (double expected, double result)
 
static __inline int ulp_error_flt (float expected, float result)
 
static __inline int64_t ulp_error_precise (PRECISE_VALUE *expected, double result)
 

Macro Definition Documentation

◆ __ATTRIBUTE_SSE2__

#define __ATTRIBUTE_SSE2__

Definition at line 19 of file math_helpers.h.

◆ _USE_MATH_DEFINES

#define _USE_MATH_DEFINES

Definition at line 10 of file math_helpers.h.

◆ ok_eq_dbl_exact

#define ok_eq_dbl_exact (   func,
  ullx,
  z,
  ullexp 
)    ok_eq_dbl_exact_(__FILE__, __LINE__, func, ullx, z, ullexp)

Definition at line 184 of file math_helpers.h.

◆ ok_eq_dbl_exact_

#define ok_eq_dbl_exact_ (   file,
  line,
  func,
  ullx,
  z,
  ullexp 
)
Value:
{ \
double x = u64_to_dbl(ullx); \
unsigned long long ullz = dbl_to_u64(z); \
double exp = u64_to_dbl(ullexp); \
ok_(file, line)(ullz == ullexp, "Wrong value for '%s(%f)' [0x%016I64x], expected: %f [0x%016I64x], got: %f [0x%016I64x]\n", \
func, x, ullx, exp, ullexp, z, ullz); \
}
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLenum func
Definition: glext.h:6028
GLdouble GLdouble z
Definition: glext.h:5874
static __inline double u64_to_dbl(UINT64 x)
Definition: math_helpers.h:25
static __inline UINT64 dbl_to_u64(double x)
Definition: math_helpers.h:33
DWORD exp
Definition: msg.c:16058
Definition: fci.c:127
Definition: parser.c:49

Definition at line 176 of file math_helpers.h.

◆ ok_eq_flt_exact

#define ok_eq_flt_exact (   func,
  ux,
  z,
  uexp 
)    ok_eq_flt_exact_(__FILE__, __LINE__, func, ux, z, uexp)

Definition at line 194 of file math_helpers.h.

◆ ok_eq_flt_exact_

#define ok_eq_flt_exact_ (   file,
  line,
  func,
  ux,
  z,
  uexp 
)
Value:
{ \
float x = u32_to_flt(ux); \
unsigned int uz = flt_to_u32(z); \
float exp = u32_to_flt(uexp); \
ok_(file, line)(uz == uexp, "Wrong value for '%s(%f)' [0x%08x], expected: %f [0x%08x], got: %f [0x%08x]\n", \
func, x, (unsigned)ux, exp, (unsigned)uexp, z, (unsigned)uz); \
}
static __inline float u32_to_flt(UINT32 x)
Definition: math_helpers.h:41
static __inline UINT32 flt_to_u32(float x)
Definition: math_helpers.h:49
static unsigned(__cdecl *hash_bstr)(bstr_t s)

Definition at line 186 of file math_helpers.h.

Typedef Documentation

◆ PRECISE_VALUE

◆ TESTENTRY_DBL

◆ TESTENTRY_DBL_APPROX

◆ TESTENTRY_DBL_INT

◆ TESTENTRY_FLT

◆ TESTENTRY_FLT_INT

Function Documentation

◆ dbl_to_u64()

static __inline UINT64 dbl_to_u64 ( double  x)
static

Definition at line 33 of file math_helpers.h.

34{
35 return *(UINT64*)(&x);
36}
unsigned long long UINT64

◆ double_to_int64_lex()

static int64_t double_to_int64_lex ( double  d)
inlinestatic

Definition at line 92 of file math_helpers.h.

93{
94 union {
95 double d;
96 int64_t i;
97 } u;
98 u.d = d;
99 // For negative numbers, flip the ordering.
100 if (u.i < 0)
101 u.i = 0x8000000000000000LL - u.i;
102 return u.i;
103}
INT64 int64_t
Definition: types.h:72
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
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 * u
Definition: glfuncs.h:240
#define d
Definition: ke_i.h:81

Referenced by ulp_error_dbl().

◆ float_to_int_lex()

static int float_to_int_lex ( float  f)
inlinestatic

Definition at line 106 of file math_helpers.h.

107{
108 union {
109 float f;
110 int i;
111 } u;
112 u.f = f;
113 // For negative numbers, flip the ordering.
114 if (u.i < 0)
115 u.i = 0x80000000 - u.i;
116 return u.i;
117}
#define f
Definition: ke_i.h:83

Referenced by ulp_error_flt().

◆ flt_to_u32()

static __inline UINT32 flt_to_u32 ( float  x)
static

Definition at line 49 of file math_helpers.h.

50{
51 return *(UINT32*)(&x);
52}
unsigned int UINT32

◆ u32_to_flt()

static __inline float u32_to_flt ( UINT32  x)
static

Definition at line 41 of file math_helpers.h.

42{
43 return *(float*)(&x);
44}

Referenced by Test__finitef(), Test__isnanf(), Test_ceilf(), Test_fabsf(), Test_floorf(), and Test_roundf().

◆ u64_to_dbl()

◆ ulp_error_dbl()

static __inline int64_t ulp_error_dbl ( double  expected,
double  result 
)
static

Definition at line 122 of file math_helpers.h.

123{
124 // Exact equality: error is 0 ULPs.
125 if (expected == result)
126 return 0;
127
128 // If either value is not a number, return a sentinel.
129 if (_isnan(expected) || _isnan(result))
130 return INT64_MAX;
131
134
135 return i_result - i_expected;
136}
GLuint64EXT * result
Definition: glext.h:11304
_Check_return_ __MINGW_NOTHROW _CRTIMP int __cdecl _isnan(_In_ double)
Definition: _isnan.c:13
i_result
Definition: intersect.cc:51
#define INT64_MAX
Definition: intsafe.h:159
static int64_t double_to_int64_lex(double d)
Definition: math_helpers.h:92
BOOL expected
Definition: store.c:2000

Referenced by ulp_error_precise().

◆ ulp_error_flt()

static __inline int ulp_error_flt ( float  expected,
float  result 
)
static

Definition at line 138 of file math_helpers.h.

139{
140 // Exact equality: error is 0 ULPs.
141 if (expected == result)
142 return 0;
143
144 // If either value is not a number, return a sentinel.
145 if (_isnan(expected) || _isnan(result))
146 return INT_MAX;
147
148 int i_expected = float_to_int_lex(expected);
150
151 return i_result - i_expected;
152}
#define INT_MAX
Definition: intsafe.h:150
static int float_to_int_lex(float f)
Definition: math_helpers.h:106

Referenced by Test_acosf_approx(), Test_asinf_approx(), Test_atanf_approx(), Test_cosf_approx(), Test_expf_approx(), Test_log10f_approx(), Test_logf_approx(), Test_sinf_approx(), Test_sqrtf_approx(), and Test_tanf_approx().

◆ ulp_error_precise()

static __inline int64_t ulp_error_precise ( PRECISE_VALUE expected,
double  result 
)
static

Definition at line 154 of file math_helpers.h.

155{
156 // Calculate error to expected rouned value as ULP
158 if ((error == INT64_MAX) || (error == 0))
159 return error;
160
161 // Check if the error has the same sign as the delta
162 if ((expected->delta >= 0.0) == (error >= 0))
163 {
164 // We have an error in the same direction as the delta.
165 // This means the error is correct as it is.
166 return error;
167 }
168 else
169 {
170 // We have an error in the opposite direction of the delta.
171 // This means the actual error is larger than the calculated error.
172 return (error < 0) ? error - 1 : error + 1;
173 }
174}
static __inline int64_t ulp_error_dbl(double expected, double result)
Definition: math_helpers.h:122
#define error(str)
Definition: mkdosfs.c:1605

Referenced by Test_acos_approx(), Test_asin_approx(), Test_atan_approx(), Test_cos_approx(), Test_exp_approx(), Test_log10_approx(), Test_log_approx(), Test_sin_approx(), Test_sqrt_approx(), and Test_tan_approx().