From 2f9a21423a1ef666c93f15e2068bcde979d20f7e Mon Sep 17 00:00:00 2001 From: Marko Viitanen Date: Wed, 14 Aug 2024 12:47:57 +0300 Subject: [PATCH] Add an offset to double comparison in mv_cost to fix problems on some platforms --- src/search_inter.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/search_inter.c b/src/search_inter.c index 9e624532..f8f876a3 100644 --- a/src/search_inter.c +++ b/src/search_inter.c @@ -220,8 +220,9 @@ static bool check_mv_cost(inter_search_info_t *info, info->height, info->optimized_sad ); - - if (cost >= *best_cost) return false; + // On some platforms comparing two doubles give weird results, so add an offset +#define KVZ_TEMP_DOUBLE_PRECISION 0.001 + if (cost + KVZ_TEMP_DOUBLE_PRECISION >= *best_cost) return false; cost += info->mvd_cost_func( info->state, @@ -233,7 +234,8 @@ static bool check_mv_cost(inter_search_info_t *info, &bitcost ); - if (cost >= *best_cost) return false; + if (cost + KVZ_TEMP_DOUBLE_PRECISION >= *best_cost) return false; +#undef KVZ_TEMP_DOUBLE_PRECISION // Set to motion vector in quarter pixel precision. best_mv->x = x * 4;