summaryrefslogtreecommitdiff
path: root/src/util.c
diff options
context:
space:
mode:
authorMariya Markova <maria.markova@intel.com>2022-05-10 13:55:09 +0200
committerGitHub <noreply@github.com>2022-05-10 14:55:09 +0300
commitc2d8d4e648faa172a65a88fcffaf4ccc10a1ad78 (patch)
treeb14296a6cd289c3933daa0142d92e0844b468387 /src/util.c
parent2a1ea8c7d811cb4461cd42a0c7b811910c80fcb2 (diff)
downloadredis-c2d8d4e648faa172a65a88fcffaf4ccc10a1ad78.tar.gz
Replace float zero comparison to FP_ZERO comparison (#10675)
I suggest to use "[fpclassify](https://en.cppreference.com/w/cpp/numeric/math/fpclassify)" for float comparison with zero, because of expression "value == 0" with value very close to zero can be considered as true with some performance compiler optimizations. Note: this code was introduced by 9d520a7f to accept zset scores that get ERANGE in conversion due to precision loss near 0. But with Intel compilers, ICC and ICX, where optimizations for 0 check are more aggressive, "==0" is true for mentioned functions, however should not be. Behavior is seen starting from O2. This leads to a failure in the ZSCAN test in scan.tcl
Diffstat (limited to 'src/util.c')
-rw-r--r--src/util.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/util.c b/src/util.c
index 85b631f19..1e083fc54 100644
--- a/src/util.c
+++ b/src/util.c
@@ -522,7 +522,7 @@ int string2ld(const char *s, size_t slen, long double *dp) {
if (isspace(buf[0]) || eptr[0] != '\0' ||
(size_t)(eptr-buf) != slen ||
(errno == ERANGE &&
- (value == HUGE_VAL || value == -HUGE_VAL || value == 0)) ||
+ (value == HUGE_VAL || value == -HUGE_VAL || fpclassify(value) == FP_ZERO)) ||
errno == EINVAL ||
isnan(value))
return 0;
@@ -546,7 +546,7 @@ int string2d(const char *s, size_t slen, double *dp) {
isspace(((const char*)s)[0]) ||
(size_t)(eptr-(char*)s) != slen ||
(errno == ERANGE &&
- (*dp == HUGE_VAL || *dp == -HUGE_VAL || *dp == 0)) ||
+ (*dp == HUGE_VAL || *dp == -HUGE_VAL || fpclassify(*dp) == FP_ZERO)) ||
isnan(*dp))
return 0;
return 1;