[PATCH 0/1] MR247: tests: Cast abs() result to unsigned int in compare_float().
From: Zebediah Figura <zfigura(a)codeweavers.com> --- tests/utils.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/utils.h b/tests/utils.h index 5fd7b086e..a74275e3a 100644 --- a/tests/utils.h +++ b/tests/utils.h @@ -101,7 +101,8 @@ static bool compare_float(float f, float g, unsigned int ulps) if (y < 0) y = INT_MIN - y; - if (abs(x - y) > ulps) + /* Cast to unsigned int in case x - y == INT_MIN. */ + if ((unsigned int)abs(x - y) > ulps) return false; return true; -- GitLab https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/247
I'm not sure if this is the best solution to this, maybe there's something cleverer, but this at least stops the function from treating -1.0 and 4.0 as equal. -- https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/247#note_36678
On Sun Jun 25 06:07:44 2023 +0000, Zebediah Figura wrote:
I'm not sure if this is the best solution to this, maybe there's something cleverer, but this at least stops the function from treating -1.0 and 4.0 as equal. I thought I wrote an `absdiff()` function for this exact scenario...
Oh yeah, it's in the d3d9 tests. It's not terribly clever. All it does is make sure the greater of the two operands is the minuend: ```c static inline unsigned int absdiff(unsigned int x, unsigned int y) { return x > y ? x - y : y - x; } ``` ~~See `wine/dlls/d3d9/tests/visual.c:66`.~~ EDIT: Wait, that one didn't go in yet. I could've sworn I had one like that in... -- https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/247#note_36718
This merge request was approved by Giovanni Mascellani. -- https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/247
I thought I wrote an `absdiff()` function for this exact scenario...
Oh yeah, it's in the d3d9 tests. It's not terribly clever. All it does is make sure the greater of the two operands is the minuend:
```c static inline unsigned int absdiff(unsigned int x, unsigned int y) { return x > y ? x - y : y - x; } ```
~~See~~ `wine/dlls/d3d9/tests/visual.c:66`. EDIT: Wait, that one didn't go in yet. I could've sworn I had one like that in...
Well, we have compare_uint() in the various Wine D3D tests. So does vkd3d, and we could probably use "return compare_uint(x, y, ulps);" here. -- https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/247#note_36793
participants (5)
-
Chip Davis (@cdavis5e) -
Giovanni Mascellani (@giomasce) -
Henri Verbeet (@hverbeet) -
Zebediah Figura -
Zebediah Figura (@zfigura)