diff options
author | Binbin <binloveplay1314@qq.com> | 2022-12-09 01:29:30 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-08 19:29:30 +0200 |
commit | fa5474e15319743908e4cd32bd003272ed018ed3 (patch) | |
tree | 280c83dca5eb2d70a9ab5e9b07ef490e532536d3 /src/networking.c | |
parent | 4a27aa4875250c075ad2860e9ecc88d77ef6091b (diff) | |
download | redis-fa5474e15319743908e4cd32bd003272ed018ed3.tar.gz |
Normalize NAN to a single nan type, like we do with inf (#11597)
From https://en.wikipedia.org/wiki/NaN#Display, it says
that apart from nan and -nan, we can also get NAN and even
nan(char-sequence) from libc.
In #11482, our conclusion was that we wanna normalize it in
Redis to a single nan type, like we already normalized inf.
For this, we also reverted the assert_match part of the test
added in #11506, using assert_equal to validate the changes.
Diffstat (limited to 'src/networking.c')
-rw-r--r-- | src/networking.c | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/networking.c b/src/networking.c index 8e7c5ace1..054bca6a0 100644 --- a/src/networking.c +++ b/src/networking.c @@ -850,6 +850,15 @@ void addReplyDouble(client *c, double d) { addReplyProto(c, d > 0 ? ",inf\r\n" : ",-inf\r\n", d > 0 ? 6 : 7); } + } else if (isnan(d)) { + /* Libc in some systems will format nan in a different way, + * like nan, -nan, NAN, nan(char-sequence). + * So we normalize it and create a single nan form in an explicit way. */ + if (c->resp == 2) { + addReplyBulkCString(c, "nan"); + } else { + addReplyProto(c, ",nan\r\n", 6); + } } else { char dbuf[MAX_LONG_DOUBLE_CHARS+32]; int dlen = 0; @@ -864,7 +873,7 @@ void addReplyDouble(client *c, double d) { dbuf[start] = '$'; /* Convert `dlen` to string, putting it's digits after '$' and before the - * formatted double string. */ + * formatted double string. */ for(int i = digits, val = dlen; val && i > 0 ; --i, val /= 10) { dbuf[start + i] = "0123456789"[val % 10]; } |