Implement missing hex float format options

This commit is contained in:
Evil Eye 2025-08-21 22:00:00 +02:00
parent 59753d8b8e
commit d66b86f2c9
3 changed files with 30 additions and 11 deletions

View File

@ -57,12 +57,12 @@ namespace Interpreter
float value = mRuntime[0].mFloat;
mRuntime.pop();
if (notation == FixedNotation)
if (notation == Notation::Fixed)
{
out << std::fixed << value;
mFormattedMessage += out.str();
}
else if (notation == ShortestNotation)
else if (notation == Notation::Shortest)
{
out << value;
std::string standard = out.str();
@ -75,6 +75,17 @@ namespace Interpreter
mFormattedMessage += standard.length() < scientific.length() ? standard : scientific;
}
// TODO switch to std::format so the precision argument applies to these two
else if (notation == Notation::HexLower)
{
out << std::hexfloat << value;
mFormattedMessage += out.str();
}
else if (notation == Notation::HexUpper)
{
out << std::uppercase << std::hexfloat << value;
mFormattedMessage += out.str();
}
else
{
out << std::scientific << value;

View File

@ -56,15 +56,21 @@ namespace Misc
if (i < m.size())
{
if (m[i] == 'S' || m[i] == 's')
visitedPlaceholder(StringPlaceholder, pad, width, precision, FixedNotation);
visitedPlaceholder(StringPlaceholder, pad, width, precision, Notation::Fixed);
else if (m[i] == 'd' || m[i] == 'i')
visitedPlaceholder(IntegerPlaceholder, pad, width, precision, FixedNotation);
visitedPlaceholder(IntegerPlaceholder, pad, width, precision, Notation::Fixed);
else if (m[i] == 'f' || m[i] == 'F')
visitedPlaceholder(FloatPlaceholder, pad, width, precision, FixedNotation);
visitedPlaceholder(FloatPlaceholder, pad, width, precision, Notation::Fixed);
else if (m[i] == 'e' || m[i] == 'E')
visitedPlaceholder(FloatPlaceholder, pad, width, precision, ScientificNotation);
visitedPlaceholder(FloatPlaceholder, pad, width, precision, Notation::Scientific);
else if (m[i] == 'g' || m[i] == 'G')
visitedPlaceholder(FloatPlaceholder, pad, width, precision, ShortestNotation);
visitedPlaceholder(FloatPlaceholder, pad, width, precision, Notation::Shortest);
else if (m[i] == 'a')
visitedPlaceholder(FloatPlaceholder, pad, width, precision, Notation::HexLower);
else if (m[i] == 'A')
visitedPlaceholder(FloatPlaceholder, pad, width, precision, Notation::HexUpper);
else
visitedCharacter(m[i]);
}
}
}

View File

@ -15,11 +15,13 @@ namespace Misc
FloatPlaceholder
};
enum Notation
enum class Notation
{
FixedNotation,
ScientificNotation,
ShortestNotation
Fixed,
Scientific,
Shortest,
HexUpper,
HexLower
};
virtual void visitedPlaceholder(