aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog10
-rw-r--r--builtin.c2
-rw-r--r--mpfr.c43
-rw-r--r--pc/ChangeLog4
-rw-r--r--pc/Makefile.tst4
-rw-r--r--test/ChangeLog5
-rw-r--r--test/Makefile.am1
-rw-r--r--test/Makefile.in5
-rw-r--r--test/Maketests4
-rw-r--r--test/forcenum-mpfr.ok9
10 files changed, 66 insertions, 21 deletions
diff --git a/ChangeLog b/ChangeLog
index 26ad3f78..87805af4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+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.
diff --git a/builtin.c b/builtin.c
index afd866ac..2b0f8189 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_sgn(n->mpg_numbr) < 0 ? "-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 38f38a3a..f1a460a6 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/pc/ChangeLog b/pc/ChangeLog
index d8df9a37..2c0b8b34 100644
--- a/pc/ChangeLog
+++ b/pc/ChangeLog
@@ -1,3 +1,7 @@
+2020-12-20 Arnold D. Robbins <arnold@skeeve.com>
+
+ * Makefile.tst: Rebuilt.
+
2020-12-19 Arnold D. Robbins <arnold@skeeve.com>
* Makefile.tst: Rebuilt.
diff --git a/pc/Makefile.tst b/pc/Makefile.tst
index 96902d93..0d5cef13 100644
--- a/pc/Makefile.tst
+++ b/pc/Makefile.tst
@@ -2665,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 $@
diff --git a/test/ChangeLog b/test/ChangeLog
index 48f28ed2..f1c0a6a0 100644
--- a/test/ChangeLog
+++ b/test/ChangeLog
@@ -1,3 +1,8 @@
+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.
diff --git a/test/Makefile.am b/test/Makefile.am
index 278a0eb1..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 \
diff --git a/test/Makefile.in b/test/Makefile.in
index e0528b9d..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 \
@@ -4325,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 $@
diff --git a/test/Maketests b/test/Maketests
index d849f54d..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 $@
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)