Skip to content
Merged
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
2 changes: 1 addition & 1 deletion include/boost/charconv/detail/to_chars_integer_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ BOOST_CHARCONV_CONSTEXPR to_chars_result to_chars_128integer_impl(char* first, c
// If the value fits into 64 bits use the other method of processing
if (converted_value < (std::numeric_limits<std::uint64_t>::max)())
{
return to_chars_integer_impl(first, last, static_cast<std::uint64_t>(value));
return to_chars_integer_impl(first, last, static_cast<std::uint64_t>(converted_value));
}

constexpr std::uint32_t ten_9 = UINT32_C(1000000000);
Expand Down
1 change: 1 addition & 0 deletions test/Jamfile
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,4 @@ run github_issue_266.cpp ;
run github_issue_267.cpp ;
run github_issue_280.cpp ;
run github_issue_282.cpp ;
run github_issue_int128_320.cpp ;
60 changes: 60 additions & 0 deletions test/github_issue_int128_320.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Copyright 2026 Matt Borland
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
//
// See: https://github.com/cppalliance/int128/issues/320

#include <boost/charconv.hpp>

#ifdef BOOST_CHARCONV_HAS_INT128

#if defined(__GNUC__) && __GNUC__ == 12
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wstringop-overflow"
#endif

#include <boost/core/lightweight_test.hpp>
#include <string>
#include <cstdlib>

void toChars(char* ptr, char* ptrEnd, boost::int128_type i128)
{
auto r = boost::charconv::to_chars(ptr, ptrEnd, i128);
*r.ptr = '\0';
}

void toChars(char* ptr, char* ptrEnd, boost::uint128_type u128)
{
auto r = boost::charconv::to_chars(ptr, ptrEnd, u128);
*r.ptr = '\0';
}

int main()
{
boost::int128_type i128 = -123;
boost::uint128_type u128 = 123;

std::int64_t ref_value = -123;

for (int i = 1; i < 5; ++i)
{
i128 *= i;
u128 *= static_cast<unsigned>(i);
ref_value *= i;

char buf[64] = {};
toChars(buf, buf + 64, i128);
BOOST_TEST_CSTR_EQ(buf, std::to_string(ref_value).c_str());

toChars(buf, buf + 64, u128);
BOOST_TEST_CSTR_EQ(buf, std::to_string(std::abs(ref_value)).c_str());
};

return boost::report_errors();
}

#else

int main() { return 0; }

#endif