diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-08-19 01:46:37 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-08-19 01:46:37 -0400 |
| commit | 752be14eed4c56186b0a814980445b279ea88661 (patch) | |
| tree | ca9d03e9e6c8b21e50758f62eac33d2c248ed7ea | |
| parent | 14b4a674e82967b14d32eb52dfe5fa7d6ca60ee9 (diff) | |
Fix some numeric precision issues with how nums are printed
| -rw-r--r-- | builtins/nums.c | 8 | ||||
| -rw-r--r-- | compile.c | 8 |
2 files changed, 8 insertions, 8 deletions
diff --git a/builtins/nums.c b/builtins/nums.c index 2efd4cbc..6b4f6a8a 100644 --- a/builtins/nums.c +++ b/builtins/nums.c @@ -17,8 +17,8 @@ public CORD Num$as_text(const double *f, bool colorize, const TypeInfo *type) { (void)type; if (!f) return "Num"; CORD c; - if (colorize) CORD_sprintf(&c, "\x1b[35m%g\x1b[33;2m\x1b[m", *f); - else CORD_sprintf(&c, "%g", *f); + if (colorize) CORD_sprintf(&c, "\x1b[35m%.16g\x1b[33;2m\x1b[m", *f); + else CORD_sprintf(&c, "%.16g", *f); return c; } @@ -99,8 +99,8 @@ public CORD Num32$as_text(const float *f, bool colorize, const TypeInfo *type) { (void)type; if (!f) return "Num32"; CORD c; - if (colorize) CORD_sprintf(&c, "\x1b[35m%g_f32\x1b[m", *f); - else CORD_sprintf(&c, "%g_f32", *f); + if (colorize) CORD_sprintf(&c, "\x1b[35m%.8g_f32\x1b[m", *f); + else CORD_sprintf(&c, "%.8g_f32", *f); return c; } @@ -1320,7 +1320,7 @@ CORD compile_arguments(env_t *env, ast_t *call_ast, arg_t *spec_args, arg_ast_t Int_t int_val = Int$from_text(Match(call_arg->value, Int)->str); double n = Int_to_Num(int_val); value = CORD_asprintf(Match(spec_arg->type, NumType)->bits == TYPE_NBITS64 - ? "N64(%.99g)" : "N32(%.99g)", n); + ? "N64(%.20g)" : "N32(%.10g)", n); } else { env_t *arg_env = with_enum_scope(env, spec_arg->type); type_t *actual_t = get_type(arg_env, call_arg->value); @@ -1348,7 +1348,7 @@ CORD compile_arguments(env_t *env, ast_t *call_ast, arg_t *spec_args, arg_ast_t Int_t int_val = Int$from_text(Match(call_arg->value, Int)->str); double n = Int_to_Num(int_val); value = CORD_asprintf(Match(spec_arg->type, NumType)->bits == TYPE_NBITS64 - ? "N64(%.99g)" : "N32(%.99g)", n); + ? "N64(%.20g)" : "N32(%.10g)", n); } else { env_t *arg_env = with_enum_scope(env, spec_arg->type); type_t *actual_t = get_type(arg_env, call_arg->value); @@ -1511,9 +1511,9 @@ CORD compile(env_t *env, ast_t *ast) case Num: { switch (Match(ast, Num)->bits) { case NBITS_UNSPECIFIED: case NBITS64: - return CORD_asprintf("N64(%.99g)", Match(ast, Num)->n); + return CORD_asprintf("N64(%.20g)", Match(ast, Num)->n); case NBITS32: - return CORD_asprintf("N32(%.99g)", Match(ast, Num)->n); + return CORD_asprintf("N32(%.10g)", Match(ast, Num)->n); default: code_err(ast, "This is not a valid number bit width"); } } |
