Skip to content

Commit d663bf3

Browse files
committed
Add test set
1 parent 10c60d0 commit d663bf3

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

test/Jamfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,4 @@ run ../examples/charconv.cpp ;
8888
# Github Issues
8989
run github_issue_207.cpp ;
9090
run github_issue_210.cpp ;
91+
run github_issue_221.cpp ;

test/github_issue_221.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright 2025 Matt Borland
2+
// Distributed under the Boost Software License, Version 1.0.
3+
// https://www.boost.org/LICENSE_1_0.txt
4+
//
5+
// See: https://github.com/cppalliance/int128/issues/221
6+
7+
#include <boost/int128.hpp>
8+
#include <boost/core/lightweight_test.hpp>
9+
#include <random>
10+
#include <limits>
11+
12+
constexpr std::size_t N {1024u};
13+
static std::mt19937_64 gen(42);
14+
15+
template <typename T>
16+
void test()
17+
{
18+
constexpr T numerator {0};
19+
20+
using dist_type = std::conditional_t<std::numeric_limits<T>::is_signed, std::int64_t, std::uint64_t>;
21+
std::uniform_int_distribution<dist_type> dist {std::numeric_limits<dist_type>::min(), std::numeric_limits<dist_type>::max()};
22+
23+
for (std::size_t i {0}; i < N; ++i)
24+
{
25+
const auto value {dist(gen)};
26+
BOOST_TEST_EQ(numerator / value, numerator);
27+
}
28+
}
29+
30+
int main()
31+
{
32+
test<boost::int128::int128_t>();
33+
test<boost::int128::uint128_t>();
34+
35+
return boost::report_errors();
36+
}

0 commit comments

Comments
 (0)