all repos — mgba @ 3f75078174dd7cd7f696b59c3e43bd2842c6359c

mGBA Game Boy Advance Emulator

Util: Factor out gcd code
Vicki Pfau vi@endrift.com
Thu, 23 Jul 2020 21:42:35 -0700
commit

3f75078174dd7cd7f696b59c3e43bd2842c6359c

parent

9eb0c374b3459264d3180f59f033cf9490c0e1ea

2 files changed, 16 insertions(+), 9 deletions(-)

jump to
M include/mgba-util/math.hinclude/mgba-util/math.h

@@ -58,6 +58,19 @@ unsigned lz = clz32(bits - 1);

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
M src/platform/qt/VideoView.cppsrc/platform/qt/VideoView.cpp

@@ -10,6 +10,8 @@

#include "GBAApp.h" #include "LogController.h" +#include <mgba-util/math.h> + #include <QMap> using namespace QGBA;

@@ -396,15 +398,7 @@ safelySet(m_ui.height, m_height);

} 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); }