Skip to content

Commit

Permalink
Catch -inf runtime error
Browse files Browse the repository at this point in the history
  • Loading branch information
apulsipher committed Jan 23, 2025
1 parent a9738a3 commit e20221e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
19 changes: 17 additions & 2 deletions epiworld.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2243,7 +2243,15 @@ inline void LFMCMC<TData>::print(size_t burnin) const
for (auto & n : summ_params)
{

int tmp_nchar = std::floor(std::log10(std::abs(n)));
int tmp_nchar;

if (n == 0) {
// std::log10 will return -inf and throw a runtime error
tmp_nchar = s;
} else {
tmp_nchar = std::floor(std::log10(std::abs(n)));
}

if (nchar_par_num < tmp_nchar)
nchar_par_num = tmp_nchar;
}
Expand Down Expand Up @@ -2311,7 +2319,14 @@ inline void LFMCMC<TData>::print(size_t burnin) const
int nchar = 0;
for (auto & s : summ_stats)
{
int tmp_nchar = std::floor(std::log10(std::abs(s)));
int tmp_nchar;
if (s == 0) {
// std::log10 will return -inf and throw a runtime error
tmp_nchar = s;
} else {
tmp_nchar = std::floor(std::log10(std::abs(s)));
}

if (nchar < tmp_nchar)
nchar = tmp_nchar;
}
Expand Down
19 changes: 17 additions & 2 deletions include/epiworld/math/lfmcmc/lfmcmc-meat-print.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,15 @@ inline void LFMCMC<TData>::print(size_t burnin) const
for (auto & n : summ_params)
{

int tmp_nchar = std::floor(std::log10(std::abs(n)));
int tmp_nchar;

if (n == 0) {
// std::log10 will return -inf and throw a runtime error
tmp_nchar = s;
} else {
tmp_nchar = std::floor(std::log10(std::abs(n)));
}

if (nchar_par_num < tmp_nchar)
nchar_par_num = tmp_nchar;
}
Expand Down Expand Up @@ -161,7 +169,14 @@ inline void LFMCMC<TData>::print(size_t burnin) const
int nchar = 0;
for (auto & s : summ_stats)
{
int tmp_nchar = std::floor(std::log10(std::abs(s)));
int tmp_nchar;
if (s == 0) {
// std::log10 will return -inf and throw a runtime error
tmp_nchar = s;
} else {
tmp_nchar = std::floor(std::log10(std::abs(s)));
}

if (nchar < tmp_nchar)
nchar = tmp_nchar;
}
Expand Down

0 comments on commit e20221e

Please sign in to comment.