From e091287c438747fd99cc6af9171c7f2e5dfbdcee Mon Sep 17 00:00:00 2001 From: "Mr.UNIX" Date: Sun, 24 Mar 2024 22:41:58 +0100 Subject: [PATCH] fix: disable using scientific notation for numbers --- src/bytecode/objects/StackObject.h | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/bytecode/objects/StackObject.h b/src/bytecode/objects/StackObject.h index 5ba7545..73321b5 100644 --- a/src/bytecode/objects/StackObject.h +++ b/src/bytecode/objects/StackObject.h @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -59,14 +60,19 @@ namespace Bytecode { } [[nodiscard]] std::string toString() const { - std::stringstream s; switch (type) { case Boolean: return asBoolean() ? std::string("#true") : std::string("#false"); - case Number: - s << asNumber(); - return s.str(); + case Number: { + std::ostringstream s; + s.precision(std::numeric_limits::digits10); + s << std::fixed << asNumber(); + std::string str = s.str(); + str.erase(str.find_last_not_of('0') + 1); + str.erase(str.find_last_not_of('.') + 1); + return str; + } case String: { std::string string = asString(); return string[0] == '"' && string.back() == '"'