diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/mpfr.h | 35 |
1 files changed, 30 insertions, 5 deletions
diff --git a/src/mpfr.h b/src/mpfr.h index 396fb9d8c..87316839a 100644 --- a/src/mpfr.h +++ b/src/mpfr.h @@ -875,11 +875,36 @@ __MPFR_DECLSPEC int mpfr_total_order_p (mpfr_srcptr, mpfr_srcptr); that. */ /* FIXME: most macros are currently buggy. */ -/* Inlining these functions is both faster and smaller */ -#define mpfr_nan_p(_x) ((_x)->_mpfr_exp == __MPFR_EXP_NAN) -#define mpfr_inf_p(_x) ((_x)->_mpfr_exp == __MPFR_EXP_INF) -#define mpfr_zero_p(_x) ((_x)->_mpfr_exp == __MPFR_EXP_ZERO) -#define mpfr_regular_p(_x) ((_x)->_mpfr_exp > __MPFR_EXP_INF) +#if __GNUC__ > 2 || __GNUC_MINOR__ >= 95 +/* We need to make sure that the usual type conversion for function + parameters is done. Forcing the correct type with a cast like in + ((mpfr_srcptr)(_x))->_mpfr_exp should be avoided since this would + hide potential type errors, e.g. if _x has an integer type. */ +#define mpfr_nan_p(_x) \ + __extension__ ({ \ + mpfr_srcptr _p = (_x); \ + _p->_mpfr_exp == __MPFR_EXP_NAN; \ + }) +#define mpfr_inf_p(_x) \ + __extension__ ({ \ + mpfr_srcptr _p = (_x); \ + _p->_mpfr_exp == __MPFR_EXP_INF; \ + }) +#define mpfr_zero_p(_x) \ + __extension__ ({ \ + mpfr_srcptr _p = (_x); \ + _p->_mpfr_exp == __MPFR_EXP_ZERO; \ + }) +#define mpfr_regular_p(_x) \ + __extension__ ({ \ + mpfr_srcptr _p = (_x); \ + _p->_mpfr_exp > __MPFR_EXP_INF; \ + }) +#endif + +/* mpfr_sgn is documented as a macro, thus the following code is fine. + But it would be safer to regard it as a function in some future + MPFR version. */ #define mpfr_sgn(_x) \ ((_x)->_mpfr_exp < __MPFR_EXP_INF ? \ (mpfr_nan_p (_x) ? mpfr_set_erangeflag () : (mpfr_void) 0), 0 : \ |