diff options
| author | Yong He <yonghe@outlook.com> | 2023-02-07 18:36:35 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-02-07 18:36:35 -0800 |
| commit | 4be623c52a6518eb86756a0369706c1d6670f6bb (patch) | |
| tree | c24f54e34db9f1f02c2d51808b15121eba9195a9 /source/slang/slang-emit-source-writer.cpp | |
| parent | 101f164b036d0c1c012243df69179559b6f40fb8 (diff) | |
Arithmetic simplifications and more IR clean up logic. (#2632)
Diffstat (limited to 'source/slang/slang-emit-source-writer.cpp')
| -rw-r--r-- | source/slang/slang-emit-source-writer.cpp | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/source/slang/slang-emit-source-writer.cpp b/source/slang/slang-emit-source-writer.cpp index bed9a2dbc..7692bd0ec 100644 --- a/source/slang/slang-emit-source-writer.cpp +++ b/source/slang/slang-emit-source-writer.cpp @@ -247,8 +247,21 @@ void SourceWriter::emit(double value) stream.setf(std::ios::fixed, std::ios::floatfield); stream.precision(20); stream << value; - - emit(stream.str().c_str()); + auto str = stream.str(); + auto slice = UnownedStringSlice(str.c_str()); + // Remove redundant trailing 0s. + if (slice.end() > slice.begin()) + { + auto lastChar = slice.end() - 1; + while (lastChar > slice.begin() && *lastChar == '0') + lastChar--; + if (*lastChar == '.') + lastChar++; + if (lastChar > slice.end() - 1) + lastChar = slice.end() - 1; + slice = slice.subString(0, lastChar - slice.begin() + 1); + } + emit(slice); } void SourceWriter::advanceToSourceLocationIfValid(const SourceLoc& sourceLocation) |
