Skip to content

Commit

Permalink
d3drm/tests: Use compare_uint() in compare_float() instead of abs().
Browse files Browse the repository at this point in the history
The result of abs(INT_MIN) is INT_MIN, which breaks the ulps comparison.
  • Loading branch information
whydoubt authored and julliard committed Aug 10, 2023
1 parent a6d828b commit 468ace0
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions dlls/d3drm/tests/d3drm.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ static ULONG get_refcount(IUnknown *object)
return IUnknown_Release( object );
}

static BOOL compare_uint(unsigned int x, unsigned int y, unsigned int max_diff)
{
unsigned int diff = x > y ? x - y : y - x;

return diff <= max_diff;
}

static BOOL compare_float(float f, float g, unsigned int ulps)
{
int x = *(int *)&f;
Expand All @@ -54,10 +61,7 @@ static BOOL compare_float(float f, float g, unsigned int ulps)
if (y < 0)
y = INT_MIN - y;

if (abs(x - y) > ulps)
return FALSE;

return TRUE;
return compare_uint(x, y, ulps);
}

#define expect_matrix(m, m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, m41, m42, m43, m44, u) \
Expand Down Expand Up @@ -103,13 +107,6 @@ static void vector_eq_(unsigned int line, const D3DVECTOR *left, const D3DVECTOR
expect_vector_(line, left, U1(*right).x, U2(*right).y, U3(*right).z, 0);
}

static BOOL compare_uint(unsigned int x, unsigned int y, unsigned int max_diff)
{
unsigned int diff = x > y ? x - y : y - x;

return diff <= max_diff;
}

static BOOL compare_color(D3DCOLOR c1, D3DCOLOR c2, BYTE max_diff)
{
return compare_uint(c1 & 0xff, c2 & 0xff, max_diff)
Expand Down

0 comments on commit 468ace0

Please sign in to comment.