FFmpeg
Loading...
Searching...
No Matches
rational64.h
Go to the documentation of this file.
1/*
2 * 64-bit rational numbers
3 * Copyright (c) 2025 Niklas Haas
4 * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23/**
24 * @file
25 * @ingroup lavu_math_rational
26 * 64-bit extension of AVRational.
27 * @author Niklas Haas
28 */
29
30#ifndef SWSCALE_RATIONAL64_H
31#define SWSCALE_RATIONAL64_H
32
33#include <stdint.h>
34#include <limits.h>
35
37
38/**
39 * @defgroup AVRational64
40 * 64-bit extension of AVRational
41 *
42 * Offers a 64-bit extended version of AVRational. This is less efficient (and
43 * may revolve around emulated 128-bit multiplications internally), but allows
44 * to represent a much larger range of rational numbers without overflow.
45 *
46 * @{
47 */
48
49/**
50 * 64-bit Rational number (pair of numerator and denominator).
51 */
52typedef struct AVRational64 {
53 int64_t num; ///< Numerator
54 int64_t den; ///< Denominator
56
57/**
58 * Create an AVRational64.
59 *
60 * Useful for compilers that do not support compound literals.
61 *
62 * @note The return value is not reduced.
63 */
64static inline AVRational64 av_make_q64(int64_t num, int64_t den)
65{
66 AVRational64 r = { num, den };
67 return r;
68}
69
70/**
71 * Compare two 64-bit rationals.
72 *
73 * @param a First rational
74 * @param b Second rational
75 *
76 * @return One of the following values:
77 * - 0 if `a == b`
78 * - 1 if `a > b`
79 * - -1 if `a < b`
80 * - `INT_MIN` if one of the values is of the form `0 / 0`
81 */
83
84/**
85 * Convert an AVRational64 to a `double`.
86 * @param a AVRational64 to convert
87 * @return `a` in floating-point form
88 * @see av_d2q()
89 */
90static inline double av_q2d_64(AVRational64 a){
91 return a.num / (double) a.den;
92}
93
94/**
95 * Multiply two 64-bit rationals.
96 * @param b First multiplicant
97 * @param c Second multiplicant
98 * @return b*c
99 */
101
102/**
103 * Divide one 64-bit rational by another.
104 * @param b Dividend
105 * @param c Divisor
106 * @return b/c
107 */
109
110/**
111 * Add two 64-bit rationals.
112 * @param b First addend
113 * @param c Second addend
114 * @return b+c
115 */
117
118/**
119 * Subtract one 64-bit rational from another.
120 * @param b Minuend
121 * @param c Subtrahend
122 * @return b-c
123 */
125
126/**
127 * Invert a 64-bit rational.
128 * @param q value
129 * @return 1 / q
130 */
132{
133 AVRational64 r = { q.den, q.num };
134 return r;
135}
136
137/**
138 * @}
139 */
140
141#endif /* SWSCALE_RATIONAL64_H */
long long int64_t
Definition coverity.c:34
AVRational64 av_div_q64(AVRational64 b, AVRational64 c) av_const
Divide one 64-bit rational by another.
Definition rational64.c:130
AVRational64 av_mul_q64(AVRational64 b, AVRational64 c) av_const
Multiply two 64-bit rationals.
Definition rational64.c:124
int av_cmp_q64(AVRational64 a, AVRational64 b)
Compare two 64-bit rationals.
Definition rational64.c:108
static av_always_inline AVRational64 av_inv_q64(AVRational64 q)
Invert a 64-bit rational.
Definition rational64.h:131
AVRational64 av_add_q64(AVRational64 b, AVRational64 c) av_const
Add two 64-bit rationals.
Definition rational64.c:135
static double av_q2d_64(AVRational64 a)
Convert an AVRational64 to a double.
Definition rational64.h:90
AVRational64 av_sub_q64(AVRational64 b, AVRational64 c) av_const
Subtract one 64-bit rational from another.
Definition rational64.c:141
static AVRational64 av_make_q64(int64_t num, int64_t den)
Create an AVRational64.
Definition rational64.h:64
int a
#define r
Definition input.c:42
#define b
Definition input.c:43
Macro definitions for various function/variable attributes.
#define av_always_inline
Definition attributes.h:72
#define av_const
Definition attributes.h:111
64-bit Rational number (pair of numerator and denominator).
Definition rational64.h:52
int64_t num
Numerator.
Definition rational64.h:53
int64_t den
Denominator.
Definition rational64.h:54
static double c[64]