blob: d6da0c99e8d8d64e65fbaa80f1c68e8c82d6201f [file] [log] [blame]
Misha Brukman9437db42004-10-29 23:17:45 +00001//===-- IsInf.cpp - Platform-independent wrapper around C99 isinf() -------===//
Misha Brukmanf976c852005-04-21 22:55:34 +00002//
Brian Gaeke418f73c2004-07-21 03:13:50 +00003// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Misha Brukmanf976c852005-04-21 22:55:34 +00007//
Brian Gaeke418f73c2004-07-21 03:13:50 +00008//===----------------------------------------------------------------------===//
Chris Lattnerf42d1dd2006-08-11 23:52:54 +00009//
10// Platform-independent wrapper around C99 isinf()
11//
12//===----------------------------------------------------------------------===//
Brian Gaeke418f73c2004-07-21 03:13:50 +000013
Reid Spencer551ccae2004-09-01 22:55:40 +000014#include "llvm/Config/config.h"
Misha Brukman9437db42004-10-29 23:17:45 +000015
Brian Gaeke418f73c2004-07-21 03:13:50 +000016#if HAVE_ISINF_IN_MATH_H
17# include <math.h>
18#elif HAVE_ISINF_IN_CMATH
19# include <cmath>
20#elif HAVE_STD_ISINF_IN_CMATH
21# include <cmath>
22using std::isinf;
Brian Gaeke0d3ac4c2004-07-21 03:32:51 +000023#elif HAVE_FINITE_IN_IEEEFP_H
24// A handy workaround I found at http://www.unixguide.net/sun/faq ...
25// apparently this has been a problem with Solaris for years.
26# include <ieeefp.h>
27static int isinf(double x) { return !finite(x) && x==x; }
Chris Lattnerf0ae6c62004-10-25 18:47:10 +000028#elif defined(_MSC_VER)
29#include <float.h>
30#define isinf(X) (!_finite(X))
Misha Brukman9437db42004-10-29 23:17:45 +000031#elif defined(_AIX) && defined(__GNUC__)
32// GCC's fixincludes seems to be removing the isinf() declaration from the
Misha Brukmanf976c852005-04-21 22:55:34 +000033// system header /usr/include/math.h
Misha Brukman9437db42004-10-29 23:17:45 +000034# include <math.h>
35static int isinf(double x) { return !finite(x) && x==x; }
Duraid Madinaaaad8382005-05-16 06:45:57 +000036#elif defined(__hpux)
37// HP-UX is "special"
38#include <math.h>
Chris Lattnerf42d1dd2006-08-11 23:52:54 +000039static int isinf(double x) { return ((x) == INFINITY) || ((x) == -INFINITY); }
Brian Gaeke418f73c2004-07-21 03:13:50 +000040#else
41# error "Don't know how to get isinf()"
42#endif
43
44namespace llvm {
45
Chris Lattnerf42d1dd2006-08-11 23:52:54 +000046int IsInf(float f) { return isinf(f); }
47int IsInf(double d) { return isinf(d); }
Brian Gaeke418f73c2004-07-21 03:13:50 +000048
Chris Lattnerd74ea2b2006-05-24 17:04:05 +000049} // end namespace llvm;