common: add mp_lcm helper

This commit is contained in:
Niklas Haas 2023-10-19 17:58:28 +02:00 committed by Niklas Haas
parent 227e1fef43
commit d67b0022aa
2 changed files with 8 additions and 0 deletions

View File

@ -21,6 +21,7 @@
#include <libavutil/common.h>
#include <libavutil/error.h>
#include <libavutil/mathematics.h>
#include "mpv_talloc.h"
#include "misc/bstr.h"
@ -404,3 +405,9 @@ uint32_t mp_round_next_power_of_2(uint32_t v)
int l = mp_log2(v) + 1;
return l == 32 ? 0 : (uint32_t)1 << l;
}
int mp_lcm(int x, int y)
{
assert(x && y);
return x * (y / av_gcd(x, y));
}

View File

@ -113,6 +113,7 @@ void mp_rect_rotate(struct mp_rect *rc, int w, int h, int rotation);
unsigned int mp_log2(uint32_t v);
uint32_t mp_round_next_power_of_2(uint32_t v);
int mp_lcm(int x, int y);
int mp_snprintf_cat(char *str, size_t size, const char *format, ...)
PRINTF_ATTRIBUTE(3, 4);