aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2021-08-05 20:11:07 +0300
committerArnold D. Robbins <arnold@skeeve.com>2021-08-05 20:11:07 +0300
commitf2e5270b21042a09bf33b86f31fbe79bd8fbea06 (patch)
tree8f746aecac9cccb0f9213154923e94553c5e1c33
parent41658f8679967bd276973c3fe02f6d4db94975e3 (diff)
downloadegawk-f2e5270b21042a09bf33b86f31fbe79bd8fbea06.tar.gz
egawk-f2e5270b21042a09bf33b86f31fbe79bd8fbea06.tar.bz2
egawk-f2e5270b21042a09bf33b86f31fbe79bd8fbea06.zip
Add warnings for negative arguments for -M mode.
-rw-r--r--ChangeLog7
-rw-r--r--mpfr.c20
2 files changed, 19 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index a03edc8b..73896243 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+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.
+
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/mpfr.c b/mpfr.c
index cabc3910..cf18288a 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 */