aboutsummaryrefslogtreecommitdiffhomepage
path: root/io.c
diff options
context:
space:
mode:
authorlemon <lsof@mailbox.org>2025-12-05 12:54:11 +0100
committerlemon <lsof@mailbox.org>2025-12-05 12:54:11 +0100
commit78333412a9b502ebd04306ecfd71b0db216d51c7 (patch)
treed037098457bb7165356da2f68a64b3cc1401c73a /io.c
parent139dfbd9b812757f0070745f93624c95ea902615 (diff)
io: print nans as NaN
Diffstat (limited to 'io.c')
-rw-r--r--io.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/io.c b/io.c
index 1721f7b..6e1d425 100644
--- a/io.c
+++ b/io.c
@@ -291,6 +291,11 @@ putdouble(struct wbuf *buf, double x, vlong prec)
x = -x;
}
+ if (x != x) {
+ iowrite(buf, "NaN", 3);
+ return n + 3;
+ }
+
x += 0.5 / prec; // round last decimal
if (x >= (double)(-1ULL>>1)) { // out of range?
n += bwriteS(buf, "inf");