Skip to content

Commit

Permalink
fastbrili: Conformant float printing
Browse files Browse the repository at this point in the history
  • Loading branch information
sampsyo committed Jan 6, 2024
1 parent e07819e commit 46eb363
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions fastbril/src/interp/interp.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "interp.h"
#include <string.h>
#include <stdio.h>
#include <math.h>

value_t interpret_insn(program_t *prog, size_t which_fun,
value_t *context, uint16_t *labels,
Expand Down Expand Up @@ -126,8 +127,21 @@ value_t interpret_insn(program_t *prog, size_t which_fun,
printf("%ld", context[args[2 * a + 1]].int_val);
break;
case BRILFLOAT:
printf("%.17g", context[args[2 * a + 1]].float_val);
break;
{
double f = context[args[2 * a + 1]].float_val;
if (isnan(f)) {
printf("NaN");
} else if (isinf(f)) {
if (f < 0) {
printf("-Infinity");
} else {
printf("Infinity");
}
} else {
printf("%.17lf", f);
}
break;
}
default:
fprintf(stderr, "unrecognized type: %d. exiting.\n", args[2 * a]);
exit(1);
Expand Down

0 comments on commit 46eb363

Please sign in to comment.