From 79e553a58d7f814fd08482b118561fcf9854b1df Mon Sep 17 00:00:00 2001 From: antirez Date: Thu, 18 Feb 2016 22:08:47 +0100 Subject: [PATCH] addReplyHumanLongDouble() API added. Send a long double or double as a bulk reply, in a human friendly format. --- src/networking.c | 9 +++++++++ src/server.h | 1 + 2 files changed, 10 insertions(+) diff --git a/src/networking.c b/src/networking.c index fd4db7c97..1c0340952 100644 --- a/src/networking.c +++ b/src/networking.c @@ -479,6 +479,15 @@ void addReplyDouble(client *c, double d) { } } +/* Add a long double as a bulk reply, but uses a human readable formatting + * of the double instead of exposing the crude behavior of doubles to the + * dear user. */ +void addReplyHumanLongDouble(client *c, long double d) { + robj *o = createStringObjectFromLongDouble(d,1); + addReplyBulk(c,o); + decrRefCount(o); +} + /* Add a long long as integer reply or bulk len / multi bulk count. * Basically this is used to output . */ void addReplyLongLongWithPrefix(client *c, long long ll, char prefix) { diff --git a/src/server.h b/src/server.h index 97ca21cb8..933a4db27 100644 --- a/src/server.h +++ b/src/server.h @@ -1104,6 +1104,7 @@ void addReplyBulkSds(client *c, sds s); void addReplyError(client *c, const char *err); void addReplyStatus(client *c, const char *status); void addReplyDouble(client *c, double d); +void addReplyHumanLongDouble(client *c, long double d); void addReplyLongLong(client *c, long long ll); void addReplyMultiBulkLen(client *c, long length); void copyClientOutputBuffer(client *dst, client *src);