Skip to content

Commit fb293d6

Browse files
kimmanbomilot-mirdita
authored andcommitted
[fix] fastSeqIdToBuffer function edge case error fixed.
1 parent f2b68ce commit fb293d6

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

‎src/commons/Util.cpp‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -261,20 +261,22 @@ char* Util::fastSeqIdToBuffer(float seqId, char* buffer) {
261261
*(buffer) = '0';
262262
buffer++;
263263
*(buffer) = '\0';
264+
buffer++;
264265
} else {
266+
const int scaledSeqId = static_cast<int>(seqId * 1000);
265267
*(buffer) = '0';
266268
buffer++;
267269
*(buffer) = '.';
268270
buffer++;
269-
if (seqId < 0.10) {
271+
if (scaledSeqId < 100) {
270272
*(buffer) = '0';
271273
buffer++;
272274
}
273-
if (seqId < 0.01) {
275+
if (scaledSeqId < 10) {
274276
*(buffer) = '0';
275277
buffer++;
276278
}
277-
buffer = Itoa::i32toa_sse2((int)(seqId * 1000), buffer);
279+
buffer = Itoa::i32toa_sse2(scaledSeqId, buffer);
278280
}
279281
return buffer;
280282
}
@@ -737,4 +739,4 @@ std::string SSTR(float x) {
737739
template<>
738740
std::string SSTR(float x, int precision) {
739741
return fmt::format("{:.{}f}", x, precision);
740-
}
742+
}

‎src/commons/Util.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ class Util {
145145
return sign * val;
146146
}
147147

148+
// Writes a null-terminated identity with three fractional digits for values in [0.0f, 1.0f]
149+
// and returns one byte past the terminator.
148150
static char* fastSeqIdToBuffer(float seqId, char* buffer);
149151

150152
static bool isNumber(const std::string& s)

0 commit comments

Comments
 (0)