mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Add an error parameter on the GncInt128 constructor.
This commit is contained in:
parent
43fbb338af
commit
b5f06ab6dc
@ -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() ||
|
||||
|
@ -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. */
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user