json: improve infinite checks

Avoid compiler errors like this:

/usr/include/spa-0.2/spa/utils/json.h:417:25: error: comparing floating-point with '==' or '!=' is unsafe [-Werror=float-equal]
|   417 |                 if (val == INFINITY)
|       |                         ^~
This commit is contained in:
Wim Taymans 2024-11-06 10:52:05 +01:00
parent 41b5c50c86
commit cdb3c64753

View file

@ -457,10 +457,8 @@ static inline int spa_json_get_float(struct spa_json *iter, float *res)
static inline char *spa_json_format_float(char *str, int size, float val)
{
if (SPA_UNLIKELY(!isnormal(val))) {
if (val == INFINITY)
val = FLT_MAX;
else if (val == -INFINITY)
val = FLT_MIN;
if (isinf(val))
val = signbit(val) ? FLT_MIN : FLT_MAX;
else
val = 0.0f;
}