mirror of
https://github.com/boostorg/charconv.git
synced 2026-02-09 11:02:30 +00:00
Fix compute_float32 for edge cases
This commit is contained in:
@@ -6,22 +6,30 @@
|
||||
#define BOOST_CHARCONV_DETAIL_COMPUTE_FLOAT32_HPP
|
||||
|
||||
#include <boost/charconv/detail/compute_float64.hpp>
|
||||
#include <limits>
|
||||
#include <cstdint>
|
||||
#include <cmath>
|
||||
|
||||
namespace boost { namespace charconv { namespace detail {
|
||||
|
||||
inline float compute_float32(std::int64_t power, std::uint64_t i, bool negative, bool& success) noexcept
|
||||
{
|
||||
const double d = compute_float64(power, i, negative, success);
|
||||
|
||||
if (d > (std::numeric_limits<float>::max)() || d < (std::numeric_limits<float>::lowest)())
|
||||
float return_val;
|
||||
|
||||
if (success)
|
||||
{
|
||||
success = false;
|
||||
return negative ? -0.0F : 0.0F;
|
||||
return_val = static_cast<float>(d);
|
||||
if (std::isinf(return_val))
|
||||
{
|
||||
return_val = negative ? -0.0F : 0.0F;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return_val = negative ? -0.0F : 0.0F;
|
||||
}
|
||||
|
||||
return static_cast<float>(d);
|
||||
return return_val;
|
||||
}
|
||||
|
||||
}}} // Namespaces
|
||||
|
||||
@@ -37,7 +37,7 @@ boost::charconv::from_chars_result boost::charconv::from_chars(char const* first
|
||||
if (!success)
|
||||
{
|
||||
value = 0.0F;
|
||||
r.ec = EINVAL;
|
||||
r.ec = ERANGE;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -65,7 +65,7 @@ boost::charconv::from_chars_result boost::charconv::from_chars(char const* first
|
||||
if (!success)
|
||||
{
|
||||
value = 0.0;
|
||||
r.ec = EINVAL;
|
||||
r.ec = ERANGE;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user