MCPcopy Create free account
hub / github.com/RedisGraph/RedisGraph / _ReplyWithRoundedDouble

Function _ReplyWithRoundedDouble

src/slow_log/slow_log.c:21–32  ·  view source on GitHub ↗

redis prints doubles with up to 17 digits of precision, which captures the inaccuracy of many floating-point numbers (such as 0.1) By using the %g format and a precision of 5 significant digits, we avoid many awkward representations like RETURN 0.1 emitting "0.10000000000000001", though we're still subject to many of the typical issues with floating-point error

Source from the content-addressed store, hash-verified

19// awkward representations like RETURN 0.1 emitting "0.10000000000000001",
20// though we're still subject to many of the typical issues with floating-point error
21static inline void _ReplyWithRoundedDouble
22(
23 RedisModuleCtx *ctx,
24 double d
25) {
26 // get length required to print number
27 int len = snprintf(NULL, 0, "%.5g", d);
28 char str[len + 1];
29 sprintf(str, "%.5g", d);
30 // output string-formatted number
31 RedisModule_ReplyWithStringBuffer(ctx, str, len);
32}
33
34static SlowLogItem *_SlowLogItem_New
35(

Callers 1

SlowLog_ReplayFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected