From: Karel Zak Date: Thu, 2 Nov 2023 12:44:32 +0000 (+0100) Subject: libsmartcols: prefer float in filter expression X-Git-Tag: v2.40-rc1~151^2~23 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7a9af89f2d1fe999cf89edc890ece16494fb256f;p=thirdparty%2Futil-linux.git libsmartcols: prefer float in filter expression Reported-by: Masatake YAMATO Addresses: https://github.com/util-linux/util-linux/pull/2531#discussion_r1373797202 Signed-off-by: Karel Zak --- diff --git a/libsmartcols/src/filter-expr.c b/libsmartcols/src/filter-expr.c index d3229d00eb..16a476bde8 100644 --- a/libsmartcols/src/filter-expr.c +++ b/libsmartcols/src/filter-expr.c @@ -141,7 +141,7 @@ static int guess_expr_datatype(struct filter_expr *n) { int type; int l = node_get_datatype(n->left), - r = node_get_datatype(n->right); + r = node_get_datatype(n->right); if (l == r) type = l; @@ -159,6 +159,11 @@ static int guess_expr_datatype(struct filter_expr *n) type = l; else type = l; + + /* Always prefer float before number */ + if (type == SCOLS_DATA_U64 + && (r == SCOLS_DATA_FLOAT || l == SCOLS_DATA_FLOAT)) + type = SCOLS_DATA_FLOAT; } DBG(FPARAM, ul_debugobj(n, " expr datatype: %d", type));