mirror of
https://github.com/boostorg/charconv.git
synced 2026-02-08 22:52:27 +00:00
Use integer to_chars if in integer range with general formatting
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <cstdint>
|
||||
#include <cmath>
|
||||
|
||||
namespace boost { namespace charconv { namespace detail {
|
||||
|
||||
@@ -292,8 +293,21 @@ boost::charconv::to_chars_result boost::charconv::to_chars(char* first, char* la
|
||||
|
||||
if (fmt == boost::charconv::chars_format::general)
|
||||
{
|
||||
auto* ptr = jkj::floff::floff<jkj::floff::main_cache_full, jkj::floff::extended_cache_long>(value, std::numeric_limits<double>::max_digits10 - 1, first, fmt);
|
||||
return { ptr, 0 };
|
||||
const auto abs_value = std::abs(value);
|
||||
if (abs_value < 1E17 && abs_value > 1E-17)
|
||||
{
|
||||
if (value < 0)
|
||||
{
|
||||
*first = '-';
|
||||
++first;
|
||||
}
|
||||
return boost::charconv::to_chars(first, last, static_cast<std::uint64_t>(abs_value));
|
||||
}
|
||||
else
|
||||
{
|
||||
auto* ptr = jkj::floff::floff<jkj::floff::main_cache_full, jkj::floff::extended_cache_long>(value, std::numeric_limits<double>::max_digits10 - 1, first, fmt);
|
||||
return { ptr, 0 };
|
||||
}
|
||||
}
|
||||
else if (fmt == boost::charconv::chars_format::scientific)
|
||||
{
|
||||
@@ -308,11 +322,14 @@ boost::charconv::to_chars_result boost::charconv::to_chars(char* first, char* la
|
||||
auto* ptr = jkj::floff::floff<jkj::floff::main_cache_full, jkj::floff::extended_cache_long>(value, precision, first, fmt);
|
||||
return { ptr, 0 };
|
||||
}
|
||||
/*
|
||||
else
|
||||
{
|
||||
std::snprintf( first, last - first, "%.*g", std::numeric_limits<double>::max_digits10, value );
|
||||
return { first + std::strlen(first), 0 };
|
||||
}
|
||||
*/
|
||||
return { first + std::strlen(first), 0 };
|
||||
}
|
||||
|
||||
boost::charconv::to_chars_result boost::charconv::to_chars( char* first, char* last, long double value ) noexcept
|
||||
|
||||
Reference in New Issue
Block a user