Skip to content

Commit 5083f30

Browse files
committed
Replace finite() with std::isfinite()
`finite()` is a BSD extension for C that is widely supported but not standard. Fails to compile under MacOS.
1 parent d67ab8c commit 5083f30

7 files changed

Lines changed: 18 additions & 18 deletions

File tree

src/field/field2d.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ namespace {
355355
void checkDataIsFiniteOnRegion(const Field2D& f, const std::string& region) {
356356
// Do full checks
357357
BOUT_FOR_SERIAL(i, f.getRegion(region)) {
358-
if (!::finite(f[i])) {
358+
if (!std::isfinite(f[i])) {
359359
throw BoutException("Field2D: Operation on non-finite data at [{:d}][{:d}]\n",
360360
i.x(), i.y());
361361
}

src/field/field3d.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,7 @@ namespace {
751751
void checkDataIsFiniteOnRegion(const Field3D& f, const std::string& region) {
752752
// Do full checks
753753
BOUT_FOR_SERIAL(i, f.getValidRegionWithDefault(region)) {
754-
if (!finite(f[i])) {
754+
if (!std::isfinite(f[i])) {
755755
throw BoutException("Field3D: Operation on non-finite data at [{:d}][{:d}][{:d}]\n",
756756
i.x(), i.y(), i.z());
757757
}

src/field/fieldperp.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ const FieldPerp sliceXZ(const Field3D& f, int y) {
175175
void checkDataIsFiniteOnRegion(const FieldPerp& f, const std::string& region) {
176176
// Do full checks
177177
BOUT_FOR_SERIAL(i, f.getRegion(region)) {
178-
if (!::finite(f[i])) {
178+
if (!std::isfinite(f[i])) {
179179
throw BoutException("FieldPerp: Operation on non-finite data at [{:d}][{:d}]\n",
180180
i.x(), i.z());
181181
}

src/invert/laplace/impls/iterative_parallel_tri/iterative_parallel_tri.cxx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -575,8 +575,8 @@ FieldPerp LaplaceIPT::solve(const FieldPerp& b, const FieldPerp& x0) {
575575
#if CHECK > 2
576576
for (int ix = 0; ix < 4; ix++) {
577577
for (int kz = 0; kz < nmode; kz++) {
578-
if (!finite(levels[0].xloc(ix, kz).real())
579-
or !finite(levels[0].xloc(ix, kz).imag())) {
578+
if (!std::isfinite(levels[0].xloc(ix, kz).real())
579+
or !std::isfinite(levels[0].xloc(ix, kz).imag())) {
580580
throw BoutException("Non-finite xloc at {:d}, {:d}, {:d}", ix, jy, kz);
581581
}
582582
}
@@ -595,7 +595,7 @@ FieldPerp LaplaceIPT::solve(const FieldPerp& b, const FieldPerp& x0) {
595595
#if CHECK > 2
596596
for (int ix = 0; ix < ncx; ix++) {
597597
for (int kz = 0; kz < nmode; kz++) {
598-
if (!finite(xk1d(kz, ix).real()) or !finite(xk1d(kz, ix).imag())) {
598+
if (!std::isfinite(xk1d(kz, ix).real()) or !std::isfinite(xk1d(kz, ix).imag())) {
599599
throw BoutException("Non-finite xloc at {:d}, {:d}, {:d}", ix, jy, kz);
600600
}
601601
}
@@ -636,7 +636,7 @@ FieldPerp LaplaceIPT::solve(const FieldPerp& b, const FieldPerp& x0) {
636636

637637
#if CHECK > 2
638638
for (int kz = 0; kz < ncz; kz++) {
639-
if (!finite(x(ix, kz))) {
639+
if (!std::isfinite(x(ix, kz))) {
640640
throw BoutException("Non-finite at {:d}, {:d}, {:d}", ix, jy, kz);
641641
}
642642
}

src/invert/laplace/impls/petsc/petsc_laplace.cxx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ FieldPerp LaplacePetsc::solve(const FieldPerp& b, const FieldPerp& x0) {
466466
BoutReal A0, A1, A2, A3, A4, A5;
467467
A0 = A(x, y, z);
468468

469-
ASSERT3(finite(A0));
469+
ASSERT3(std::isfinite(A0));
470470

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

480-
ASSERT3(finite(A1));
481-
ASSERT3(finite(A2));
482-
ASSERT3(finite(A3));
483-
ASSERT3(finite(A4));
484-
ASSERT3(finite(A5));
480+
ASSERT3(std::isfinite(A1));
481+
ASSERT3(std::isfinite(A2));
482+
ASSERT3(std::isfinite(A3));
483+
ASSERT3(std::isfinite(A4));
484+
ASSERT3(std::isfinite(A5));
485485

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

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

981-
ASSERT3(finite(coef4));
982-
ASSERT3(finite(coef5));
981+
ASSERT3(std::isfinite(coef4));
982+
ASSERT3(std::isfinite(coef5));
983983
}
984984

985985
if (nonuniform) {

src/invert/laplace/impls/serial_tri/serial_tri.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ FieldPerp LaplaceSerialTri::solve(const FieldPerp& b, const FieldPerp& x0) {
235235

236236
#if CHECK > 2
237237
for (int kz = 0; kz < ncz; kz++) {
238-
if (!finite(x(ix, kz))) {
238+
if (!std::isfinite(x(ix, kz))) {
239239
throw BoutException("Non-finite at {:d}, {:d}, {:d}", ix, jy, kz);
240240
}
241241
}

src/mesh/parallel/fci.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ Field3D FCIMap::integrate(Field3D& f) const {
292292
// which would include cell edges and corners
293293
result[inext] = 0.5 * (f_c + 0.25 * (f_pp + f_mp + f_pm + f_mm));
294294
}
295-
ASSERT2(finite(result[inext]));
295+
ASSERT2(std::isfinite(result[inext]));
296296
}
297297
return result;
298298
}

0 commit comments

Comments
 (0)