From 373efa085dcea5fe6b4539cd875b6bd8645f16fa Mon Sep 17 00:00:00 2001 From: Oliver Kiddle Date: Sun, 13 May 2018 10:02:01 +0200 Subject: Nelson H. F. Beebe: 19597 (rebased 42369): return Inf, NaN etc from floating point operations instead of errors to allow non-stop IEEE 754 arithmetic --- Src/params.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'Src/params.c') diff --git a/Src/params.c b/Src/params.c index 36f5f0676..51f6e6d9a 100644 --- a/Src/params.c +++ b/Src/params.c @@ -36,6 +36,8 @@ #else #include "patchlevel.h" +#include + /* If removed from the ChangeLog for some reason */ #ifndef ZSH_PATCHLEVEL #define ZSH_PATCHLEVEL "unknown" @@ -5431,10 +5433,16 @@ convfloat(double dval, int digits, int flags, FILE *fout) ret = NULL; } else { VARARR(char, buf, 512 + digits); - sprintf(buf, fmt, digits, dval); - if (!strchr(buf, 'e') && !strchr(buf, '.')) - strcat(buf, "."); - ret = dupstring(buf); + if (isinf(dval)) + ret = dupstring((dval < 0.0) ? "-Inf" : "Inf"); + else if (isnan(dval)) + ret = dupstring("NaN"); + else { + sprintf(buf, fmt, digits, dval); + if (!strchr(buf, 'e') && !strchr(buf, '.')) + strcat(buf, "."); + ret = dupstring(buf); + } } #ifdef USE_LOCALE if (prev_locale) setlocale(LC_NUMERIC, prev_locale); -- cgit 1.4.1