diff --git a/epiworld.hpp b/epiworld.hpp index 9a258db8..7c368b07 100644 --- a/epiworld.hpp +++ b/epiworld.hpp @@ -2243,7 +2243,15 @@ inline void LFMCMC::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; } @@ -2311,7 +2319,14 @@ inline void LFMCMC::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; } diff --git a/include/epiworld/math/lfmcmc/lfmcmc-meat-print.hpp b/include/epiworld/math/lfmcmc/lfmcmc-meat-print.hpp index 6a658ab5..c33a7b61 100755 --- a/include/epiworld/math/lfmcmc/lfmcmc-meat-print.hpp +++ b/include/epiworld/math/lfmcmc/lfmcmc-meat-print.hpp @@ -93,7 +93,15 @@ inline void LFMCMC::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; } @@ -161,7 +169,14 @@ inline void LFMCMC::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; }