This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Re: [gfortran, patch] provide isfinite as a macro
- From: FX Coudert <fxcoudert at gmail dot com>
- To: Richard Henderson <rth at redhat dot com>
- Cc: "fortran at gcc dot gnu dot org" <fortran at gcc dot gnu dot org>, patch <gcc-patches at gcc dot gnu dot org>
- Date: Wed, 03 Aug 2005 21:05:04 +0200
- Subject: Re: [gfortran, patch] provide isfinite as a macro
- References: <19c433eb05080307312d9ccf75@mail.gmail.com> <20050803182942.GD16865@redhat.com>
+#define isfinite(x) (((x) == (x)) && ((2 * (x) != (x)) || ((x) == 0)))
Isn't ((x) - (x) == 0) a better definition?
Right. New patch attached, now regtested on i686-cygwin and
sparc-solaris2.7. OK for mainline and 4.0?
FX
2005-08-04 Francois-Xavier Coudert <coudert@clipper.ens.fr>
* libgfortran.h: When isfinite is not provided by the system,
define it as a macro, so that it can accept any floating point
type.
Index: libgfortran/libgfortran.h
===================================================================
RCS file: /cvsroot/gcc/gcc/libgfortran/libgfortran.h,v
retrieving revision 1.27
diff -p -u -r1.27 libgfortran.h
--- libgfortran/libgfortran.h 7 Jul 2005 22:07:53 -0000 1.27
+++ libgfortran/libgfortran.h 3 Aug 2005 14:15:49 -0000
@@ -179,17 +179,11 @@ typedef off_t gfc_offset;
alternatives, or bail out. */
#if (!defined(isfinite) || defined(__CYGWIN__))
#undef isfinite
-static inline int
-isfinite (double x)
-{
#if defined(fpclassify)
- return (fpclassify(x) != FP_NAN && fpclassify(x) != FP_INFINITE);
-#elif defined(HAVE_FINITE)
- return finite (x);
+#define isfinite(x) (fpclassify(x) != FP_NAN && fpclassify(x) != FP_INFINITE)
#else
-#error "libgfortran needs isfinite, fpclassify, or finite"
+#define isfinite(x) ((x) - (x) == 0)
#endif
-}
#endif /* !defined(isfinite) */
/* TODO: find the C99 version of these an move into above ifdef. */