23 #ifndef __GNC_RATIONAL_HPP__ 24 #define __GNC_RATIONAL_HPP__ 27 #include "gnc-int128.hpp" 28 #include "gnc-rational-rounding.hpp" 69 : m_num(
num), m_den(den) {}
82 bool valid() const noexcept;
87 bool is_big() const noexcept;
89 operator gnc_numeric() const noexcept;
116 template <RoundType RT>
119 auto params = prepare_conversion(new_denom);
125 params.rem,
RT2T<RT>()), new_denom);
139 template <RoundType RT>
142 auto new_denom(sigfigs_denom(figs));
143 auto params = prepare_conversion(new_denom);
149 params.rem,
RT2T<RT>()), new_denom);
188 GncInt128 sigfigs_denom(
unsigned figs)
const noexcept;
192 round_param prepare_conversion(
GncInt128 new_denom)
const;
279 inline std::ostream& operator<<(std::ostream& stream,
const GncRational& val) noexcept
281 stream << val.num() <<
"/" << val.denom();
285 #endif //__GNC_RATIONAL_HPP__ GncInt128 denom() const noexcept
Denominator accessor.
GncRational inv() const noexcept
Inverts the number, equivalent of /= {1, 1}.
GncRational reduce() const
Return an equivalent fraction with all common factors between the numerator and the denominator remov...
An exact-rational-number library for gnucash.
The primary numeric class for representing amounts and values.
GncRational convert(GncInt128 new_denom) const
Convert a GncRational to use a new denominator.
GncRational(GncInt128 num, GncInt128 den) noexcept
GncInt128 constructor.
GncRational abs() const noexcept
Absolute value; return value is always >= 0 and of same magnitude.
Rational number class using GncInt128 for the numerator and denominator.
GncRational round_to_numeric() const
Round to fit an int64_t, finding the closest possible approximation.
GncRational()
Default constructor provides the zero value.
bool is_big() const noexcept
Report if either numerator or denominator are too big to fit in an int64_t.
GncInt128 num() const noexcept
Numerator accessor.
int cmp(GncRational b)
Compare function.
bool valid() const noexcept
Report if both members are valid numbers.
#define GNC_DENOM_AUTO
Values that can be passed as the 'denom' argument.
GncRational convert_sigfigs(unsigned int figs) const
Convert with the specified sigfigs.