Skip to content

Commit

Permalink
Use isfinite and isnan provided by <cmath>
Browse files Browse the repository at this point in the history
The included <cmath> provides std::isfinite and std::isnan. There is no
need to fallback to C functions.
  • Loading branch information
a-andre committed Jul 19, 2024
1 parent 73781a7 commit 0eedf97
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 30 deletions.
12 changes: 2 additions & 10 deletions src/CoinFinite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,12 @@

bool CoinFinite(double val)
{
#ifdef COINUTILS_C_FINITE
return COINUTILS_C_FINITE(val) != 0;
#else
return val != COIN_DBL_MAX && val != -COIN_DBL_MAX;
#endif
return std::isfinite(val);
}

bool CoinIsnan(double val)
{
#ifdef COINUTILS_C_ISNAN
return COINUTILS_C_ISNAN(val) != 0;
#else
return false;
#endif
return std::isnan(val);
}

/* vi: softtabstop=2 shiftwidth=2 expandtab tabstop=2
Expand Down
6 changes: 0 additions & 6 deletions test/CoinPackedVectorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -685,13 +685,9 @@ CoinPackedVectorUnitTest()
int inx2[ne2] = { 7, 4, 2, 1 };
double el2[ne2] = { 7., 4., 2., 1. };

# ifdef COINUTILS_C_FINITE
double one = 1.0 ;
double zero = 0.0 ;
double infty = one/zero ;
# else
double infty = COIN_DBL_MAX ;
# endif

CoinPackedVector v1;
CoinPackedVector v2;
Expand All @@ -702,11 +698,9 @@ CoinPackedVectorUnitTest()
rV.setConstant(ne1,inx1,0) ;
r = v2 / v1;
assert(r.isEquivalent(rV)) ;
# ifdef COINUTILS_C_FINITE
rV.setConstant(ne1,inx1,infty) ;
r = v1 / v2;
assert(r.isEquivalent(rV)) ;
# endif

r.isEquivalent(rV) ;

Expand Down
14 changes: 0 additions & 14 deletions test/unitTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,7 @@ int main (int argc, const char *argv[])
double checkVal ;

testingMessage( "Testing CoinFinite ... " ) ;
# ifdef COINUTILS_C_FINITE
checkVal = finiteVal/zero ;
# else
checkVal = COIN_DBL_MAX ;
# endif
testingMessage( " finite value: " ) ;
if (CoinFinite(finiteVal))
{ testingMessage( "ok" ) ; }
Expand All @@ -154,11 +150,8 @@ int main (int argc, const char *argv[])
else
{ allOK = false ;
testingMessage( "ERROR.\n" ) ; }
#else
#undef COINUTILS_C_FINITE
#endif

# ifdef COINUTILS_C_ISNAN
testingMessage( "Testing CoinIsnan ... " ) ;
testingMessage( " finite value: " ) ;
if (!CoinIsnan(finiteVal))
Expand All @@ -167,19 +160,12 @@ int main (int argc, const char *argv[])
{ allOK = false ;
testingMessage( "ERROR" ) ; }
testingMessage( "; NaN value: " ) ;
# ifdef COINUTILS_C_FINITE
checkVal = checkVal/checkVal ;
if (CoinIsnan(checkVal))
{ testingMessage( "ok.\n" ) ; }
else
{ allOK = false ;
testingMessage( "ERROR.\n" ) ; }
# endif
# else
allOK = false ;
testingMessage( "ERROR: No functional CoinIsnan.\n" ) ;
# endif


if (netlibDir != "" && mpsDir != "" && testModel != ""){
testingMessage( "Testing CoinModel\n" );
Expand Down

0 comments on commit 0eedf97

Please sign in to comment.