23 #include <com/avpkit/core/Rational.h>
25 namespace com {
namespace avpkit {
namespace core
28 Rational :: Rational()
36 Rational :: ~Rational()
44 (void)
reduce(mRational.num,
46 FFMAX(mRational.den, mRational.num));
67 mRational = av_d2q(d, 0x7fffffff);
84 result->mRational = *src;
105 result->mRational = src->mRational;
146 result = av_cmp_q(mRational, arg->mRational);
157 if (mRational.den == 0)
158 if (mRational.num == 0)
159 result = std::numeric_limits<double>::quiet_NaN();
161 result = std::numeric_limits<double>::infinity();
163 result = av_q2d(mRational);
171 result = av_reduce(&mRational.num, &mRational.den,
186 result->mRational = av_mul_q(this->mRational,
203 result->mRational = av_div_q(this->mRational,
220 result->mRational = av_sub_q(this->mRational,
236 result->mRational = av_add_q(this->mRational,
246 int64_t retval=origValue;
251 retval = av_rescale_q(origValue, arg->mRational, this->mRational);
260 int64_t retval=origValue;
265 int64_t b = arg->mRational.num * (int64_t)this->mRational.den;
266 int64_t c = this->mRational.num * (int64_t)arg->mRational.den;
268 retval = av_rescale_rnd(origValue, b,
269 c, (
enum AVRounding)rounding);
276 int32_t dstNumerator,
277 int32_t dstDenominator,
278 int32_t srcNumerator,
279 int32_t srcDenominator,
282 int64_t retval = srcValue;
283 if (!dstNumerator || !dstDenominator ||
284 !srcNumerator || !srcDenominator)
287 int64_t b = srcNumerator * (int64_t)dstDenominator;
288 int64_t c = dstNumerator * (int64_t)srcDenominator;
290 retval = av_rescale_rnd(srcValue, b,
291 c, (
enum AVRounding)rounding);
This class wraps represents a Rational number for the AVPKit.
static IRational * make()
Get a new rational that will be set to 0/0.
virtual void init()
Marks this object as finalized and immutable.
virtual IRational * multiply(IRational *arg)
Multiplies this number by arg.
virtual void setDenominator(int32_t value)
Sets the denominator on this object.
virtual double getValue()
An alias for getDouble() but matching JavaBean conventions.
virtual double getDouble()
Rational to double conversion.
virtual int32_t reduce(int64_t num, int64_t den, int64_t max)
Reduce a fraction to it's lowest common denominators.
virtual void setValue(double value)
Sets the numerator and denominator on this object by reducing the double to the closest integer numer...
virtual IRational * divide(IRational *arg)
Divides this rational by arg.
virtual int64_t rescale(int64_t origValue, IRational *origBase)
Takes a value scaled in increments of origBase and gives the equivalent value scaled in terms of this...
virtual void setNumerator(int32_t value)
Sets the numerator on this object.
virtual IRational * add(IRational *arg)
Adds arg to this rational.
virtual int32_t compareTo(IRational *other)
Compare a rational to this rational.
virtual bool isFinalized()
Returns true if init() has been called and this object is now considered finalized and immutable.
virtual IRational * subtract(IRational *arg)
Subtracts arg from this rational.
virtual IRational * copy()
Creates a new IRational object by copying (by value) this object.
WARNING: Do not use logging in this class, and do not set any static file variables to values other t...