impr: Don't check for overflow every frame
This commit is contained in:
parent
ea5d4ca3ae
commit
ad4e7c3355
@ -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();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user