summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 3362af5)
raw | patch | inline | side by side (parent: 3362af5)
author | Sebastian Harl <sh@tokkee.org> | |
Mon, 17 Nov 2014 18:41:40 +0000 (19:41 +0100) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Mon, 17 Nov 2014 18:41:40 +0000 (19:41 +0100) |
Some versions of GNU libc use '-nan' instead which we don't want. For example,
Go's JSON package doesn't support that at all.
Go's JSON package doesn't support that at all.
src/core/data.c | patch | blob | history | |
src/core/store.c | patch | blob | history |
diff --git a/src/core/data.c b/src/core/data.c
index 3186aa2622ecbfdc3caf2fc877dc7ae890c7754f..9f2b1f6fe4dda241997222ec62ac4fcdabf96eb0 100644 (file)
--- a/src/core/data.c
+++ b/src/core/data.c
ret = snprintf(buf, buflen, "%"PRIi64, datum->data.integer);
}
else if (datum->type == SDB_TYPE_DECIMAL) {
- ret = snprintf(buf, buflen, "%g", datum->data.decimal);
+ if (isnan(datum->data.decimal))
+ ret = snprintf(buf, buflen, "nan");
+ else
+ ret = snprintf(buf, buflen, "%g", datum->data.decimal);
}
else if (datum->type == SDB_TYPE_STRING) {
if (! datum->data.string)
diff --git a/src/core/store.c b/src/core/store.c
index 455e5a328ae14c29d012906bd1057959d8ad15ae..ad59a2e99df3612178445edafe02eeabe3d9fa69 100644 (file)
--- a/src/core/store.c
+++ b/src/core/store.c
#include <stdlib.h>
#include <string.h>
+#include <math.h>
#include <pthread.h>
/*
snprintf(time_str, sizeof(time_str), "<error>");
time_str[sizeof(time_str) - 1] = '\0';
- sdb_strbuf_append(buf, "{\"timestamp\": \"%s\", "
- "\"value\": \"%f\"}", time_str, ts->data[i][j].value);
+ /* Some GNU libc versions may print '-nan' which we dont' want */
+ if (isnan(ts->data[i][j].value))
+ sdb_strbuf_append(buf, "{\"timestamp\": \"%s\", "
+ "\"value\": \"nan\"}", time_str);
+ else
+ sdb_strbuf_append(buf, "{\"timestamp\": \"%s\", "
+ "\"value\": \"%f\"}", time_str, ts->data[i][j].value);
if (j < ts->data_len - 1)
sdb_strbuf_append(buf, ",");