Skip to content

Commit

Permalink
Read double values correctly and store diskLoc as double
Browse files Browse the repository at this point in the history
  • Loading branch information
oyvindln committed Jan 15, 2024
1 parent fb9289c commit aad4190
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
14 changes: 12 additions & 2 deletions tools/library/tbc/jsonio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
#include "jsonio.h"

#include <limits>
#if ((defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || __cplusplus >= 201703L)
#include <charconv>
#else
#include <sstream>
#endif

// Recognise JSON space characters
static bool isAsciiSpace(char c)
Expand Down Expand Up @@ -332,8 +337,13 @@ void JsonReader::readNumber(double &value)
}
}

// XXX In C++17 we could use std::from_chars instead, which is slightly more efficient
value = std::stod(buf);
#if ((defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || __cplusplus >= 201703L)
// Use the faster C++17 method if available.
std::from_chars(buf.data(), buf.data() + buf.size(), value);
#else
std::istringstream(buf) >> value;
#endif


// We've read one character beyond the end of the number (there's no way to
// tell where the end is otherwise), so we must unget the last char
Expand Down
2 changes: 1 addition & 1 deletion tools/library/tbc/lddecodemetadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ class LdDecodeMetaData
DropOuts dropOuts;
bool pad = false;

qint32 diskLoc = -1;
double diskLoc = -1;
qint64 fileLoc = -1;
qint32 decodeFaults = -1;
qint32 efmTValues = -1;
Expand Down

0 comments on commit aad4190

Please sign in to comment.