Skip to content

Commit

Permalink
Maintenance: Remove isinf and isnan macros (#417)
Browse files Browse the repository at this point in the history
Remove C89 checks/workarounds for `isinf` and `isnan` functions now that
a subset of C99 is required.
  • Loading branch information
gardner48 authored Feb 7, 2024
1 parent 01cc63b commit 99cf619
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 41 deletions.
14 changes: 0 additions & 14 deletions cmake/SundialsSetupCompilers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -120,20 +120,6 @@ set(DOCSTR "Enable C compiler specific extensions")
sundials_option(CMAKE_C_EXTENSIONS BOOL "${DOCSTR}" ON)
message(STATUS "C extensions set to ${CMAKE_C_EXTENSIONS}")

# ---------------------------------------------------------------
# Check for isinf and isnan
# ---------------------------------------------------------------

check_c_source_compiles("
#include <math.h>
int main(void) {
double a = 0.0;
int result = isinf(a);
result = isnan(a);
return result;
}
" SUNDIALS_C_COMPILER_HAS_ISINF_ISNAN)

# ---------------------------------------------------------------
# Check for __builtin_expect
# ---------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion examples/sunlinsol/test_sunlinsol.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

#include "test_sunlinsol.h"

#include <math.h> /* include isnan */
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <sundials/sundials_linearsolver.h>
Expand Down
2 changes: 1 addition & 1 deletion examples/sunmatrix/test_sunmatrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

#include "test_sunmatrix.h"

#include <math.h> /* include isnan */
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <sundials/sundials_math.h>
Expand Down
1 change: 0 additions & 1 deletion include/sundials/sundials_config.in
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
* SUNDIALS build information
* -----------------------------------------------------------------*/

#cmakedefine SUNDIALS_C_COMPILER_HAS_ISINF_ISNAN
#cmakedefine SUNDIALS_C_COMPILER_HAS_BUILTIN_EXPECT
#cmakedefine SUNDIALS_C_COMPILER_HAS_ATTRIBUTE_ASSUME
#cmakedefine SUNDIALS_C_COMPILER_HAS_BUILTIN_ASSUME
Expand Down
26 changes: 2 additions & 24 deletions src/sundials/sundials_math.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,6 @@
#include <sundials/sundials_math.h>
#include <sundials/sundials_types.h>

static sunbooleantype sunIsInf(sunrealtype a)
{
#if defined(__cplusplus) || defined(SUNDIALS_C_COMPILER_HAS_ISINF_ISNAN)
return (isinf(a));
#else
return (a < -SUN_BIG_REAL || a > SUN_BIG_REAL);
#endif
}

static sunbooleantype sunIsNaN(sunrealtype a)
{
#if defined(__cplusplus) || defined(SUNDIALS_C_COMPILER_HAS_ISINF_ISNAN)
return (isnan(a));
#else
/* Most compilers/platforms follow NaN != a,
* but since C89 does not require this, it is
* possible some platforms might not follow it.
*/
return (a != a);
#endif
}

sunrealtype SUNRpowerI(sunrealtype base, int exponent)
{
int i, expt;
Expand Down Expand Up @@ -88,10 +66,10 @@ sunbooleantype SUNRCompareTol(sunrealtype a, sunrealtype b, sunrealtype tol)
if (a == b) { return (SUNFALSE); }

/* If a or b are NaN */
if (sunIsNaN(a) || sunIsNaN(b)) { return (SUNTRUE); }
if (isnan(a) || isnan(b)) { return (SUNTRUE); }

/* If one of a or b are Inf (since we handled both being inf above) */
if (sunIsInf(a) || sunIsInf(b)) { return (SUNTRUE); }
if (isinf(a) || isinf(b)) { return (SUNTRUE); }

diff = SUNRabs(a - b);
norm = SUNMIN(SUNRabs(a + b), SUN_BIG_REAL);
Expand Down

0 comments on commit 99cf619

Please sign in to comment.