Fixed build on Linux and macOS that was failing because of using std::to_chars and std::from_chars with floating-point values.

The old version of GCC and Clang support only integers to be passed to std::to_chars and std::from_chars. macOS older version of Clang doesn't support std::from_chars at all. So for Linux and macOS, it was replaced std::from_chars with strtod and temporarily was replace std::to_chars with snprintf.
This commit is contained in:
Lukáš Hejl 2021-09-07 07:33:57 +02:00
parent 428509ac00
commit 0bc77cef3e
2 changed files with 16 additions and 0 deletions

View file

@ -71,9 +71,16 @@ const char* GCodeReader::parse_line_internal(const char *ptr, const char *end, G
}
if (axis != NUM_AXES_WITH_UNKNOWN) {
// Try to parse the numeric value.
#ifdef WIN32
double v;
auto [pend, ec] = std::from_chars(++ c, end, v);
if (pend != c && is_end_of_word(*pend)) {
#else
// The older version of GCC and Clang support std::from_chars just for integers, so strtod we used it instead.
char *pend = nullptr;
double v = strtod(++ c, &pend);
if (pend != nullptr && is_end_of_word(*pend)) {
#endif
// The axis value has been parsed correctly.
if (axis != UNKNOWN_AXIS)
gline.m_axis[int(axis)] = float(v);