1
0
mirror of synced 2024-11-13 18:50:53 +01:00

impr: Don't check for overflow every frame

This commit is contained in:
WerWolv 2023-11-08 12:46:47 +01:00
parent ea5d4ca3ae
commit ad4e7c3355

View File

@ -2102,23 +2102,25 @@ namespace hex::plugin::builtin {
hasChanged = ImGui::InputScalar("A", ImGuiDataType_U64, &a) || hasChanged;
hasChanged = ImGui::InputScalar("B", ImGuiDataType_U64, &b) || hasChanged;
// Detect overflow
const u64 multiplicationResult = a * b;
if (a != 0 && multiplicationResult / a != b) {
gcdResult = 0;
lcmResult = 0;
p = 0;
q = 0;
// Update results when input changed
if (hasChanged) {
overflow = true;
} else {
if (hasChanged) {
// Detect overflow
const u64 multiplicationResult = a * b;
if (a != 0 && multiplicationResult / a != b) {
gcdResult = 0;
lcmResult = 0;
p = 0;
q = 0;
overflow = true;
} else {
gcdResult = std::gcd<i128, i128>(a, b);
lcmResult = std::lcm<i128, i128>(a, b);
std::tie(p, q) = extendedGcd(a, b);
}
overflow = false;
overflow = false;
}
}
ImGui::Separator();