aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew J. Schorr <aschorr@telemetry-investments.com>2018-02-07 14:16:47 -0500
committerAndrew J. Schorr <aschorr@telemetry-investments.com>2018-02-07 14:16:47 -0500
commitf9ff7769b7b38973bf7447b8ca596435ccf77b67 (patch)
tree28313e5d0755e3e10c10619edcc660202a0dd8fe
parent9b4b32b5911b9d51643d2efd6c646f17e5214c03 (diff)
downloadegawk-f9ff7769b7b38973bf7447b8ca596435ccf77b67.tar.gz
egawk-f9ff7769b7b38973bf7447b8ca596435ccf77b67.tar.bz2
egawk-f9ff7769b7b38973bf7447b8ca596435ccf77b67.zip
Fix bug printing +"01" in regular and MPFR mode.
-rw-r--r--ChangeLog10
-rw-r--r--interpret.h3
-rw-r--r--mpfr.c14
-rw-r--r--test/ChangeLog5
-rw-r--r--test/Makefile.am12
-rw-r--r--test/Makefile.in17
-rw-r--r--test/Maketests5
-rw-r--r--test/mpfruplus.ok3
-rw-r--r--test/uplus.awk5
-rw-r--r--test/uplus.ok3
10 files changed, 73 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index 4c3b12f0..a5fd076d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2018-02-07 Andrew J. Schorr <aschorr@telemetry-investments.com>
+
+ Print +"01" should print "1", not "01".
+ * interpret.h (Op_unary_plus): Need to make a new number node that does
+ not contain the original string representation. The logic is copied
+ from Op_unary_minus.
+ * mpfr.c (mpg_interpret): Add new case for Op_unary_plus based on
+ the Op_unary_minus logic. We need a fresh number node that does not
+ contain the string.
+
2018-01-28 Arnold D. Robbins <arnold@skeeve.com>
* config.guess, config.sub: Updated.
diff --git a/interpret.h b/interpret.h
index 2ee68112..96e2c890 100644
--- a/interpret.h
+++ b/interpret.h
@@ -621,6 +621,9 @@ mod:
case Op_unary_plus:
// Force argument to be numeric
t1 = TOP_NUMBER();
+ r = make_number(t1->numbr);
+ DEREF(t1);
+ REPLACE(r);
break;
case Op_store_sub:
diff --git a/mpfr.c b/mpfr.c
index 1c4a2b9b..0c962c67 100644
--- a/mpfr.c
+++ b/mpfr.c
@@ -1682,6 +1682,20 @@ mod:
REPLACE(r);
break;
+ case Op_unary_plus:
+ t1 = TOP_NUMBER();
+ if (is_mpg_float(t1)) {
+ r = mpg_float();
+ tval = mpfr_set(r->mpg_numbr, t1->mpg_numbr, ROUND_MODE);
+ IEEE_FMT(r->mpg_numbr, tval);
+ } else {
+ r = mpg_integer();
+ mpz_set(r->mpg_i, t1->mpg_i);
+ }
+ DEREF(t1);
+ REPLACE(r);
+ break;
+
case Op_assign_plus:
case Op_assign_minus:
case Op_assign_times:
diff --git a/test/ChangeLog b/test/ChangeLog
index 27817e24..c239ba24 100644
--- a/test/ChangeLog
+++ b/test/ChangeLog
@@ -1,3 +1,8 @@
+2018-02-07 Andrew J. Schorr <aschorr@telemetry-investments.com>
+
+ * Makefile.am (uplus, mpfruplus): Add new tests.
+ * uplus.awk, uplus.ok, mpfruplus.ok: New files.
+
2018-02-05 Arnold D. Robbins <arnold@skeeve.com>
* Makefile.am (MPFR_TESTS): Sort tests and use backslash
diff --git a/test/Makefile.am b/test/Makefile.am
index e154338c..1100cb4c 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -676,6 +676,7 @@ EXTRA_DIST = \
mpfrsqrt.ok \
mpfrstrtonum.awk \
mpfrstrtonum.ok \
+ mpfruplus.ok \
mpgforcenum.awk \
mpgforcenum.ok \
mtchi18n.awk \
@@ -1176,6 +1177,8 @@ EXTRA_DIST = \
uparrfs.awk \
uparrfs.in \
uparrfs.ok \
+ uplus.awk \
+ uplus.ok \
valgrind.awk \
watchpoint1.awk \
watchpoint1.in \
@@ -1251,7 +1254,7 @@ BASIC_TESTS = \
splitdef splitvar splitwht status-close strcat1 strnum1 strnum2 strtod \
subamp subback subi18n subsepnm subslash substr swaplns synerr1 synerr2 \
tradanch tweakfld \
- uninit2 uninit3 uninit4 uninit5 uninitialized unterm uparrfs \
+ uninit2 uninit3 uninit4 uninit5 uninitialized unterm uparrfs uplus \
wideidx wideidx2 widesub widesub2 widesub3 widesub4 wjposer1 \
zero2 zeroe0 zeroflag
@@ -1299,7 +1302,7 @@ MACHINE_TESTS = double1 double2 fmtspcl intformat
MPFR_TESTS = mpfrbigint mpfrexprange mpfrieee mpfrmemok1 mpfrnegzero \
mpfrnr mpfrrem mpfrrnd mpfrrndeval mpfrsort mpfrsqrt \
- mpfrstrtonum mpgforcenum
+ mpfrstrtonum mpgforcenum mpfruplus
LOCALE_CHARSET_TESTS = \
asort asorti backbigs1 backsmalls1 backsmalls2 \
@@ -2123,6 +2126,11 @@ mpfrstrtonum:
@$(AWK) -M -f "$(srcdir)"/$@.awk > _$@ 2>&1
@-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+mpfruplus:
+ @echo $@
+ @$(AWK) -M -f "$(srcdir)"/uplus.awk > _$@ 2>&1
+ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+
mpgforcenum:
@echo $@
@$(AWK) -M -f "$(srcdir)"/$@.awk > _$@ 2>&1
diff --git a/test/Makefile.in b/test/Makefile.in
index 99047fef..3de436f0 100644
--- a/test/Makefile.in
+++ b/test/Makefile.in
@@ -934,6 +934,7 @@ EXTRA_DIST = \
mpfrsqrt.ok \
mpfrstrtonum.awk \
mpfrstrtonum.ok \
+ mpfruplus.ok \
mpgforcenum.awk \
mpgforcenum.ok \
mtchi18n.awk \
@@ -1434,6 +1435,8 @@ EXTRA_DIST = \
uparrfs.awk \
uparrfs.in \
uparrfs.ok \
+ uplus.awk \
+ uplus.ok \
valgrind.awk \
watchpoint1.awk \
watchpoint1.in \
@@ -1508,7 +1511,7 @@ BASIC_TESTS = \
splitdef splitvar splitwht status-close strcat1 strnum1 strnum2 strtod \
subamp subback subi18n subsepnm subslash substr swaplns synerr1 synerr2 \
tradanch tweakfld \
- uninit2 uninit3 uninit4 uninit5 uninitialized unterm uparrfs \
+ uninit2 uninit3 uninit4 uninit5 uninitialized unterm uparrfs uplus \
wideidx wideidx2 widesub widesub2 widesub3 widesub4 wjposer1 \
zero2 zeroe0 zeroflag
@@ -1552,7 +1555,7 @@ INET_TESTS = inetdayu inetdayt inetechu inetecht
MACHINE_TESTS = double1 double2 fmtspcl intformat
MPFR_TESTS = mpfrbigint mpfrexprange mpfrieee mpfrmemok1 mpfrnegzero \
mpfrnr mpfrrem mpfrrnd mpfrrndeval mpfrsort mpfrsqrt \
- mpfrstrtonum mpgforcenum
+ mpfrstrtonum mpgforcenum mpfruplus
LOCALE_CHARSET_TESTS = \
asort asorti backbigs1 backsmalls1 backsmalls2 \
@@ -2563,6 +2566,11 @@ mpfrstrtonum:
@$(AWK) -M -f "$(srcdir)"/$@.awk > _$@ 2>&1
@-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+mpfruplus:
+ @echo $@
+ @$(AWK) -M -f "$(srcdir)"/uplus.awk > _$@ 2>&1
+ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+
mpgforcenum:
@echo $@
@$(AWK) -M -f "$(srcdir)"/$@.awk > _$@ 2>&1
@@ -3946,6 +3954,11 @@ uparrfs:
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
@-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+uplus:
+ @echo $@
+ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
+ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+
wjposer1:
@echo $@
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
diff --git a/test/Maketests b/test/Maketests
index 314aaaec..e449dd30 100644
--- a/test/Maketests
+++ b/test/Maketests
@@ -1037,6 +1037,11 @@ uparrfs:
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
@-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+uplus:
+ @echo $@
+ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
+ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+
wjposer1:
@echo $@
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
diff --git a/test/mpfruplus.ok b/test/mpfruplus.ok
new file mode 100644
index 00000000..9f6e83e2
--- /dev/null
+++ b/test/mpfruplus.ok
@@ -0,0 +1,3 @@
+1
+1
+-1
diff --git a/test/uplus.awk b/test/uplus.awk
new file mode 100644
index 00000000..3220f7fd
--- /dev/null
+++ b/test/uplus.awk
@@ -0,0 +1,5 @@
+BEGIN {
+ print "01" + 0
+ print +"01"
+ print -"01"
+}
diff --git a/test/uplus.ok b/test/uplus.ok
new file mode 100644
index 00000000..9f6e83e2
--- /dev/null
+++ b/test/uplus.ok
@@ -0,0 +1,3 @@
+1
+1
+-1