Add an error parameter on the GncInt128 constructor.

This commit is contained in:
John Ralls 2017-01-14 14:59:13 -08:00
parent 43fbb338af
commit b5f06ab6dc
3 changed files with 13 additions and 6 deletions

View File

@ -47,11 +47,6 @@ GncRational::GncRational (gnc_numeric n) noexcept :
}
}
GncRational::GncRational (GncInt128 num, GncInt128 den) noexcept :
m_num (num), m_den (den), m_error {}
{
}
GncRational::operator gnc_numeric () const noexcept
{
if (m_num.isOverflow() || m_num.isNan() ||

View File

@ -33,7 +33,10 @@ class GncRational
public:
GncRational() : m_num(0), m_den(1), m_error(GNC_ERROR_OK) {}
GncRational (gnc_numeric n) noexcept;
GncRational (GncInt128 num, GncInt128 den) noexcept;
GncRational (GncInt128 num, GncInt128 den,
GNCNumericErrorCode err=GNC_ERROR_OK) noexcept
: m_num(num), m_den(den), m_error(err) {}
/** Conversion operator; use static_cast<gnc_numeric>(foo). */
operator gnc_numeric() const noexcept;
/** Make a new GncRational with the opposite sign. */

View File

@ -58,3 +58,12 @@ TEST(gncrational_constructors, test_implicit_int_constructor)
EXPECT_EQ(value.m_den, 456);
EXPECT_EQ(value.m_error, GNC_ERROR_OK);
}
TEST(gncrational_constructors, test_with_error_code)
{
int num(123), denom(456);
GncRational value(num, denom, GNC_ERROR_OVERFLOW);
EXPECT_EQ(value.m_num, 123);
EXPECT_EQ(value.m_den, 456);
EXPECT_EQ(value.m_error, GNC_ERROR_OVERFLOW);
}