diff --git a/include/fast_float/float_common.h b/include/fast_float/float_common.h index 2b8a528..e14c7dc 100644 --- a/include/fast_float/float_common.h +++ b/include/fast_float/float_common.h @@ -1132,13 +1132,10 @@ template constexpr uint64_t int_luts::min_safe_u64[]; template fastfloat_really_inline constexpr uint8_t ch_to_digit(UC c) { + // wchar_t and char can be signed, so we need to be careful. using UnsignedUC = typename std::make_unsigned::type; - auto uc = static_cast(c); - // For types larger than one byte, we need to force an index with sentinel - // value (using index zero because that is easiest) if any byte other than - // the low byte is non-zero. - auto mask = static_cast(-((uc & ~0xFFull) == 0)); - return int_luts<>::chdigit[static_cast(uc & mask)]; + return int_luts<>::chdigit[static_cast(static_cast(c) + & static_cast(-((static_cast(c) & ~0xFFull) == 0)))]; } fastfloat_really_inline constexpr size_t max_digits_u64(int base) {