summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2021-08-05 20:20:51 +0300
committerArnold D. Robbins <arnold@skeeve.com>2021-08-05 20:20:51 +0300
commit16780824a151506e0712bdde02384d90cc2cb0ad (patch)
tree04b4e1aed148e7d4ecbe611bbac42eaf6b3e1eaf
parent41a3d7fd84134022cf31659fabd8fe150c3e27bc (diff)
parent492c24d65f760edea1f9228260930728eb747cf7 (diff)
downloadgawk-zos-debug.tar.gz
Merge branch 'gawk-5.1-stable' into zos-debugzos-debug
-rw-r--r--ChangeLog14
-rw-r--r--NEWS5
-rw-r--r--mpfr.c26
3 files changed, 36 insertions, 9 deletions
diff --git a/ChangeLog b/ChangeLog
index a03edc8b..c598dac5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2021-08-05 Andrew J. Schorr <aschorr@telemetry-investments.com>
+
+ * mpfr.c (do_mpfr_func): New argument, warn_negative. If true,
+ print a warning message about a negative argument. Bring -M
+ code into line with regular code. Bug report from Neil Ormos
+ in the help-gawk list.
+
+ Unrelated:
+
+ * mpfr.c (do_mpfr_int_div, mpg_div, mpg_mod): If dividing by
+ zero, print a fatal error messages. Brings MPFR code into line
+ with the regular code. Thanks to Peng Yu for noticing the bug, in
+ the help-gawk list.
+
2021-07-23 Arnold D. Robbins <arnold@skeeve.com>
* awk.h (exec_count_t): Add typedef for Vax VMS C and everyone else.
diff --git a/NEWS b/NEWS
index 7b9c4d21..9b420f94 100644
--- a/NEWS
+++ b/NEWS
@@ -53,7 +53,10 @@ Changes from 5.1.0 to 5.1.1
14. The manual has been updated with much more information about what is
and is not a bug, and the changes in the gawk mailing lists.
-15. There have been numerous minor code cleanups and bug fixes. See the
+15. Similar to item #4 above, division by zero is now fatal in MPFR
+ mode, as it is in regular mode.
+
+16. There have been numerous minor code cleanups and bug fixes. See the
ChangeLog for details.
Changes from 5.0.1 to 5.1.0
diff --git a/mpfr.c b/mpfr.c
index 573448ca..886470a1 100644
--- a/mpfr.c
+++ b/mpfr.c
@@ -749,7 +749,7 @@ do_mpfr_atan2(int nargs)
static inline NODE *
do_mpfr_func(const char *name,
int (*mpfr_func)(mpfr_ptr, mpfr_srcptr, mpfr_rnd_t),
- int nargs)
+ int nargs, bool warn_negative)
{
NODE *t1, *res;
mpfr_ptr p1;
@@ -762,6 +762,10 @@ do_mpfr_func(const char *name,
force_number(t1);
p1 = MP_FLOAT(t1);
+ if (warn_negative && mpfr_sgn(p1) < 0) {
+ force_string(t1);
+ warning(_("%s: received negative argument %.*s"), name, (int) t1->stlen, t1->stptr);
+ }
res = mpg_float();
if ((argprec = mpfr_get_prec(p1)) > default_prec)
mpfr_set_prec(res->mpg_numbr, argprec); /* needed at least for sqrt() */
@@ -771,9 +775,9 @@ do_mpfr_func(const char *name,
return res;
}
-#define SPEC_MATH(X) \
+#define SPEC_MATH(X, WN) \
NODE *result; \
-result = do_mpfr_func(#X, mpfr_##X, nargs); \
+result = do_mpfr_func(#X, mpfr_##X, nargs, WN); \
return result
/* do_mpfr_sin --- do the sin function */
@@ -781,7 +785,7 @@ return result
NODE *
do_mpfr_sin(int nargs)
{
- SPEC_MATH(sin);
+ SPEC_MATH(sin, false);
}
/* do_mpfr_cos --- do the cos function */
@@ -789,7 +793,7 @@ do_mpfr_sin(int nargs)
NODE *
do_mpfr_cos(int nargs)
{
- SPEC_MATH(cos);
+ SPEC_MATH(cos, false);
}
/* do_mpfr_exp --- exponential function */
@@ -797,7 +801,7 @@ do_mpfr_cos(int nargs)
NODE *
do_mpfr_exp(int nargs)
{
- SPEC_MATH(exp);
+ SPEC_MATH(exp, false);
}
/* do_mpfr_log --- the log function */
@@ -805,7 +809,7 @@ do_mpfr_exp(int nargs)
NODE *
do_mpfr_log(int nargs)
{
- SPEC_MATH(log);
+ SPEC_MATH(log, true);
}
/* do_mpfr_sqrt --- do the sqrt function */
@@ -813,7 +817,7 @@ do_mpfr_log(int nargs)
NODE *
do_mpfr_sqrt(int nargs)
{
- SPEC_MATH(sqrt);
+ SPEC_MATH(sqrt, true);
}
/* do_mpfr_int --- convert double to int for awk */
@@ -1505,6 +1509,8 @@ mpg_div(NODE *t1, NODE *t2)
mpfr_ptr p1, p2;
p1 = MP_FLOAT(t1);
p2 = MP_FLOAT(t2);
+ if (mpfr_zero_p(p2))
+ fatal(_("division by zero attempted"));
r = mpg_float();
tval = mpfr_div(r->mpg_numbr, p1, p2, ROUND_MODE);
IEEE_FMT(r->mpg_numbr, tval);
@@ -1538,6 +1544,8 @@ mpg_mod(NODE *t1, NODE *t2)
*/
NODE *dummy_quotient;
+ if (mpz_sgn(t2->mpg_i) == 0)
+ fatal(_("division by zero attempted"));
r = mpg_integer();
dummy_quotient = mpg_integer();
mpz_tdiv_qr(dummy_quotient->mpg_i, r->mpg_i, t1->mpg_i, t2->mpg_i);
@@ -1546,6 +1554,8 @@ mpg_mod(NODE *t1, NODE *t2)
mpfr_ptr p1, p2;
p1 = MP_FLOAT(t1);
p2 = MP_FLOAT(t2);
+ if (mpfr_zero_p(p2))
+ fatal(_("division by zero attempted in `%%'"));
r = mpg_float();
tval = mpfr_fmod(r->mpg_numbr, p1, p2, ROUND_MODE);
IEEE_FMT(r->mpg_numbr, tval);