Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use isfinite and isnan provided by <cmath> #231

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 2 additions & 20 deletions src/CoinFinite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,17 @@
// This code is licensed under the terms of the Eclipse Public License (EPL).

#include "CoinFinite.hpp"
#include "CoinUtilsConfig.h"

#include <cfloat>
#include <cmath>

#ifdef HAVE_CIEEEFP
#include <cieeefp>
#else
#ifdef HAVE_IEEEFP_H
#include <ieeefp.h>
#endif
#endif

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