json: improve infinite checks

Avoid compiler errors like this:

 /usr/include/spa-0.2/spa/utils/json-core.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-10-23 15:35:21 +02:00
parent c3e5371053
commit 7906dc854a

View file

@ -414,10 +414,8 @@ static inline bool spa_json_is_float(const char *val, int len)
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;
}