mirror of https://github.com/mgba-emu/mgba.git
Util: Factor out gcd code
This commit is contained in:
parent
9eb0c374b3
commit
3f75078174
|
@ -58,6 +58,19 @@ static inline uint32_t toPow2(uint32_t bits) {
|
|||
return 1 << (32 - lz);
|
||||
}
|
||||
|
||||
static inline int reduceFraction(int* num, int* den) {
|
||||
int n = *num;
|
||||
int d = *den;
|
||||
while (d != 0) {
|
||||
int temp = n % d;
|
||||
n = d;
|
||||
d = temp;
|
||||
}
|
||||
*num /= n;
|
||||
*den /= n;
|
||||
return n;
|
||||
}
|
||||
|
||||
CXX_GUARD_END
|
||||
|
||||
#endif
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
#include "GBAApp.h"
|
||||
#include "LogController.h"
|
||||
|
||||
#include <mgba-util/math.h>
|
||||
|
||||
#include <QMap>
|
||||
|
||||
using namespace QGBA;
|
||||
|
@ -396,15 +398,7 @@ void VideoView::updateAspectRatio(int width, int height, bool force) {
|
|||
} else {
|
||||
int w = m_width;
|
||||
int h = m_height;
|
||||
// Get greatest common divisor
|
||||
while (w != 0) {
|
||||
int temp = h % w;
|
||||
h = w;
|
||||
w = temp;
|
||||
}
|
||||
int gcd = h;
|
||||
w = m_width / gcd;
|
||||
h = m_height / gcd;
|
||||
reduceFraction(&h, &w);
|
||||
safelySet(m_ui.wratio, w);
|
||||
safelySet(m_ui.hratio, h);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue