Finish float printing

This commit is contained in:
2026-08-13 03:51:55 -07:00
parent 7b854c1559
commit 20aed63851
4 changed files with 31 additions and 145 deletions
+14 -2
View File
@@ -3,6 +3,7 @@
#include "lisp.h"
#include <limits.h>
#include <string.h>
DEFVAR(print_circular, "print-circular", "", Qt);
DEFVAR(print_length, "print-length", "", MAKE_FIXNUM(100));
@@ -172,12 +173,23 @@ static void print_float(struct PrintContext *restrict pc, LispVal *val) {
case FP_NORMAL: {
char fmt[16];
int written =
snprintf(fmt, sizeof(fmt), "%%%" LISP_FIXNUM_PRINTF(d) "g",
snprintf(fmt, sizeof(fmt), "%%.%" LISP_FIXNUM_PRINTF(d) "g",
pc->opts.precision);
assert(written < sizeof(fmt));
char buffer[32];
written = snprintf(buffer, sizeof(buffer), fmt, buffer);
written = snprintf(buffer, sizeof(buffer), fmt, fv);
assert(written < sizeof(buffer));
size_t i;
for (i = 0; i < written && buffer[i] != 'e'; ++i) {
if (buffer[i] == '.') {
goto no_add;
}
}
memmove(buffer + i + 2, buffer + i, written - i);
buffer[i] = '.';
buffer[i + 1] = '0';
written += 2;
no_add:
print_buffer(pc, buffer, written);
} break;
default: