diff --git a/include/boost/charconv/detail/ryu/generic_128.hpp b/include/boost/charconv/detail/ryu/generic_128.hpp index 80a3ec0..a0b7b9a 100644 --- a/include/boost/charconv/detail/ryu/generic_128.hpp +++ b/include/boost/charconv/detail/ryu/generic_128.hpp @@ -494,10 +494,10 @@ static BOOST_CHARCONV_CXX14_CONSTEXPR boost::uint128_type mulShift(const boost::uint128_type m, const uint64_t* const mul, const int32_t j) noexcept { BOOST_CHARCONV_ASSERT(j > 128); - uint64_t a[2]; + uint64_t a[2] {}; a[0] = (uint64_t) m; a[1] = (uint64_t) (m >> 64); - uint64_t result[4]; + uint64_t result[4] {}; mul_128_256_shift(a, mul, j, 0, result); return (((boost::uint128_type) result[1]) << 64) | result[0]; } diff --git a/include/boost/charconv/detail/ryu/ryu_generic_128.hpp b/include/boost/charconv/detail/ryu/ryu_generic_128.hpp index 0abcc90..fce6493 100644 --- a/include/boost/charconv/detail/ryu/ryu_generic_128.hpp +++ b/include/boost/charconv/detail/ryu/ryu_generic_128.hpp @@ -259,7 +259,7 @@ struct floating_decimal_128 generic_binary_to_decimal( // Round even if the exact numbers is .....50..0. lastRemovedDigit = 4; } - // We need to take vr+1 if vr is outside bounds or we need to round up. + // We need to take vr+1 if vr is outside bounds, or we need to round up. output = vr + (boost::uint128_type)((vr == vm && (!acceptBounds || !vmIsTrailingZeros)) || (lastRemovedDigit >= 5)); const int32_t exp = e10 + removed; @@ -272,21 +272,30 @@ struct floating_decimal_128 generic_binary_to_decimal( return {output, exp, ieeeSign}; } -static inline int copy_special_str(char * const result, const struct floating_decimal_128 fd) noexcept +static inline int copy_special_str(char* result, const struct floating_decimal_128 fd) noexcept { - // TODO(mborland): match the handling of the other NaNs and infinities in the library - if (fd.mantissa) - { - memcpy(result, "NaN", 3); - return 3; - } if (fd.sign) { - result[0] = '-'; + *result = '-'; + ++result; } - memcpy(result + fd.sign, "Infinity", 8); - return fd.sign + 8; + if (fd.mantissa) + { + if (fd.sign) + { + memcpy(result, "nan(ind)", 8); + return 9; + } + else + { + memcpy(result, "nan", 3); + return 4; + } + } + + memcpy(result, "inf", 3); + return (int)fd.sign + 3; } // Converts the given decimal floating point number to a string, writing to result, and returning @@ -296,7 +305,7 @@ static inline int copy_special_str(char * const result, const struct floating_de // Maximal char buffer requirement: // sign + mantissa digits + decimal dot + 'E' + exponent sign + exponent digits // = 1 + 39 + 1 + 1 + 1 + 10 = 53 -int generic_to_chars(const struct floating_decimal_128 v, char* const result) noexcept +int generic_to_chars(const struct floating_decimal_128 v, char* result) noexcept { if (v.exponent == fd128_exceptional_exponent) {