From 40351057ff80430b337ca47bbe44528765989f62 Mon Sep 17 00:00:00 2001 From: Alain BKR Date: Mon, 1 May 2023 14:49:11 +0200 Subject: [PATCH] relaxed ADV_WANTS_EQ : relative comparison --- common/fc_types.h | 2 -- server/advisors/advtools.h | 4 +++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/common/fc_types.h b/common/fc_types.h index aabf947b7..ffc829bf5 100644 --- a/common/fc_types.h +++ b/common/fc_types.h @@ -1207,8 +1207,6 @@ enum spaceship_place_type { #define SPECENUM_COUNT V_COUNT #include "specenum_gen.h" -#define FC_EPSILON (0.000001) - typedef float adv_want; #define ADV_WANT_PRINTF "%f" diff --git a/server/advisors/advtools.h b/server/advisors/advtools.h index b357fbbe6..4c741a104 100644 --- a/server/advisors/advtools.h +++ b/server/advisors/advtools.h @@ -18,7 +18,9 @@ #define MORT 24 -#define ADV_WANTS_EQ(_w1, _w2) (fabs((_w1) - (_w2)) < FC_EPSILON) +/* relative comparison for equality of floats */ +#define FC_EPSILON (0.001) +#define ADV_WANTS_EQ(_w1, _w2) (fabs((_w1) - (_w2)) < FC_EPSILON * (fabs((float) (_w1)) + fabs((float) (_w2)))) adv_want amortize(adv_want benefit, int delay); -- 2.34.1