about summary refs log tree commit diff
path: root/Src/params.c
diff options
context:
space:
mode:
authorOliver Kiddle <okiddle@yahoo.co.uk>2018-05-13 10:02:01 +0200
committerOliver Kiddle <okiddle@yahoo.co.uk>2018-05-13 10:02:01 +0200
commit373efa085dcea5fe6b4539cd875b6bd8645f16fa (patch)
treeb318a3be674458848e156e49d1df1c21543f95c6 /Src/params.c
parentf0c2cf8607dd055f2b8aaa98664f7328108f2c65 (diff)
downloadzsh-373efa085dcea5fe6b4539cd875b6bd8645f16fa.tar.gz
zsh-373efa085dcea5fe6b4539cd875b6bd8645f16fa.tar.xz
zsh-373efa085dcea5fe6b4539cd875b6bd8645f16fa.zip
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
Diffstat (limited to 'Src/params.c')
-rw-r--r--Src/params.c16
1 files changed, 12 insertions, 4 deletions
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 <math.h>
+
 /* 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);