diff --git a/src/libqof/qof/gnc-numeric.cpp b/src/libqof/qof/gnc-numeric.cpp index 4002e396ec..3e74568c83 100644 --- a/src/libqof/qof/gnc-numeric.cpp +++ b/src/libqof/qof/gnc-numeric.cpp @@ -280,6 +280,9 @@ GncNumeric::prepare_conversion(int64_t new_denom) const int64_t GncNumeric::sigfigs_denom(unsigned figs) const noexcept { + if (m_num == 0) + return 1; + int64_t num_abs{std::abs(m_num)}; bool not_frac = num_abs > m_den; int64_t val{ not_frac ? num_abs / m_den : m_den / num_abs }; diff --git a/src/libqof/qof/gnc-rational.cpp b/src/libqof/qof/gnc-rational.cpp index e409b84918..9c787a40c4 100644 --- a/src/libqof/qof/gnc-rational.cpp +++ b/src/libqof/qof/gnc-rational.cpp @@ -159,6 +159,9 @@ GncRational::prepare_conversion (GncInt128 new_denom) const GncInt128 GncRational::sigfigs_denom(unsigned figs) const noexcept { + if (m_num == 0) + return 1; + auto num_abs = m_num.abs(); bool not_frac = num_abs > m_den; int64_t val{ not_frac ? num_abs / m_den : m_den / num_abs };