summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorvlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2021-03-06 10:30:49 +0000
committervlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2021-03-06 10:30:49 +0000
commitbc362287ac851aa93cf199bc6b0287925ba8bdf8 (patch)
treed2dcc1f33da719031026f9f458bb98f18ff14e2c /src
parentb5c74b91a939a20c179eb1fe8ece57e789f63cd7 (diff)
downloadmpfr-bc362287ac851aa93cf199bc6b0287925ba8bdf8.tar.gz
[src/mpfr.h] Fixed some macros implementing functions.
Macros mpfr_nan_p, mpfr_inf_p, mpfr_zero_p and mpfr_regular_p were incorrect since they yielded a compilation error when the argument was of type void *, for instance. Their definition as macros is now available only with __GNUC__. The tisnan test r14448 should no longer fail. Also added a comment for mpfr_sgn, which is correct since documented as a macro. git-svn-id: https://scm.gforge.inria.fr/anonscm/svn/mpfr/trunk@14451 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'src')
-rw-r--r--src/mpfr.h35
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 : \