diff options
Diffstat (limited to 'mpfr.c')
-rw-r--r-- | mpfr.c | 20 |
1 files changed, 12 insertions, 8 deletions
@@ -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 */ |