From 69ecfdfb0bf9e5fddc3b74732f7db94e4948f24e Mon Sep 17 00:00:00 2001 From: Zebediah Figura Date: Fri, 23 Jun 2023 15:36:26 -0500 Subject: [PATCH] tests: Use compare_uint() in compare_float(). Comparing the result of abs() is broken in the case that x - y == INT_MIN. --- tests/d3d12_test_utils.h | 7 ------- tests/utils.h | 12 ++++++++---- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/tests/d3d12_test_utils.h b/tests/d3d12_test_utils.h index 19105e19..ec5ba5c5 100644 --- a/tests/d3d12_test_utils.h +++ b/tests/d3d12_test_utils.h @@ -74,13 +74,6 @@ static void set_viewport(D3D12_VIEWPORT *vp, float x, float y, vp->MaxDepth = max_depth; } -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(DWORD c1, DWORD c2, BYTE max_diff) { return compare_uint(c1 & 0xff, c2 & 0xff, max_diff) diff --git a/tests/utils.h b/tests/utils.h index 5fd7b086..67094190 100644 --- a/tests/utils.h +++ b/tests/utils.h @@ -82,6 +82,13 @@ static inline bool vkd3d_array_reserve(void **elements, size_t *capacity, size_t return true; } +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, y; @@ -101,10 +108,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 inline bool compare_uvec4(const struct uvec4 *v1, const struct uvec4 *v2)