harec

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 270a31d4ff340c1d0d374f87bc2979580385fed5
parent 3d4219bb46a3f2072a01680591f823e3c44bd19b
Author: Sudipto Mallick <smlckz@envs.net>
Date:   Sun,  4 Apr 2021 09:03:46 +0000

fix precision for floating point numbers in ssa

It seems that 8 and 16 digits aren't enough, we need 9 and 17 digits for f32 and
f64 respectively which is guaranteed to produce the _exact_ and
_correctly-rounded_ floating point value from the text representation when it is
read back.

Diffstat:
Msrc/emit.c | 5+++--
1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/emit.c b/src/emit.c @@ -1,5 +1,6 @@ #include <assert.h> #include <ctype.h> +#include <float.h> #include <stdlib.h> #include <stdio.h> #include "emit.h" @@ -94,10 +95,10 @@ emit_const(struct qbe_value *val, FILE *out) fprintf(out, "%lu", val->lval); break; case Q_SINGLE: - fprintf(out, "s_%.8g", val->sval); + fprintf(out, "s_%.*g", FLT_DECIMAL_DIG, val->sval); break; case Q_DOUBLE: - fprintf(out, "d_%.16g", val->dval); + fprintf(out, "d_%.*g", DBL_DECIMAL_DIG, val->dval); break; case Q__VOID: case Q__AGGREGATE: