harec

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

commit 34aa3082c18d6e249f2d23404821ee77c6960969
parent 6dc8bc29d8f2ce33f8419093d295162f995b7a54
Author: Sudipto Mallick <smlckz@disroot.org>
Date:   Wed,  7 Jul 2021 13:34:48 +0000

typedef: add special case for NaN and Infinity floating point constants

Signed-off-by: Sudipto Mallick <smlckz@disroot.org>

Diffstat:
Msrc/typedef.c | 14++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/src/typedef.c b/src/typedef.c @@ -1,6 +1,7 @@ #include <assert.h> #include <ctype.h> #include <inttypes.h> +#include <math.h> #include <stdio.h> #include <stdlib.h> #include "check.h" @@ -63,9 +64,18 @@ emit_const(const struct expression *expr, FILE *out) case STORAGE_F32: case STORAGE_F64: case STORAGE_FCONST: - fprintf(out, "%lf%s", val->fval, - storage_to_suffix(expr->result->storage)); + { + const char *suffix = storage_to_suffix(expr->result->storage); + if (isnan(val->fval)) { + fprintf(out, "0.0%s / 0.0%s", suffix, suffix); + } else if (isinf(val->fval)) { + fprintf(out, "%s1.0%s / 0.0%s", + (val->fval > 0) ? "" : "-", suffix, suffix); + } else { + fprintf(out, "%lf%s", val->fval, suffix); + } break; + } case STORAGE_I16: case STORAGE_I32: case STORAGE_I64: