mirror of
https://codeberg.org/redict/redict.git
synced 2025-01-23 00:28:26 -05:00
Geo: addReplyDoubleDistance() precision set to 4 digits
Also: 1. The function was renamed. 2. An useless initialization of a buffer was removed.
This commit is contained in:
parent
b18c68aa7f
commit
fc03d08ee0
14
src/geo.c
14
src/geo.c
@ -110,11 +110,13 @@ static double extractDistanceOrReply(redisClient *c, robj **argv,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* The defailt addReplyDouble has too much accuracy. We use this
|
/* The defailt addReplyDouble has too much accuracy. We use this
|
||||||
* for returning location distances. "5.21 meters away" is nicer
|
* for returning location distances. "5.2145 meters away" is nicer
|
||||||
* than "5.2144992818115 meters away." */
|
* than "5.2144992818115 meters away." We provide 4 digits after the dot
|
||||||
static inline void addReplyDoubleMeters(redisClient *c, double d) {
|
* so that the returned value is decently accurate even when the unit is
|
||||||
char dbuf[128] = { 0 };
|
* the kilometer. */
|
||||||
int dlen = snprintf(dbuf, sizeof(dbuf), "%.2f", d);
|
static inline void addReplyDoubleDistance(redisClient *c, double d) {
|
||||||
|
char dbuf[128];
|
||||||
|
int dlen = snprintf(dbuf, sizeof(dbuf), "%.4f", d);
|
||||||
addReplyBulkCBuffer(c, dbuf, dlen);
|
addReplyBulkCBuffer(c, dbuf, dlen);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -510,7 +512,7 @@ static void geoRadiusGeneric(redisClient *c, int type) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (withdist)
|
if (withdist)
|
||||||
addReplyDoubleMeters(c, gp[i].dist);
|
addReplyDoubleDistance(c, gp[i].dist);
|
||||||
|
|
||||||
if (withhash)
|
if (withhash)
|
||||||
addReplyLongLong(c, zr->score);
|
addReplyLongLong(c, zr->score);
|
||||||
|
Loading…
Reference in New Issue
Block a user