IAP GITLAB

Skip to content
Snippets Groups Projects
Commit 43942e1a authored by Lukas Nellen's avatar Lukas Nellen :footprints:
Browse files

Refactor cfenv feature handling - more robust and flexible

Test for missing functions
Provide implementation for OS X and (incomplete) fallback for
unknown platforms
parent 9559d501
No related branches found
No related tags found
No related merge requests found
#
# cfenv feature test - select implementation to use
#
try_compile (HAS_FEENABLEEXCEPT "${CMAKE_CURRENT_BINARY_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/try_feenableexcept.cc")
if (HAS_FEENABLEEXCEPT)
set (CORSIKA_FENV "CorsikaFenvDefault.cc")
set_property(DIRECTORY ${CMAKE_HOME_DIRECTORY} APPEND PROPERTY COMPILE_DEFINITIONS "HAS_FEENABLEEXCEPT")
else ()
if (APPLE)
set (CORSIKA_FENV "CorsikaFenvOSX.cc")
else()
set (CORSIKA_FENV "CorsikaFenvFallback.cc")
endif()
endif ()
#
# library setup
#
set ( set (
UTILITIES_SOURCES UTILITIES_SOURCES
COMBoost.cc COMBoost.cc
CorsikaFenv.cc) ${CORSIKA_FENV})
set ( set (
UTILITIES_HEADERS UTILITIES_HEADERS
......
...@@ -21,7 +21,10 @@ ...@@ -21,7 +21,10 @@
#include <cfenv> #include <cfenv>
#if !defined(__GLIBC__) /*
* Same declaration of function as provided in GLIBC
* Repetition allowed in the case where cfenv defines the functions already, no clash.
*/
extern "C" { extern "C" {
int int
...@@ -30,6 +33,5 @@ extern "C" { ...@@ -30,6 +33,5 @@ extern "C" {
fedisableexcept(int excepts); fedisableexcept(int excepts);
} }
#endif
#endif //CORSIKA_CORSIKAFENV_H #endif //CORSIKA_CORSIKAFENV_H
/**
* (c) Copyright 2018 CORSIKA Project, corsika-project@lists.kit.edu
*
* See file AUTHORS for a list of contributors.
*
* This software is distributed under the terms of the GNU General Public
* Licence version 3 (GPL Version 3). See file LICENSE for a full version of
* the license.
*
* Versions of feenableexcept() and fedisableexcept()
* exist in fenv.h / cfenv headers for C 99 or C++ 11
* Nothing needed.
*
*
* \author Lukas Nellen
* \date 14 Jan 2019
*
*/
// do nothing, functions exist in system libraries
/**
* (c) Copyright 2018 CORSIKA Project, corsika-project@lists.kit.edu
*
* See file AUTHORS for a list of contributors.
*
* This software is distributed under the terms of the GNU General Public
* Licence version 3 (GPL Version 3). See file LICENSE for a full version of
* the license.
*
* Provide fallback versions of feenableexcept() and fedisableexcept()
* Don't exist in the standard
* fenv.h / cfenv headers for C 99 or C++ 11
*
* For platforms without implementation; do-nothing dummy.
*
* \author Lukas Nellen
* \date 14 Jan 2019
*
*/
#include <corsika/utl/CorsikaFenv.h>
#include <cfenv>
extern "C" {
#warning No enabling/disabling of floating point exceptions - platform needs better implementation
int feenableexcept(int excepts)
{
return -1;
}
int fedisableexcept(int excepts)
{
return -1;
}
}
/** /**
* (c) Copyright 2018 CORSIKA Project, corsika-project@lists.kit.edu * Import public domain code
*
* See file AUTHORS for a list of contributors.
*
* This software is distributed under the terms of the GNU General Public
* Licence version 3 (GPL Version 3). See file LICENSE for a full version of
* the license.
* *
* Provide portable or fallback versions of feenableexcept() and fedisableexcept() * Provide portable or fallback versions of feenableexcept() and fedisableexcept()
* Exist by default in glibc since version 2.2, but not in the standard * Exist by default in glibc since version 2.2, but not in the standard
...@@ -19,11 +13,7 @@ ...@@ -19,11 +13,7 @@
#include <corsika/utl/CorsikaFenv.h> #include <corsika/utl/CorsikaFenv.h>
#include <cfenv> #include <cfenv>
#if defined(__GLIBC__) // Implementation for OS X on intel X64_86
// do nothing functions exist
#elif defined(__APPLE__) && defined(__MACH__)
// Implementation of OS X on intel X64_86
// code from https://stackoverflow.com/questions/37819235/how-do-you-enable-floating-point-exceptions-for-clang-in-os-x // code from https://stackoverflow.com/questions/37819235/how-do-you-enable-floating-point-exceptions-for-clang-in-os-x
// based on http://www-personal.umich.edu/~williams/archive/computation/fe-handling-example.c // based on http://www-personal.umich.edu/~williams/archive/computation/fe-handling-example.c
...@@ -68,23 +58,3 @@ extern "C" { ...@@ -68,23 +58,3 @@ extern "C" {
} }
} }
#else
// unknown environment, dummy implementations
extern "C" {
#warning No enabling/disabling of floating point exceptions
int feenableexcept(int excepts)
{
return -1;
}
int fedisableexcept(int excepts)
{
return -1;
}
}
#endif
/**
* (c) Copyright 2018 CORSIKA Project, corsika-project@lists.kit.edu
*
* See file AUTHORS for a list of contributors.
*
* This software is distributed under the terms of the GNU General Public
* Licence version 3 (GPL Version 3). See file LICENSE for a full version of
* the license.
*
* Test code for cmake to check if feenableexcept exists in cfenv
*
* \author Lukas Nellen
* \date 15 Jan 2019
*
*/
#include <cfenv>
int
main()
{
feenableexcept(FE_ALL_EXCEPT);
return 0;
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment