From db261aabf486fbfdaa2ba4bcb9ecd95f7680f060 Mon Sep 17 00:00:00 2001
From: Calvin Rose <calsrose@gmail.com>
Date: Sun, 1 Dec 2019 09:46:20 -0500
Subject: [PATCH] Fix bad integer printing range.

---
 src/core/pp.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/core/pp.c b/src/core/pp.c
index 99493106..2d37b42d 100644
--- a/src/core/pp.c
+++ b/src/core/pp.c
@@ -37,7 +37,11 @@
 
 static void number_to_string_b(JanetBuffer *buffer, double x) {
     janet_buffer_ensure(buffer, buffer->count + BUFSIZE, 2);
-    const char *fmt = (x == floor(x) && x <= 2.0e53 && x >= -2.0e53) ? "%.0f" : "%g";
+    /* Use int32_t range for valid integers because that is the
+     * range most integer-expecting functions in the C api use. */
+    const char *fmt = (x == floor(x) &&
+                       x <= ((double) INT32_MAX) &&
+                       x >= ((double) INT32_MIN)) ? "%.0f" : "%g";
     int count = snprintf((char *) buffer->data + buffer->count, BUFSIZE, fmt, x);
     buffer->count += count;
 }