Exponents dont use unicode anymore, so that text is aligned properly

This commit is contained in:
Yousef Khadadeh 2025-09-23 15:05:14 +03:00
parent 29d7f1f6b2
commit 9d39f4d380
2 changed files with 56 additions and 29 deletions

View file

@ -326,7 +326,7 @@ namespace FixedPoint {
val = T(str);
}
std::string display_int_str(size_t scientificNotationDigits, bool fancy = false) const {
std::string display_int_str(size_t scientificNotationDigits, bool fancy = false, std::string* exponentStr = nullptr) const {
if(scientificNotationDigits <= 0) {
T shiftedVal = val >> bitFractionCount;
return shiftedVal.str();
@ -339,16 +339,18 @@ namespace FixedPoint {
size_t exponent = a.size() - (isNegative ? 2 : 1);
a = a.substr(0, scientificNotationDigits + (isNegative ? 2 : 1));
a.insert(a.begin() + (isNegative ? 2 : 1), '.');
if(fancy) {
for(;;) {
if(a.back() == '0') {
a.pop_back();
continue;
}
else if(a.back() == '.')
a.pop_back();
break;
for(;;) {
if(a.back() == '0') {
a.pop_back();
continue;
}
else if(a.back() == '.')
a.pop_back();
break;
}
if(exponentStr)
*exponentStr = std::to_string(exponent);
else if(fancy) {
a += "×10";
std::string expStr = std::to_string(exponent);
for(char eChar : expStr) {