From a587c5ff743321ad99906c1aec030cad46e6c2df Mon Sep 17 00:00:00 2001 From: paxcut <53811119+paxcut@users.noreply.github.com> Date: Sun, 15 Sep 2024 06:22:35 -0700 Subject: [PATCH] feat: Added a quarter precision (8 bits) button to IEEE 745 tool (#1868) Per discussions on Discord. --- plugins/builtin/romfs/lang/en_US.json | 1 + .../source/content/tools/ieee_decoder.cpp | 20 +++++++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/plugins/builtin/romfs/lang/en_US.json b/plugins/builtin/romfs/lang/en_US.json index 51e2730c6..bc5f9d054 100644 --- a/plugins/builtin/romfs/lang/en_US.json +++ b/plugins/builtin/romfs/lang/en_US.json @@ -636,6 +636,7 @@ "hex.builtin.tools.ieee754.mantissa_size": "Mantissa Size", "hex.builtin.tools.ieee754.result.float": "Floating Point Result", "hex.builtin.tools.ieee754.result.hex": "Hexadecimal Result", + "hex.builtin.tools.ieee754.quarter_precision": "Quarter Precision", "hex.builtin.tools.ieee754.result.title": "Result", "hex.builtin.tools.ieee754.settings.display_mode.detailed": "Detailed", "hex.builtin.tools.ieee754.settings.display_mode.simplified": "Simplified", diff --git a/plugins/builtin/source/content/tools/ieee_decoder.cpp b/plugins/builtin/source/content/tools/ieee_decoder.cpp index ee97bca38..ee83a0b46 100644 --- a/plugins/builtin/source/content/tools/ieee_decoder.cpp +++ b/plugins/builtin/source/content/tools/ieee_decoder.cpp @@ -24,12 +24,7 @@ namespace hex::plugin::builtin { class IEEE754STATICS { public: - IEEE754STATICS() { - value = 0; - exponentBitCount = 8; - mantissaBitCount = 23; - resultFloat = 0; - } + IEEE754STATICS() : value(0), exponentBitCount(8), mantissaBitCount(23), resultFloat(0) {} u128 value; i32 exponentBitCount; @@ -567,6 +562,19 @@ namespace hex::plugin::builtin { auto color = ImGui::GetColorU32(ImGuiCol_ButtonActive); bool needsPop = false; + if (ieee754statics.exponentBitCount == 3 && ieee754statics.mantissaBitCount == 4) { + ImGui::PushStyleColor(ImGuiCol_Button, color); + needsPop = true; + } + if (ImGui::Button("hex.builtin.tools.ieee754.quarter_precision"_lang)) { + ieee754statics.exponentBitCount = 3; + ieee754statics.mantissaBitCount = 4; + inputFieldWidth = 0; + } + if (needsPop) ImGui::PopStyleColor(); + + ImGui::SameLine(); + needsPop = false; if (ieee754statics.exponentBitCount == 5 && ieee754statics.mantissaBitCount == 10) { ImGui::PushStyleColor(ImGuiCol_Button, color); needsPop = true;