Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ function(boost_json_setup_properties target)
Boost::align
Boost::assert
Boost::config
Boost::charconv
Boost::container
Boost::container_hash
Boost::core
Expand Down
1 change: 1 addition & 0 deletions build.jam
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ using boost-pretty-printers ;
constant boost_dependencies :
/boost/align//boost_align
/boost/assert//boost_assert
/boost/charconv//boost_charconv
/boost/config//boost_config
/boost/container//boost_container
/boost/container_hash//boost_container_hash
Expand Down
1 change: 1 addition & 0 deletions build/Jamfile
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ project
<toolset>msvc:<define>_SCL_SECURE_NO_WARNINGS
: usage-requirements
<library>/boost/container//boost_container/<warnings-as-errors>off
<library>/boost/charconv//boost_charconv/<warnings-as-errors>off
<define>BOOST_JSON_NO_LIB=1
: source-location ../src
;
Expand Down
13 changes: 6 additions & 7 deletions include/boost/json/detail/format.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@
#ifndef BOOST_JSON_DETAIL_FORMAT_HPP
#define BOOST_JSON_DETAIL_FORMAT_HPP

#include <boost/charconv/limits.hpp>
#include <boost/json/detail/config.hpp>

namespace boost {
namespace json {
namespace detail {

int constexpr max_number_chars =
1 + // '-'
19 + // unsigned 64-bit mantissa
1 + // 'e'
1 + // '-'
5; // unsigned 16-bit exponent
constexpr std::size_t max_number_chars =
boost::charconv::limits<double>::max_chars;

BOOST_JSON_DECL
unsigned
Expand All @@ -33,7 +32,7 @@ format_int64(
char* dest, int64_t i) noexcept;

BOOST_JSON_DECL
unsigned
std::size_t
format_double(
char* dest, double d, bool allow_infinity_and_nan = false) noexcept;

Expand Down
54 changes: 50 additions & 4 deletions include/boost/json/detail/impl/format.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
#ifndef BOOST_JSON_DETAIL_IMPL_FORMAT_IPP
#define BOOST_JSON_DETAIL_IMPL_FORMAT_IPP

#include <boost/json/detail/ryu/ryu.hpp>
#include <boost/charconv/to_chars.hpp>
#include <cmath>
#include <cstring>

namespace boost {
Expand Down Expand Up @@ -110,12 +111,57 @@ format_int64(
return 1 + format_uint64(dest, ui);
}

unsigned
std::size_t
format_double(
char* dest, double d, bool allow_infinity_and_nan) noexcept
{
return static_cast<int>(
ryu::d2s_buffered_n(d, dest, allow_infinity_and_nan));
if( std::isfinite(d) )
{
boost::charconv::to_chars_result result = boost::charconv::to_chars(
dest,
dest + detail::max_number_chars,
d,
boost::charconv::chars_format::scientific);
BOOST_ASSERT( result.ec == std::errc() );
return result.ptr - dest;
}

if (allow_infinity_and_nan)
{
if( std::isnan(d) )
{
std::memcpy(dest, "NaN", 3);
return 3;
}
else if( std::signbit(d) )
{
BOOST_ASSERT( std::isinf(d) );
std::memcpy(dest, "-Infinity", 9);
return 9;
}
else
{
std::memcpy(dest, "Infinity", 8);
return 8;
}
}

if( std::isnan(d) )
{
std::memcpy(dest, "null", 4);
return 4;
}
else if( std::signbit(d) )
{
BOOST_ASSERT( std::isinf(d) );
std::memcpy(dest, "-1e99999", 8);
return 8;
}
else
{
std::memcpy(dest, "1e99999", 7);
return 7;
}
}

} // detail
Expand Down
144 changes: 0 additions & 144 deletions include/boost/json/detail/ryu/detail/common.hpp

This file was deleted.

Loading
Loading