Skip to content

Commit

Permalink
Replace finite() with std::isfinite()
Browse files Browse the repository at this point in the history
`finite()` is a BSD extension for C that is widely supported
but not standard. Fails to compile under MacOS.
  • Loading branch information
bendudson committed Jan 17, 2025
1 parent d67ab8c commit 5083f30
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/field/field2d.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ namespace {
void checkDataIsFiniteOnRegion(const Field2D& f, const std::string& region) {
// Do full checks
BOUT_FOR_SERIAL(i, f.getRegion(region)) {
if (!::finite(f[i])) {
if (!std::isfinite(f[i])) {
throw BoutException("Field2D: Operation on non-finite data at [{:d}][{:d}]\n",
i.x(), i.y());
}
Expand Down
2 changes: 1 addition & 1 deletion src/field/field3d.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ namespace {
void checkDataIsFiniteOnRegion(const Field3D& f, const std::string& region) {
// Do full checks
BOUT_FOR_SERIAL(i, f.getValidRegionWithDefault(region)) {
if (!finite(f[i])) {
if (!std::isfinite(f[i])) {
throw BoutException("Field3D: Operation on non-finite data at [{:d}][{:d}][{:d}]\n",
i.x(), i.y(), i.z());
}
Expand Down
2 changes: 1 addition & 1 deletion src/field/fieldperp.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ const FieldPerp sliceXZ(const Field3D& f, int y) {
void checkDataIsFiniteOnRegion(const FieldPerp& f, const std::string& region) {
// Do full checks
BOUT_FOR_SERIAL(i, f.getRegion(region)) {
if (!::finite(f[i])) {
if (!std::isfinite(f[i])) {
throw BoutException("FieldPerp: Operation on non-finite data at [{:d}][{:d}]\n",
i.x(), i.z());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -575,8 +575,8 @@ FieldPerp LaplaceIPT::solve(const FieldPerp& b, const FieldPerp& x0) {
#if CHECK > 2
for (int ix = 0; ix < 4; ix++) {
for (int kz = 0; kz < nmode; kz++) {
if (!finite(levels[0].xloc(ix, kz).real())
or !finite(levels[0].xloc(ix, kz).imag())) {
if (!std::isfinite(levels[0].xloc(ix, kz).real())
or !std::isfinite(levels[0].xloc(ix, kz).imag())) {
throw BoutException("Non-finite xloc at {:d}, {:d}, {:d}", ix, jy, kz);
}
}
Expand All @@ -595,7 +595,7 @@ FieldPerp LaplaceIPT::solve(const FieldPerp& b, const FieldPerp& x0) {
#if CHECK > 2
for (int ix = 0; ix < ncx; ix++) {
for (int kz = 0; kz < nmode; kz++) {
if (!finite(xk1d(kz, ix).real()) or !finite(xk1d(kz, ix).imag())) {
if (!std::isfinite(xk1d(kz, ix).real()) or !std::isfinite(xk1d(kz, ix).imag())) {
throw BoutException("Non-finite xloc at {:d}, {:d}, {:d}", ix, jy, kz);
}
}
Expand Down Expand Up @@ -636,7 +636,7 @@ FieldPerp LaplaceIPT::solve(const FieldPerp& b, const FieldPerp& x0) {

#if CHECK > 2
for (int kz = 0; kz < ncz; kz++) {
if (!finite(x(ix, kz))) {
if (!std::isfinite(x(ix, kz))) {
throw BoutException("Non-finite at {:d}, {:d}, {:d}", ix, jy, kz);
}
}
Expand Down
18 changes: 9 additions & 9 deletions src/invert/laplace/impls/petsc/petsc_laplace.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ FieldPerp LaplacePetsc::solve(const FieldPerp& b, const FieldPerp& x0) {
BoutReal A0, A1, A2, A3, A4, A5;
A0 = A(x, y, z);

ASSERT3(finite(A0));
ASSERT3(std::isfinite(A0));

// Set the matrix coefficients
Coeffs(x, y, z, A1, A2, A3, A4, A5);
Expand All @@ -477,11 +477,11 @@ FieldPerp LaplacePetsc::solve(const FieldPerp& b, const FieldPerp& x0) {
BoutReal dz2 = SQ(dz);
BoutReal dxdz = dx * dz;

ASSERT3(finite(A1));
ASSERT3(finite(A2));
ASSERT3(finite(A3));
ASSERT3(finite(A4));
ASSERT3(finite(A5));
ASSERT3(std::isfinite(A1));
ASSERT3(std::isfinite(A2));
ASSERT3(std::isfinite(A3));
ASSERT3(std::isfinite(A4));
ASSERT3(std::isfinite(A5));

// Set Matrix Elements
PetscScalar val = 0.;
Expand Down Expand Up @@ -913,7 +913,7 @@ void LaplacePetsc::Element(int i, int x, int z, int xshift, int zshift, PetscSca
int index = (row_new * meshz) + col_new;

#if CHECK > 2
if (!finite(ele)) {
if (!std::isfinite(ele)) {
throw BoutException("Non-finite element at x={:d}, z={:d}, row={:d}, col={:d}\n", x,
z, i, index);
}
Expand Down Expand Up @@ -978,8 +978,8 @@ void LaplacePetsc::Coeffs(int x, int y, int z, BoutReal& coef1, BoutReal& coef2,
coef4 = coords->G1(x, y, z); // X 1st derivative
coef5 = coords->G3(x, y, z); // Z 1st derivative

ASSERT3(finite(coef4));
ASSERT3(finite(coef5));
ASSERT3(std::isfinite(coef4));
ASSERT3(std::isfinite(coef5));
}

if (nonuniform) {
Expand Down
2 changes: 1 addition & 1 deletion src/invert/laplace/impls/serial_tri/serial_tri.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ FieldPerp LaplaceSerialTri::solve(const FieldPerp& b, const FieldPerp& x0) {

#if CHECK > 2
for (int kz = 0; kz < ncz; kz++) {
if (!finite(x(ix, kz))) {
if (!std::isfinite(x(ix, kz))) {
throw BoutException("Non-finite at {:d}, {:d}, {:d}", ix, jy, kz);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/mesh/parallel/fci.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ Field3D FCIMap::integrate(Field3D& f) const {
// which would include cell edges and corners
result[inext] = 0.5 * (f_c + 0.25 * (f_pp + f_mp + f_pm + f_mm));
}
ASSERT2(finite(result[inext]));
ASSERT2(std::isfinite(result[inext]));
}
return result;
}
Expand Down

0 comments on commit 5083f30

Please sign in to comment.