1
0
mirror of synced 2025-02-26 14:21:39 +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("A", ImGuiDataType_U64, &a) || hasChanged;
hasChanged = ImGui::InputScalar("B", ImGuiDataType_U64, &b) || hasChanged; hasChanged = ImGui::InputScalar("B", ImGuiDataType_U64, &b) || hasChanged;
// Detect overflow // Update results when input changed
const u64 multiplicationResult = a * b; if (hasChanged) {
if (a != 0 && multiplicationResult / a != b) {
gcdResult = 0;
lcmResult = 0;
p = 0;
q = 0;
overflow = true; // Detect overflow
} else { const u64 multiplicationResult = a * b;
if (hasChanged) { if (a != 0 && multiplicationResult / a != b) {
gcdResult = 0;
lcmResult = 0;
p = 0;
q = 0;
overflow = true;
} else {
gcdResult = std::gcd<i128, i128>(a, b); gcdResult = std::gcd<i128, i128>(a, b);
lcmResult = std::lcm<i128, i128>(a, b); lcmResult = std::lcm<i128, i128>(a, b);
std::tie(p, q) = extendedGcd(a, b); std::tie(p, q) = extendedGcd(a, b);
}
overflow = false; overflow = false;
}
} }
ImGui::Separator(); ImGui::Separator();