mirror of
https://github.com/fluencelabs/redis
synced 2025-06-21 21:11:33 +00:00
Fix HINCRBYFLOAT to work with long doubles.
During the refactoring needed for lazy free, specifically the conversion of t_hash from struct robj to plain SDS strings, HINCRBFLOAT was accidentally moved away from long doubles to doubles for internal processing of increments and formatting. The diminished precision created more obvious artifacts in the way small numbers are formatted once we convert from decimal number in radix 10 to double and back to its string in radix 10. By using more precision, we now have less surprising results at least with small numbers like "1.23", exactly like in the previous versions of Redis. See issue #2846.
This commit is contained in:
@ -596,23 +596,23 @@ void hincrbyCommand(client *c) {
|
||||
}
|
||||
|
||||
void hincrbyfloatCommand(client *c) {
|
||||
double value, incr;
|
||||
long double value, incr;
|
||||
long long ll;
|
||||
robj *o;
|
||||
sds new;
|
||||
unsigned char *vstr;
|
||||
unsigned int vlen;
|
||||
|
||||
if (getDoubleFromObjectOrReply(c,c->argv[3],&incr,NULL) != C_OK) return;
|
||||
if (getLongDoubleFromObjectOrReply(c,c->argv[3],&incr,NULL) != C_OK) return;
|
||||
if ((o = hashTypeLookupWriteOrCreate(c,c->argv[1])) == NULL) return;
|
||||
if (hashTypeGetValue(o,c->argv[2]->ptr,&vstr,&vlen,&ll) == C_OK) {
|
||||
if (vstr) {
|
||||
if (string2d((char*)vstr,vlen,&value) == 0) {
|
||||
if (string2ld((char*)vstr,vlen,&value) == 0) {
|
||||
addReplyError(c,"hash value is not a float");
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
value = (double)ll;
|
||||
value = (long double)ll;
|
||||
}
|
||||
} else {
|
||||
value = 0;
|
||||
|
Reference in New Issue
Block a user