Go to the documentation of this file.
29 #ifndef AVUTIL_RATIONAL_H
30 #define AVUTIL_RATIONAL_H
90 const int64_t
tmp=
a.num * (int64_t)
b.den -
b.num * (int64_t)
a.den;
92 if(
tmp)
return (
int)((
tmp ^
a.den ^
b.den)>>63)|1;
93 else if(
b.den &&
a.den)
return 0;
94 else if(
a.num &&
b.num)
return (
a.num>>31) - (
b.num>>31);
105 return a.num / (double)
a.den;
120 int av_reduce(
int *dst_num,
int *dst_den, int64_t num, int64_t den, int64_t
max);
static const uint8_t q1[256]
AVRational av_div_q(AVRational b, AVRational c) av_const
Divide one rational by another.
AVRational av_sub_q(AVRational b, AVRational c) av_const
Subtract one rational from another.
uint32_t av_q2intfloat(AVRational q)
Convert an AVRational to a IEEE 32-bit float expressed in fixed-point format.
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
static double av_q2d(AVRational a)
Convert an AVRational to a double.
Rational number (pair of numerator and denominator).
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
static AVRational av_make_q(int num, int den)
Create an AVRational.
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
int av_find_nearest_q_idx(AVRational q, const AVRational *q_list)
Find the value in a list of rationals nearest a given reference rational.
AVRational av_gcd_q(AVRational a, AVRational b, int max_den, AVRational def)
Return the best rational so that a and b are multiple of it.
AVRational av_d2q(double d, int max) av_const
Convert a double precision floating point number to a rational.
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
static int av_cmp_q(AVRational a, AVRational b)
Compare two rationals.
AVRational av_mul_q(AVRational b, AVRational c) av_const
Multiply two rationals.
int av_nearer_q(AVRational q, AVRational q1, AVRational q2)
Find which of the two rationals is closer to another rational.
AVRational av_add_q(AVRational b, AVRational c) av_const
Add two rationals.