diff --git a/components/interpreter/miscopcodes.hpp b/components/interpreter/miscopcodes.hpp index 72cc1439d2..0b49b3c248 100644 --- a/components/interpreter/miscopcodes.hpp +++ b/components/interpreter/miscopcodes.hpp @@ -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; diff --git a/components/misc/messageformatparser.cpp b/components/misc/messageformatparser.cpp index 4b77a9da7a..649d0184d3 100644 --- a/components/misc/messageformatparser.cpp +++ b/components/misc/messageformatparser.cpp @@ -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]); } } } diff --git a/components/misc/messageformatparser.hpp b/components/misc/messageformatparser.hpp index dc7ce09884..eeef29234d 100644 --- a/components/misc/messageformatparser.hpp +++ b/components/misc/messageformatparser.hpp @@ -15,11 +15,13 @@ namespace Misc FloatPlaceholder }; - enum Notation + enum class Notation { - FixedNotation, - ScientificNotation, - ShortestNotation + Fixed, + Scientific, + Shortest, + HexUpper, + HexLower }; virtual void visitedPlaceholder(