24
24
25
25
// #include <iostream> // debug
26
26
// #include <iomanip>
27
- #include < assert.h >
28
- #include < math.h >
27
+ #include < cmath >
28
+ #include < cstdio >
29
29
#include < ports-of-call/portability.hpp>
30
- #include < stdio.h >
30
+ #include < ports-of-call/portable_errors.hpp >
31
31
#include < tuple>
32
32
33
33
#define SINGULARITY_ROOT_DEBUG (0 )
@@ -84,7 +84,7 @@ class RootCounts {
84
84
counts_[i] = 0 ;
85
85
}
86
86
PORTABLE_INLINE_FUNCTION void increment (std::size_t i) const {
87
- assert (i < nbins_ && i >= 0 );
87
+ PORTABLE_REQUIRE (i < nbins_ && i >= 0 , " Index in bounds " );
88
88
#ifdef PORTABILITY_STRATEGY_NONE
89
89
counts_[i] += 1 ;
90
90
#endif // PORTABILITY_STRATEGY_NONE
@@ -96,11 +96,11 @@ class RootCounts {
96
96
return tot;
97
97
}
98
98
PORTABLE_INLINE_FUNCTION const Real &operator [](const std::size_t i) const {
99
- assert (i < nbins_ && i >= 0 );
99
+ PORTABLE_REQUIRE (i < nbins_ && i >= 0 , " Index in bounds " );
100
100
return counts_[i];
101
101
}
102
102
PORTABLE_INLINE_FUNCTION Real &operator [](const std::size_t i) {
103
- assert (i < nbins_ && i >= 0 );
103
+ PORTABLE_REQUIRE (i < nbins_ && i >= 0 , " Index in bounds " );
104
104
return counts_[i];
105
105
}
106
106
PORTABLE_INLINE_FUNCTION void print_counts () const {
@@ -362,7 +362,7 @@ PORTABLE_INLINE_FUNCTION Status findRoot(const T &f, const Real ytarget, Real xg
362
362
status = bisect (f, ytarget, xguess, xmin, xmax, xtol, ytol, xroot, counts);
363
363
364
364
// Check for something horrible happening
365
- if (isnan (xroot) || isinf (xroot)) {
365
+ if (std:: isnan (xroot) || std:: isinf (xroot)) {
366
366
#if SINGULARITY_ROOT_DEBUG
367
367
fprintf (stderr, " xroot is nan after bisection\n " );
368
368
#endif
@@ -396,7 +396,7 @@ PORTABLE_INLINE_FUNCTION Status secant(const T &f, const Real ytarget, const Rea
396
396
x -= y / dy;
397
397
if (x < xmin) x = xmin;
398
398
if (x > xmax) x = xmax;
399
- if (isnan (x) || isinf (x)) {
399
+ if (std:: isnan (x) || std:: isinf (x)) {
400
400
// can't recover from this
401
401
#if SINGULARITY_ROOT_DEBUG
402
402
fprintf (stderr,
@@ -472,8 +472,8 @@ PORTABLE_INLINE_FUNCTION Status secant(const T &f, const Real ytarget, const Rea
472
472
}
473
473
#endif
474
474
475
- const int secant_failed =
476
- ( fabs (x - x_last) > xtol || fabs (frac_error) > ytol || isnan (x) || isinf (x));
475
+ const int secant_failed = ( std::abs (x - x_last) > xtol || std::abs (frac_error) > ytol ||
476
+ std:: isnan (x) || std:: isinf (x));
477
477
return secant_failed ? Status::FAIL : Status::SUCCESS;
478
478
}
479
479
@@ -577,7 +577,7 @@ PORTABLE_INLINE_FUNCTION Status bisect(const T &f, const Real ytarget, const Rea
577
577
578
578
xroot = 0.5 * (xl + xr);
579
579
580
- if (isnan (xroot)) {
580
+ if (std:: isnan (xroot)) {
581
581
#if SINGULARITY_ROOT_DEBUG
582
582
Real il = f (xl);
583
583
Real ir = f (xr);
0 commit comments