summaryrefslogtreecommitdiff
path: root/src/geo.c
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2015-06-22 13:08:46 +0200
committerantirez <antirez@gmail.com>2015-06-22 13:08:52 +0200
commitfc03d08ee0bc7abcb5f036454458d5b085fff10c (patch)
tree4df68cd4dbd996635f9f3932d16b9d6637291187 /src/geo.c
parentb18c68aa7fa780ab0d591c91ad758246fa9fdc9e (diff)
downloadredis-fc03d08ee0bc7abcb5f036454458d5b085fff10c.tar.gz
Geo: addReplyDoubleDistance() precision set to 4 digits
Also: 1. The function was renamed. 2. An useless initialization of a buffer was removed.
Diffstat (limited to 'src/geo.c')
-rw-r--r--src/geo.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/geo.c b/src/geo.c
index 802acb919..8ab04eb39 100644
--- a/src/geo.c
+++ b/src/geo.c
@@ -110,11 +110,13 @@ static double extractDistanceOrReply(redisClient *c, robj **argv,
}
/* The defailt addReplyDouble has too much accuracy. We use this
- * for returning location distances. "5.21 meters away" is nicer
- * than "5.2144992818115 meters away." */
-static inline void addReplyDoubleMeters(redisClient *c, double d) {
- char dbuf[128] = { 0 };
- int dlen = snprintf(dbuf, sizeof(dbuf), "%.2f", d);
+ * for returning location distances. "5.2145 meters away" is nicer
+ * than "5.2144992818115 meters away." We provide 4 digits after the dot
+ * so that the returned value is decently accurate even when the unit is
+ * the kilometer. */
+static inline void addReplyDoubleDistance(redisClient *c, double d) {
+ char dbuf[128];
+ int dlen = snprintf(dbuf, sizeof(dbuf), "%.4f", d);
addReplyBulkCBuffer(c, dbuf, dlen);
}
@@ -510,7 +512,7 @@ static void geoRadiusGeneric(redisClient *c, int type) {
}
if (withdist)
- addReplyDoubleMeters(c, gp[i].dist);
+ addReplyDoubleDistance(c, gp[i].dist);
if (withhash)
addReplyLongLong(c, zr->score);