Skip to content

Commit

Permalink
fix: disable using scientific notation for numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
mrunix00 committed Mar 24, 2024
1 parent 4c99e22 commit e091287
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/bytecode/objects/StackObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <cstdint>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <limits>
#include <sstream>
#include <string>
Expand Down Expand Up @@ -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<double>::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() == '"'
Expand Down

0 comments on commit e091287

Please sign in to comment.