18#if AVCPP_USE_SPACESHIP_OPERATOR
30#define AV_TIME_BASE_Q_CPP AVRational{1, AV_TIME_BASE}
34 RationalMaxPrecision = 5
61 Rational(
int numerator,
int denominator = 1) noexcept;
74 Rational(
double value,
int maxPrecision = RationalMaxPrecision) noexcept;
81 AVRational&
getValue() noexcept {
return m_value; }
87 const AVRational&
getValue() const noexcept {
return m_value; }
93 void setValue(
const AVRational &newValue)
noexcept { m_value = newValue; }
125 double getDouble() const noexcept {
return (
double)m_value.num / (double)m_value.den; }
159 Rational& operator= (const AVRational &value) noexcept;
176 bool operator== (const
Rational &other) const noexcept;
177#if AVCPP_USE_SPACESHIP_OPERATOR
187 if (
auto const cmp = threewaycmp(other); cmp == 0) {
188 return std::strong_ordering::equal;
189 }
else if (cmp < 0) {
190 return std::strong_ordering::less;
192 return std::strong_ordering::greater;
204 return threewaycmp(other) != 0;
214 return threewaycmp(other) < 0;
224 return threewaycmp(other) > 0;
234 return (*
this < other) || (*
this == other);
244 return (*
this > other) || (*
this == other);
293 operator const AVRational&() const noexcept
299 int threewaycmp(
const Rational &other)
const noexcept;
318 std::enable_if_t<std::is_floating_point_v<T> || std::is_integral_v<T>,
Rational>
335 std::enable_if_t<std::is_floating_point_v<T> || std::is_integral_v<T>,
Rational>
370 stream >> temp.num >> ch >> temp.den;
377 catch (
const std::exception &e)
387#ifdef __cpp_lib_format
390template <
typename CharT>
391struct std::formatter<
av::Rational, CharT>
393 template<
typename ParseContext>
394 constexpr auto parse(ParseContext& ctx)
398 template<
typename ParseContext>
399 auto format(
const av::Rational& value, ParseContext& ctx)
const
Common helpers: comparisons, value lookup, non-copyable base, string utilities.
Rational number: a numerator and a denominator.
Definition rational.h:49
Rational operator-(const Rational &value) const noexcept
Subtract another rational.
const AVRational & getValue() const noexcept
The underlying FFmpeg value.
Definition rational.h:87
double getDouble() const noexcept
The value as a floating point number.
Definition rational.h:125
Rational operator*(const Rational &value) const noexcept
Multiply by another rational.
void setNumerator(int numerator) noexcept
Set the numerator.
Definition rational.h:100
AVRational & getValue() noexcept
Mutable access to the underlying FFmpeg value.
Definition rational.h:81
Rational() noexcept
Create zero, in the sense of 0/1.
static Rational fromDouble(double value, int maxPrecision=RationalMaxPrecision) noexcept
Approximate a floating point value as a rational.
void dump() const noexcept
Print the value through the FFmpeg log system.
int getDenominator() const noexcept
The denominator.
Definition rational.h:119
std::strong_ordering operator<=>(const Rational &other) const noexcept
Order two rationals by value.
Definition rational.h:185
int64_t rescale(int64_t srcValue, const Rational &dstBase) const noexcept
Rescale a value from this base to another.
void setValue(const AVRational &newValue) noexcept
Replace the value.
Definition rational.h:93
int getNumerator() const noexcept
The numerator.
Definition rational.h:113
Rational operator+(const Rational &value) const noexcept
Add another rational.
double operator()() const noexcept
The value as a floating point number.
void setDenominator(int denominator) noexcept
Set the denominator.
Definition rational.h:106
Rational operator/(const Rational &value) const noexcept
Divide by another rational.
FFmpeg types re-exported for the public API and small value wrappers.
Root namespace of the library.
Definition audioresampler.h:19
bool operator<(const Timestamp &left, const Timestamp &right) noexcept
Compare two timestamps, taking their time bases into account.
Definition timestamp.h:274
std::istream & operator>>(std::istream &stream, Rational &value)
Read a rational written as "numerator/denominator".
Definition rational.h:363
bool operator>(const Timestamp &left, const Timestamp &right) noexcept
Compare two timestamps, taking their time bases into account.
Definition timestamp.h:258
bool operator<=(const Timestamp &left, const Timestamp &right) noexcept
Compare two timestamps.
Definition timestamp.h:334
bool operator>=(const Timestamp &left, const Timestamp &right) noexcept
Compare two timestamps.
Definition timestamp.h:319
bool operator!=(const Timestamp &left, const Timestamp &right) noexcept
Compare two timestamps.
Definition timestamp.h:305
std::ostream & operator<<(std::ostream &stream, const Rational &value)
Print the rational as "numerator/denominator".
Definition rational.h:348
auto operator/(T num, Rational value) -> std::enable_if_t< std::is_floating_point_v< T >||std::is_integral_v< T >, Rational >
Divide a number by a rational.
Definition rational.h:317