IsInf.cpp revision 256281
1236769Sobrien//===-- IsInf.cpp - Platform-independent wrapper around C99 isinf() -------===//
2236769Sobrien//
3236769Sobrien//                     The LLVM Compiler Infrastructure
4236769Sobrien//
5236769Sobrien// This file is distributed under the University of Illinois Open Source
6236769Sobrien// License. See LICENSE.TXT for details.
7236769Sobrien//
8236769Sobrien//===----------------------------------------------------------------------===//
9236769Sobrien//
10236769Sobrien// Platform-independent wrapper around C99 isinf()
11236769Sobrien//
12236769Sobrien//===----------------------------------------------------------------------===//
13236769Sobrien
14236769Sobrien#include "llvm/Config/config.h"
15236769Sobrien
16236769Sobrien#if HAVE_ISINF_IN_MATH_H
17236769Sobrien# include <math.h>
18236769Sobrien#elif HAVE_ISINF_IN_CMATH
19236769Sobrien# include <cmath>
20236769Sobrien#elif HAVE_STD_ISINF_IN_CMATH
21236769Sobrien# include <cmath>
22236769Sobrienusing std::isinf;
23236769Sobrien#elif HAVE_FINITE_IN_IEEEFP_H
24236769Sobrien// A handy workaround I found at http://www.unixguide.net/sun/faq ...
25236769Sobrien// apparently this has been a problem with Solaris for years.
26236769Sobrien# include <ieeefp.h>
27236769Sobrienstatic int isinf(double x) { return !finite(x) && x==x; }
28236769Sobrien#elif defined(_MSC_VER)
29236769Sobrien#include <float.h>
30236769Sobrien#define isinf(X) (!_finite(X))
31236769Sobrien#elif defined(_AIX) && defined(__GNUC__)
32236769Sobrien// GCC's fixincludes seems to be removing the isinf() declaration from the
33236769Sobrien// system header /usr/include/math.h
34236769Sobrien# include <math.h>
35236769Sobrienstatic int isinf(double x) { return !finite(x) && x==x; }
36236769Sobrien#elif defined(__hpux)
37236769Sobrien// HP-UX is "special"
38236769Sobrien#include <math.h>
39236769Sobrienstatic int isinf(double x) { return ((x) == INFINITY) || ((x) == -INFINITY); }
40236769Sobrien#else
41236769Sobrien# error "Don't know how to get isinf()"
42236769Sobrien#endif
43236769Sobrien
44236769Sobriennamespace llvm {
45236769Sobrien
46236769Sobrienint IsInf(float f)  { return isinf(f); }
47236769Sobrienint IsInf(double d) { return isinf(d); }
48236769Sobrien
49236769Sobrien} // end namespace llvm;
50236769Sobrien