From 197fc75ab9850402b47d79da2e6cde47c8deb7d4 Mon Sep 17 00:00:00 2001
From: Michael Forney <mforney@mforney.org>
Date: Sun, 2 May 2021 11:52:48 -0700
Subject: qbe: Use fixed precision of 17 when printing floating point constants

It appears that some operating systems don't yet support the C11
DBL_DECIMAL_DIG. In order to ensure consistent output no matter the
precision of long double (which varies from arch to arch), just use
a fixed 17, which is sufficient for IEEE 754 binary64.
---
 qbe.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/qbe.c b/qbe.c
index 5d7c88a..2663085 100644
--- a/qbe.c
+++ b/qbe.c
@@ -1039,7 +1039,7 @@ emitvalue(struct value *v)
 	switch (v->kind) {
 	case VALUE_CONST:
 		if (v->repr->base == 's' || v->repr->base == 'd')
-			printf("%c_%.*g", v->repr->base, DBL_DECIMAL_DIG, v->f);
+			printf("%c_%.17g", v->repr->base, v->f);
 		else
 			printf("%" PRIu64, v->i);
 		break;
@@ -1275,7 +1275,7 @@ dataitem(struct expr *expr, uint64_t size)
 		break;
 	case EXPRCONST:
 		if (expr->type->prop & PROPFLOAT)
-			printf("%c_%.*g", expr->type->size == 4 ? 's' : 'd', DECIMAL_DIG, expr->constant.f);
+			printf("%c_%.17g", expr->type->size == 4 ? 's' : 'd', expr->constant.f);
 		else
 			printf("%" PRIu64, expr->constant.i);
 		break;
-- 
cgit v1.2.3