diff options
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | mpfr.c | 20 |
2 files changed, 19 insertions, 8 deletions
@@ -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. @@ -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 */ |