[petsc-dev] [petsc-maint #40445] PetscIsInfOrNanReal causing problems w/C++ on Mac
Barry Smith
bsmith at mcs.anl.gov
Sun Jan 17 18:36:45 CST 2010
Brad,
This is a know glitch, sorry bout it.
PETSc folks,
Rather than having the awful mess that is in the code now
#if defined(PETSC_HAVE_ISINF) && defined(PETSC_HAVE_ISNAN)
#define PetscIsInfOrNanScalar(a) (isinf(PetscAbsScalar(a)) ||
isnan(PetscAbsScalar(a)))
#define PetscIsInfOrNanReal(a) (isinf(a) || isnan(a))
#elif defined(PETSC_HAVE__FINITE) && defined(PETSC_HAVE__ISNAN)
#if defined(PETSC_HAVE_FLOAT_H)
#include "float.h" /* windows defines _finite() in float.h */
#endif
#if defined(PETSC_HAVE_IEEEFP_H)
#include "ieeefp.h" /* Solaris prototypes these here */
#endif
#define PetscIsInfOrNanScalar(a) (!_finite(PetscAbsScalar(a)) ||
_isnan(PetscAbsScalar(a)))
#define PetscIsInfOrNanReal(a) (!_finite(a) || _isnan(a))
#else
#define PetscIsInfOrNanScalar(a) ((a - a) != 0.0)
#define PetscIsInfOrNanReal(a) ((a - a) != 0.0)
#endif
I propose the following
#if defined(PETSC_HAVE_FLOAT_H)
#include "float.h" /* windows defines _finite() in float.h */
#endif
#if defined(PETSC_HAVE_IEEEFP_H)
#include "ieeefp.h" /* Solaris prototypes these here */
#endif
#define PetscIsInfOrNanScalar(a) PetscIsInfOrNanReal(PetscAbsScalar(a))
then have configure generate the macro
PetscIsInfOrNanReal() by testing in order std::isinf, std::isnan then
isinf(), isnan() then _finite(),_isnan(), then (a-a) != 0.0
Barry
On Jan 17, 2010, at 4:47 PM, Brad Aagaard wrote:
> I am running into some discrepancies in how PetscIsInfOrNanReal is
> defined under OS X 10.5 using g++ 4.0.0. The macro seems to be
> expanded
> in a reasonable way if I include math.h, but not if I include cmath
> instead. Since I actually include valarray (which includes cmath) in
> PyLith, I seem to be stuck with a stupid workaround. I have added
>
>
> #define isnan std::isnan
> #define isinf std::isinf
>
> after including the header files. I would like to eliminate this if
> possible.
>
> I created a simple test case and have attached a tarball with the
> source
> code, the preprocessed files, and my PETSc configure.log. The
> preprocessed files illustrate the difference in how the
> PetscIsInfOrNanReal is expanded.
>
> Brad
>
> <isnan_problem.tgz>
More information about the petsc-dev
mailing list