Skip to contentSkip to conversation

Correct FP minimum handling

PATCH New [email protected] 1 participant 1 message Jan 6, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 Correct FP minimum handling

From: John Levon <[email protected]>

FP_MIN and friends are the minimum *positive* value: what we really want is -FP_MAX.

---
 smatch_sval.c | 6 +++---
 smatch_type.c | 6 +++---
 2 files changed, 6 insertions(+), 6 deletions(-)
smatch_sval.c +3 -3
index 7a2e74cc..2ef3551c 100644
@@ -142,11 +142,11 @@ int sval_is_positive(sval_t sval)
 static bool fp_is_min(sval_t sval)
 {
 	if (sval.type == &float_ctype)
-		return sval.fvalue == FLT_MIN;
+		return sval.fvalue == -FLT_MAX;
 	if (sval.type == &double_ctype)
-		return sval.dvalue == DBL_MIN;
+		return sval.dvalue == -DBL_MAX;
 	if (sval.type == &ldouble_ctype)
-		return sval.ldvalue == LDBL_MIN;
+		return sval.ldvalue == -LDBL_MAX;
 	sm_perror("%s: bad type: '%s'", __func__, type_to_str(sval.type));
 	return false;
 }
smatch_type.c +3 -3
index e3da7627..7e2e29ad 100644
@@ -475,11 +475,11 @@ static sval_t fp_min(struct symbol *type)
 	sval_t ret = { .type = type };
 
 	if (type == &float_ctype)
-		ret.fvalue = FLT_MIN;
+		ret.fvalue = -FLT_MAX;
 	else if (type == &double_ctype)
-		ret.dvalue = DBL_MIN;
+		ret.dvalue = -DBL_MAX;
 	else
-		ret.ldvalue = LDBL_MIN;
+		ret.ldvalue = -LDBL_MAX;
 
 	return ret;
 }
Signature · 1 line
2.17.1