aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2020-12-20 20:14:27 +0200
committerArnold D. Robbins <arnold@skeeve.com>2020-12-20 20:14:27 +0200
commitb82e1ea2fff1333272d1c29b762dc1abd0215e7e (patch)
treedae4343fb59d01f32cd0f2d84a3c676f21fb51bd
parent86df8fd1c504793b43404ce9467cff7b1d1fe2a1 (diff)
parente1be14cd37e0c6c58284e18c859e334d1b5fa97f (diff)
downloadegawk-b82e1ea2fff1333272d1c29b762dc1abd0215e7e.tar.gz
egawk-b82e1ea2fff1333272d1c29b762dc1abd0215e7e.tar.bz2
egawk-b82e1ea2fff1333272d1c29b762dc1abd0215e7e.zip
Merge branch 'gawk-5.1-stable'
-rw-r--r--ChangeLog18
-rw-r--r--awk.h1
-rw-r--r--builtin.c2
-rw-r--r--mpfr.c43
-rw-r--r--node.c15
-rw-r--r--pc/ChangeLog8
-rw-r--r--pc/Makefile.tst12
-rw-r--r--test/ChangeLog11
-rw-r--r--test/Makefile.am7
-rw-r--r--test/Makefile.in16
-rw-r--r--test/Maketests9
-rw-r--r--test/forcenum-mpfr.ok9
-rw-r--r--test/inf-nan-torture.awk4
-rw-r--r--test/inf-nan-torture.in1
-rw-r--r--test/inf-nan-torture.ok16
15 files changed, 143 insertions, 29 deletions
diff --git a/ChangeLog b/ChangeLog
index 4e36e5b6..6f940724 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,21 @@
+2020-12-20 Arnold D. Robbins <arnold@skeeve.com>
+
+ Second steps fixing +inform, +nancy, for MPFR.
+
+ * builtin.c (format_nan_inf): Use mpfr_signbit instead of mpfr_sgn.
+ * mpfr.c (force_mpnum): Check for NaN and leading minus and if so
+ set the signbit with mpfr_setsign.
+ (mpg_force_number): Copy in code from f_force_number to check
+ properly for +inf, +nan.
+
+2020-12-19 Arnold D. Robbins <arnold@skeeve.com>
+
+ First steps fixing +inform, +nancy. Sigh.
+
+ * awk.h (is_ieee_magic_val): Add declaration.
+ * node.c (is_ieee_magic_val): Make extern, not static.
+ (r_force_number): Make the check smarter, catch -nan.
+
2020-11-02 Arnold D. Robbins <arnold@skeeve.com>
Make gawk numeric comparisons act like C doubles.
diff --git a/awk.h b/awk.h
index 0540ead7..abc35630 100644
--- a/awk.h
+++ b/awk.h
@@ -1730,6 +1730,7 @@ extern void init_btowc_cache();
#define is_valid_character(b) (btowc_cache[(b)&0xFF] != WEOF)
extern bool out_of_range(NODE *n);
extern char *format_nan_inf(NODE *n, char format);
+extern bool is_ieee_magic_val(const char *val);
/* re.c */
extern Regexp *make_regexp(const char *s, size_t len, bool ignorecase, bool dfa, bool canfatal);
extern int research(Regexp *rp, char *str, int start, size_t len, int flags);
diff --git a/builtin.c b/builtin.c
index caf3d3b9..55c8878e 100644
--- a/builtin.c
+++ b/builtin.c
@@ -4293,7 +4293,7 @@ format_nan_inf(NODE *n, char format)
return NULL;
else if (is_mpg_float(n)) {
if (mpfr_nan_p(n->mpg_numbr)) {
- strcpy(buf, mpfr_signbit(n->mpg_numbr) ? "-nan" : "+nan");
+ strcpy(buf, mpfr_signbit(n->mpg_numbr) != 0 ? "-nan" : "+nan");
goto fmt;
} else if (mpfr_inf_p(n->mpg_numbr)) {
diff --git a/mpfr.c b/mpfr.c
index 2dfff447..a9153415 100644
--- a/mpfr.c
+++ b/mpfr.c
@@ -328,6 +328,8 @@ force_mpnum(NODE *n, int do_nondec, int use_locale)
errno = 0;
tval = mpfr_strtofr(n->mpg_numbr, cp, & ptr, base, ROUND_MODE);
+ if (mpfr_nan_p(n->mpg_numbr) && *cp == '-')
+ tval = mpfr_setsign(n->mpg_numbr, n->mpg_numbr, 1, ROUND_MODE);
IEEE_FMT(n->mpg_numbr, tval);
done:
/* trailing space is OK for NUMBER */
@@ -345,10 +347,47 @@ done:
static NODE *
mpg_force_number(NODE *n)
{
+ char *cp, *cpend;
+
if ((n->flags & NUMCUR) != 0)
return n;
n->flags |= NUMCUR;
+ /* Trim leading white space, bailing out if there's nothing else */
+ for (cp = n->stptr, cpend = cp + n->stlen;
+ cp < cpend && isspace((unsigned char) *cp); cp++)
+ continue;
+
+ if (cp == cpend)
+ goto badnum;
+
+ /* At this point, we know the string is not entirely white space */
+ /* Trim trailing white space */
+ while (isspace((unsigned char) cpend[-1]))
+ cpend--;
+
+ /*
+ * 2/2007:
+ * POSIX, by way of severe language lawyering, seems to
+ * allow things like "inf" and "nan" to mean something.
+ * So if do_posix, the user gets what he deserves.
+ * This also allows hexadecimal floating point. Ugh.
+ */
+ if (! do_posix) {
+ if (is_alpha((unsigned char) *cp))
+ goto badnum;
+ else if (is_ieee_magic_val(cp)) {
+ if (cpend != cp + 4)
+ goto badnum;
+ /* else
+ fall through */
+ }
+ /* else
+ fall through */
+ }
+ /* else POSIX, so
+ fall through */
+
if (force_mpnum(n, (do_non_decimal_data && ! do_traditional), true)) {
if ((n->flags & USER_INPUT) != 0) {
/* leave USER_INPUT set to indicate a strnum */
@@ -358,6 +397,10 @@ mpg_force_number(NODE *n)
} else
n->flags &= ~USER_INPUT;
return n;
+badnum:
+ mpg_zero(n);
+ n->flags &= ~USER_INPUT;
+ return n;
}
/* mpg_format_val --- format a numeric value based on format */
diff --git a/node.c b/node.c
index 772131a2..0982a6df 100644
--- a/node.c
+++ b/node.c
@@ -28,7 +28,6 @@
#include <math.h>
#include "floatmagic.h" /* definition of isnan */
-static int is_ieee_magic_val(const char *val);
static NODE *r_make_number(double x);
static AWKNUM get_ieee_magic_val(char *val);
extern NODE **fmt_list; /* declared in eval.c */
@@ -101,9 +100,12 @@ r_force_number(NODE *n)
if (! do_posix) {
if (is_alpha((unsigned char) *cp))
goto badnum;
- else if (cpend == cp+4 && is_ieee_magic_val(cp)) {
- n->numbr = get_ieee_magic_val(cp);
- goto goodnum;
+ else if (is_ieee_magic_val(cp)) {
+ if (cpend == cp + 4) {
+ n->numbr = get_ieee_magic_val(cp);
+ goto goodnum;
+ } else
+ goto badnum;
}
/* else
fall through */
@@ -165,6 +167,9 @@ badnum:
return n;
goodnum:
+ if (isnan(n->numbr) && *cp == '-' && signbit(n->numbr) == 0)
+ n->numbr = -(n->numbr);
+
if ((n->flags & USER_INPUT) != 0) {
/* leave USER_INPUT enabled to indicate that this is a strnum */
n->flags &= ~STRING;
@@ -958,7 +963,7 @@ out: ;
/* is_ieee_magic_val --- return true for +inf, -inf, +nan, -nan */
-static int
+bool
is_ieee_magic_val(const char *val)
{
/*
diff --git a/pc/ChangeLog b/pc/ChangeLog
index fe1a53d7..2c0b8b34 100644
--- a/pc/ChangeLog
+++ b/pc/ChangeLog
@@ -1,3 +1,11 @@
+2020-12-20 Arnold D. Robbins <arnold@skeeve.com>
+
+ * Makefile.tst: Rebuilt.
+
+2020-12-19 Arnold D. Robbins <arnold@skeeve.com>
+
+ * Makefile.tst: Rebuilt.
+
2020-11-01 Arnold D. Robbins <arnold@skeeve.com>
* Makefile.tst: Rebuilt.
diff --git a/pc/Makefile.tst b/pc/Makefile.tst
index 318a5b64..0d5cef13 100644
--- a/pc/Makefile.tst
+++ b/pc/Makefile.tst
@@ -203,7 +203,8 @@ GAWK_EXT_TESTS = \
genpot gensub gensub2 gensub3 getlndir gnuops2 gnuops3 gnureops gsubind \
icasefs icasers id igncdym igncfs ignrcas2 ignrcas4 ignrcase incdupe \
incdupe2 incdupe3 incdupe4 incdupe5 incdupe6 incdupe7 include include2 \
- indirectbuiltin indirectcall indirectcall2 intarray iolint isarrayunset \
+ indirectbuiltin indirectcall indirectcall2 inf-nan-torture \
+ intarray iolint isarrayunset \
lint lintexp lintindex lintint lintlength lintplus lintold lintset lintwarn \
manyfiles match1 match2 match3 mbstr1 mbstr2 mixed1 mktime muldimposix \
nastyparm negtime next nondec nondec2 nonfatal1 nonfatal2 nonfatal3 \
@@ -2664,9 +2665,7 @@ fieldwdth:
forcenum:
@echo $@ $(ZOS_FAIL)
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk --non-decimal-data >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
- @-if echo "$$GAWK_TEST_ARGS" | egrep -q -e '-M|--bignum' > /dev/null ; \
- then $(CMP) "$(srcdir)"/$@-mpfr.ok _$@ && rm -f _$@ ; \
- else $(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ ; fi
+ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
fpat1:
@echo $@
@@ -2883,6 +2882,11 @@ indirectcall2:
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
@-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+inf-nan-torture:
+ @echo $@
+ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
+ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+
intarray:
@echo $@
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk --non-decimal-data >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
diff --git a/test/ChangeLog b/test/ChangeLog
index 3817087e..f1c0a6a0 100644
--- a/test/ChangeLog
+++ b/test/ChangeLog
@@ -1,3 +1,14 @@
+2020-12-20 Arnold D. Robbins <arnold@skeeve.com>
+
+ * Makefile.am (EXTRA_DIST): Remove forcenum-mpfr.ok.
+ * forcenum-mpfr.ok: File deleted, no longer needed.
+
+2020-12-19 Arnold D. Robbins <arnold@skeeve.com>
+
+ * Makefile.am (EXTRA_DIST): inf-nan-torture, new test.
+ * inf-nan-torture.awk, inf-nan-torture.in, inf-nan-torture.ok: New
+ files.
+
2020-10-29 Arnold D. Robbins <arnold@skeeve.com>
* Makefile.am (EXTRA_DIST): functab5, new test.
diff --git a/test/Makefile.am b/test/Makefile.am
index aebdf83b..097dc261 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -344,7 +344,6 @@ EXTRA_DIST = \
fnparydl.ok \
forcenum.awk \
forcenum.ok \
- forcenum-mpfr.ok \
fordel.awk \
fordel.ok \
fork.awk \
@@ -563,6 +562,9 @@ EXTRA_DIST = \
indirectcall.awk \
indirectcall.in \
indirectcall.ok \
+ inf-nan-torture.awk \
+ inf-nan-torture.in \
+ inf-nan-torture.ok \
inftest.awk \
inftest.ok \
inplace1.1.ok \
@@ -1428,7 +1430,8 @@ GAWK_EXT_TESTS = \
genpot gensub gensub2 gensub3 getlndir gnuops2 gnuops3 gnureops gsubind \
icasefs icasers id igncdym igncfs ignrcas2 ignrcas4 ignrcase incdupe \
incdupe2 incdupe3 incdupe4 incdupe5 incdupe6 incdupe7 include include2 \
- indirectbuiltin indirectcall indirectcall2 intarray iolint isarrayunset \
+ indirectbuiltin indirectcall indirectcall2 inf-nan-torture \
+ intarray iolint isarrayunset \
lint lintexp lintindex lintint lintlength lintplus lintold lintset lintwarn \
manyfiles match1 match2 match3 mbstr1 mbstr2 mixed1 mktime muldimposix \
nastyparm negtime next nondec nondec2 nonfatal1 nonfatal2 nonfatal3 \
diff --git a/test/Makefile.in b/test/Makefile.in
index bed55b9f..871e5a43 100644
--- a/test/Makefile.in
+++ b/test/Makefile.in
@@ -607,7 +607,6 @@ EXTRA_DIST = \
fnparydl.ok \
forcenum.awk \
forcenum.ok \
- forcenum-mpfr.ok \
fordel.awk \
fordel.ok \
fork.awk \
@@ -826,6 +825,9 @@ EXTRA_DIST = \
indirectcall.awk \
indirectcall.in \
indirectcall.ok \
+ inf-nan-torture.awk \
+ inf-nan-torture.in \
+ inf-nan-torture.ok \
inftest.awk \
inftest.ok \
inplace1.1.ok \
@@ -1691,7 +1693,8 @@ GAWK_EXT_TESTS = \
genpot gensub gensub2 gensub3 getlndir gnuops2 gnuops3 gnureops gsubind \
icasefs icasers id igncdym igncfs ignrcas2 ignrcas4 ignrcase incdupe \
incdupe2 incdupe3 incdupe4 incdupe5 incdupe6 incdupe7 include include2 \
- indirectbuiltin indirectcall indirectcall2 intarray iolint isarrayunset \
+ indirectbuiltin indirectcall indirectcall2 inf-nan-torture \
+ intarray iolint isarrayunset \
lint lintexp lintindex lintint lintlength lintplus lintold lintset lintwarn \
manyfiles match1 match2 match3 mbstr1 mbstr2 mixed1 mktime muldimposix \
nastyparm negtime next nondec nondec2 nonfatal1 nonfatal2 nonfatal3 \
@@ -4321,9 +4324,7 @@ fieldwdth:
forcenum:
@echo $@ $(ZOS_FAIL)
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk --non-decimal-data >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
- @-if echo "$$GAWK_TEST_ARGS" | egrep -q -e '-M|--bignum' > /dev/null ; \
- then $(CMP) "$(srcdir)"/$@-mpfr.ok _$@ && rm -f _$@ ; \
- else $(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ ; fi
+ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
fpat1:
@echo $@
@@ -4536,6 +4537,11 @@ indirectcall2:
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
@-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+inf-nan-torture:
+ @echo $@
+ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
+ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+
intarray:
@echo $@
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk --non-decimal-data >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
diff --git a/test/Maketests b/test/Maketests
index 7fc7d87f..90599c49 100644
--- a/test/Maketests
+++ b/test/Maketests
@@ -1409,9 +1409,7 @@ fieldwdth:
forcenum:
@echo $@ $(ZOS_FAIL)
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk --non-decimal-data >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
- @-if echo "$$GAWK_TEST_ARGS" | egrep -q -e '-M|--bignum' > /dev/null ; \
- then $(CMP) "$(srcdir)"/$@-mpfr.ok _$@ && rm -f _$@ ; \
- else $(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ ; fi
+ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
fpat1:
@echo $@
@@ -1624,6 +1622,11 @@ indirectcall2:
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
@-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+inf-nan-torture:
+ @echo $@
+ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
+ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+
intarray:
@echo $@
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk --non-decimal-data >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
diff --git a/test/forcenum-mpfr.ok b/test/forcenum-mpfr.ok
deleted file mode 100644
index 6e5853fa..00000000
--- a/test/forcenum-mpfr.ok
+++ /dev/null
@@ -1,9 +0,0 @@
-[] -> 0 (type string)
-[5apple] -> 5 (type string)
-[NaN] -> nan (type strnum)
-[-NaN] -> nan (type strnum)
-[+NaN] -> nan (type strnum)
-[ 6] -> 6 (type strnum)
-[0x1az] -> 26 (type string)
-[011Q] -> 9 (type string)
-[027] -> 23 (type strnum)
diff --git a/test/inf-nan-torture.awk b/test/inf-nan-torture.awk
new file mode 100644
index 00000000..8d145f2a
--- /dev/null
+++ b/test/inf-nan-torture.awk
@@ -0,0 +1,4 @@
+{
+ for (i = 1; i <= NF; i++)
+ print i, $i, $i + 0
+}
diff --git a/test/inf-nan-torture.in b/test/inf-nan-torture.in
new file mode 100644
index 00000000..45dfdc85
--- /dev/null
+++ b/test/inf-nan-torture.in
@@ -0,0 +1 @@
+-inf -inform inform -nan -nancy nancy -123 0 123 +123 nancy +nancy +nan inform +inform +inf
diff --git a/test/inf-nan-torture.ok b/test/inf-nan-torture.ok
new file mode 100644
index 00000000..40d31942
--- /dev/null
+++ b/test/inf-nan-torture.ok
@@ -0,0 +1,16 @@
+1 -inf -inf
+2 -inform 0
+3 inform 0
+4 -nan -nan
+5 -nancy 0
+6 nancy 0
+7 -123 -123
+8 0 0
+9 123 123
+10 +123 123
+11 nancy 0
+12 +nancy 0
+13 +nan +nan
+14 inform 0
+15 +inform 0
+16 +inf +inf