mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Add GncRational(GncNumeric) constructor.
This commit is contained in:
parent
82fe06e390
commit
a54edf1a5e
@ -24,6 +24,17 @@
|
||||
#include "gnc-rational.hpp"
|
||||
#include "gnc-numeric.hpp"
|
||||
|
||||
|
||||
GncRational::GncRational(GncNumeric n) noexcept :
|
||||
m_num(n.num()), m_den(n.denom()), m_error(GNC_ERROR_OK)
|
||||
{
|
||||
if (m_den.isNeg())
|
||||
{
|
||||
m_num *= -m_den;
|
||||
m_den = 1;
|
||||
}
|
||||
}
|
||||
|
||||
GncRational::GncRational (gnc_numeric n) noexcept :
|
||||
m_num (n.num), m_den (n.denom), m_error {GNC_ERROR_OK}
|
||||
{
|
||||
|
@ -39,10 +39,14 @@ class GncRational
|
||||
public:
|
||||
GncRational() : m_num(0), m_den(1), m_error(GNC_ERROR_OK) {}
|
||||
GncRational (gnc_numeric n) noexcept;
|
||||
GncRational(GncNumeric n) noexcept;
|
||||
GncRational (GncInt128 num, GncInt128 den,
|
||||
GNCNumericErrorCode err=GNC_ERROR_OK) noexcept
|
||||
: m_num(num), m_den(den), m_error(err) {}
|
||||
|
||||
GncRational(const GncRational& rhs) = default;
|
||||
GncRational(GncRational&& rhs) = default;
|
||||
GncRational& operator=(const GncRational& rhs) = default;
|
||||
GncRational& operator=(GncRational&& rhs) = default;
|
||||
/** Conversion operator; use static_cast<gnc_numeric>(foo). */
|
||||
operator gnc_numeric() const noexcept;
|
||||
/** Make a new GncRational with the opposite sign. */
|
||||
|
Loading…
Reference in New Issue
Block a user