Skip to content

Commit d9456b3

Browse files
authored
fix numeric_limits usage problem on windows caused by the max macro (simdjson#1293)
See https://stackoverflow.com/questions/2789481/problem-calling-stdmax/2789509#2789509
1 parent f195f84 commit d9456b3

File tree

1 file changed

+10
-16
lines changed

1 file changed

+10
-16
lines changed

include/simdjson/generic/numberparsing.h

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -291,23 +291,17 @@ simdjson_really_inline bool compute_float_64(int64_t power, uint64_t i, bool neg
291291
// one digit.
292292
static bool parse_float_fallback(const uint8_t *ptr, double *outDouble) {
293293
*outDouble = simdjson::internal::from_chars((const char *)ptr);
294-
// We do not accept infinite values. Detecting finite values in a portable manner is ridiculously hard.
295-
//
296-
// Next line would be nice but if fails under Visual Studio with error C2589: '(': illegal token on right side of '::'
297-
// despite the fact that we have '#include <limits>' above.
298-
// if ((*outDouble > std::numeric_limits<double>::max()) || (*outDouble < std::numeric_limits<double>::lowest())) {
299-
//
300-
// Next line would be better but it mysteriously fails under legacy/old libc++ libraries.
301-
// See https://github.com/simdjson/simdjson/issues/1286
302-
//if (!std::isfinite(*outDouble)) {
303-
//
304-
// So we use the following that ought to work under all systems.
305-
// (Note that I also tried hexadecimal floats but it failed under some systems too.)
294+
// We do not accept infinite values.
295+
296+
// Detecting finite values in a portable manner is ridiculously hard, ideally
297+
// we would want to do:
298+
// return !std::isfinite(*outDouble);
299+
// but that mysteriously fails under legacy/old libc++ libraries, see
300+
// https://github.com/simdjson/simdjson/issues/1286
306301
//
307-
if ((*outDouble > 1.7976931348623157E+308) || (*outDouble < -1.7976931348623157E+308)) {
308-
return false;
309-
}
310-
return true;
302+
// Therefore, fall back to this solution (the extra parens are there
303+
// to handle that max may be a macro on windows).
304+
return !(*outDouble > (std::numeric_limits<double>::max)() || *outDouble < std::numeric_limits<double>::lowest());
311305
}
312306

313307
// check quickly whether the next 8 chars are made of digits

0 commit comments

Comments
 (0)