Skip to content

Commit

Permalink
d3d10core/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 22fcf28 commit 162a8e1
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions dlls/d3d10core/tests/d3d10core.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,13 @@ static HRESULT check_interface_(unsigned int line, void *iface, REFIID riid, BOO
return hr;
}

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 @@ -192,10 +199,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);
}

static BOOL compare_vec4(const struct vec4 *v1, const struct vec4 *v2, unsigned int ulps)
Expand All @@ -206,13 +210,6 @@ static BOOL compare_vec4(const struct vec4 *v1, const struct vec4 *v2, unsigned
&& compare_float(v1->w, v2->w, ulps);
}

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_uvec4(const struct uvec4* v1, const struct uvec4 *v2)
{
return v1->x == v2->x && v1->y == v2->y && v1->z == v2->z && v1->w == v2->w;
Expand Down

0 comments on commit 162a8e1

Please sign in to comment.