summaryrefslogtreecommitdiff
path: root/gpsd_json.c
diff options
context:
space:
mode:
authorGary E. Miller <gem@rellim.com>2015-02-02 13:50:48 -0800
committerGary E. Miller <gem@rellim.com>2015-02-02 13:50:48 -0800
commit61a37a2f3a8b47513f5d2e4a7dee0b3a4a581aed (patch)
tree6468c9907b658b704fd82deb8ff3cc2a6914bddb /gpsd_json.c
parent8c0106875fe6c4792b5cc0781b1aba109a9e75f7 (diff)
downloadgpsd-61a37a2f3a8b47513f5d2e4a7dee0b3a4a581aed.tar.gz
Fix loss of precision in PPS json message.
PPS time is 63 bits of precision A doulbe is only 53 bits of preccision PPS time does not fit in a double without loss of precision
Diffstat (limited to 'gpsd_json.c')
-rw-r--r--gpsd_json.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/gpsd_json.c b/gpsd_json.c
index 9962a809..48c63664 100644
--- a/gpsd_json.c
+++ b/gpsd_json.c
@@ -187,9 +187,12 @@ void json_tpv_dump(const struct gps_device_t *session,
#ifdef PPS_ENABLE
/*@-type -formattype@*/ /* splint is confused about struct timespec */
if (session->ppscount)
+ /* you can not use a double here as you will lose 11 bits
+ * of precision */
str_appendf(reply, replylen,
- "\"pps\":%.9f,",
- session->ppslast.clock.tv_sec + session->ppslast.clock.tv_nsec / 1e9);
+ "\"pps\":%ld.$09ld,",
+ session->ppslast.clock.tv_sec,
+ session->ppslast.clock.tv_nsec);
/*@+type +formattype@*/
#endif /* PPS_ENABLE */
str_appendf(reply, replylen,