summaryrefslogtreecommitdiff
path: root/source/slang/slang-emit-source-writer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/slang/slang-emit-source-writer.cpp')
-rw-r--r--source/slang/slang-emit-source-writer.cpp17
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)