2011-06-23 14:02:13 +00:00
|
|
|
//===- llvm/Support/FEnv.h - Host floating-point exceptions ------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file provides an operating system independent interface to
|
|
|
|
// floating-point exception interfaces.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2013-01-10 00:45:19 +00:00
|
|
|
#ifndef LLVM_SUPPORT_FENV_H
|
|
|
|
#define LLVM_SUPPORT_FENV_H
|
2011-06-23 14:02:13 +00:00
|
|
|
|
|
|
|
#include "llvm/Config/config.h"
|
|
|
|
#include <cerrno>
|
|
|
|
#ifdef HAVE_FENV_H
|
|
|
|
#include <fenv.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// FIXME: Clang's #include handling apparently doesn't work for libstdc++'s
|
|
|
|
// fenv.h; see PR6907 for details.
|
|
|
|
#if defined(__clang__) && defined(_GLIBCXX_FENV_H)
|
|
|
|
#undef HAVE_FENV_H
|
|
|
|
#endif
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
namespace sys {
|
|
|
|
|
|
|
|
/// llvm_fenv_clearexcept - Clear the floating-point exception state.
|
|
|
|
static inline void llvm_fenv_clearexcept() {
|
2013-03-25 13:13:33 +00:00
|
|
|
#if defined(HAVE_FENV_H) && HAVE_DECL_FE_ALL_EXCEPT
|
2011-06-23 14:02:13 +00:00
|
|
|
feclearexcept(FE_ALL_EXCEPT);
|
|
|
|
#endif
|
|
|
|
errno = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// llvm_fenv_testexcept - Test if a floating-point exception was raised.
|
|
|
|
static inline bool llvm_fenv_testexcept() {
|
|
|
|
int errno_val = errno;
|
|
|
|
if (errno_val == ERANGE || errno_val == EDOM)
|
|
|
|
return true;
|
2013-03-25 13:13:33 +00:00
|
|
|
#if defined(HAVE_FENV_H) && HAVE_DECL_FE_ALL_EXCEPT && HAVE_DECL_FE_INEXACT
|
2011-06-23 14:02:13 +00:00
|
|
|
if (fetestexcept(FE_ALL_EXCEPT & ~FE_INEXACT))
|
|
|
|
return true;
|
|
|
|
#endif
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // End sys namespace
|
|
|
|
} // End llvm namespace
|
|
|
|
|
|
|
|
#endif
|