Added engineering display mode to calculator
This commit is contained in:
parent
f9039f4b34
commit
73e259d6e7
@ -158,6 +158,24 @@ namespace hex {
|
|||||||
return T(1) << bit_width(T(x - 1));
|
return T(1) << bit_width(T(x - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string toEngineeringString(double value) {
|
||||||
|
constexpr std::array prefixes = { "a", "f", "p", "n", "u", "m", "", "k", "M", "G", "T", "P", "E" };
|
||||||
|
|
||||||
|
int8_t prefixIndex = 6;
|
||||||
|
|
||||||
|
while (prefixIndex != 0 && prefixIndex != 12 && (value >= 1000 || value < 1) && value != 0) {
|
||||||
|
if (value >= 1000) {
|
||||||
|
value /= 1000;
|
||||||
|
prefixIndex++;
|
||||||
|
} else if (value < 1) {
|
||||||
|
value *= 1000;
|
||||||
|
prefixIndex--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return std::to_string(value).substr(0, 5) + prefixes[prefixIndex];
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<u8> readFile(std::string_view path);
|
std::vector<u8> readFile(std::string_view path);
|
||||||
|
|
||||||
#define SCOPE_EXIT(func) ScopeExit TOKEN_CONCAT(scopeGuard, __COUNTER__)([&] { func })
|
#define SCOPE_EXIT(func) ScopeExit TOKEN_CONCAT(scopeGuard, __COUNTER__)([&] { func })
|
||||||
|
@ -195,7 +195,7 @@ namespace hex {
|
|||||||
else
|
else
|
||||||
ImGui::NewLine();
|
ImGui::NewLine();
|
||||||
|
|
||||||
enum class MathDisplayType { Standard, Scientific, Programmer } mathDisplayType;
|
enum class MathDisplayType { Standard, Scientific, Engineering, Programmer } mathDisplayType;
|
||||||
if (ImGui::BeginTabBar("##mathFormatTabBar")) {
|
if (ImGui::BeginTabBar("##mathFormatTabBar")) {
|
||||||
if (ImGui::BeginTabItem("Standard")) {
|
if (ImGui::BeginTabItem("Standard")) {
|
||||||
mathDisplayType = MathDisplayType::Standard;
|
mathDisplayType = MathDisplayType::Standard;
|
||||||
@ -205,6 +205,10 @@ namespace hex {
|
|||||||
mathDisplayType = MathDisplayType::Scientific;
|
mathDisplayType = MathDisplayType::Scientific;
|
||||||
ImGui::EndTabItem();
|
ImGui::EndTabItem();
|
||||||
}
|
}
|
||||||
|
if (ImGui::BeginTabItem("Engineering")) {
|
||||||
|
mathDisplayType = MathDisplayType::Engineering;
|
||||||
|
ImGui::EndTabItem();
|
||||||
|
}
|
||||||
if (ImGui::BeginTabItem("Programmer")) {
|
if (ImGui::BeginTabItem("Programmer")) {
|
||||||
mathDisplayType = MathDisplayType::Programmer;
|
mathDisplayType = MathDisplayType::Programmer;
|
||||||
ImGui::EndTabItem();
|
ImGui::EndTabItem();
|
||||||
@ -242,6 +246,9 @@ namespace hex {
|
|||||||
case MathDisplayType::Scientific:
|
case MathDisplayType::Scientific:
|
||||||
ImGui::Text("%.6Le", this->m_mathHistory[(this->m_mathHistory.size() - 1) - i]);
|
ImGui::Text("%.6Le", this->m_mathHistory[(this->m_mathHistory.size() - 1) - i]);
|
||||||
break;
|
break;
|
||||||
|
case MathDisplayType::Engineering:
|
||||||
|
ImGui::Text("%s", hex::toEngineeringString(this->m_mathHistory[(this->m_mathHistory.size() - 1) - i]).c_str());
|
||||||
|
break;
|
||||||
case MathDisplayType::Programmer:
|
case MathDisplayType::Programmer:
|
||||||
ImGui::Text("0x%llX (%llu)",
|
ImGui::Text("0x%llX (%llu)",
|
||||||
u64(this->m_mathHistory[(this->m_mathHistory.size() - 1) - i]),
|
u64(this->m_mathHistory[(this->m_mathHistory.size() - 1) - i]),
|
||||||
@ -279,6 +286,9 @@ namespace hex {
|
|||||||
case MathDisplayType::Scientific:
|
case MathDisplayType::Scientific:
|
||||||
ImGui::Text("%.6Le", value);
|
ImGui::Text("%.6Le", value);
|
||||||
break;
|
break;
|
||||||
|
case MathDisplayType::Engineering:
|
||||||
|
ImGui::Text("%s", hex::toEngineeringString(value).c_str());
|
||||||
|
break;
|
||||||
case MathDisplayType::Programmer:
|
case MathDisplayType::Programmer:
|
||||||
ImGui::Text("0x%llX (%llu)", u64(value), u64(value));
|
ImGui::Text("0x%llX (%llu)", u64(value), u64(value));
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user