-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathgithub_issue_int128_320.cpp
More file actions
60 lines (45 loc) · 1.32 KB
/
github_issue_int128_320.cpp
File metadata and controls
60 lines (45 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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