-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathgithub_issue_221.cpp
More file actions
36 lines (29 loc) · 946 Bytes
/
github_issue_221.cpp
File metadata and controls
36 lines (29 loc) · 946 Bytes
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
// Copyright 2025 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/221
#include <boost/int128.hpp>
#include <boost/core/lightweight_test.hpp>
#include <random>
#include <limits>
constexpr std::size_t N {1024u};
static std::mt19937_64 gen(42);
template <typename T>
void test()
{
constexpr T numerator {0};
using dist_type = std::conditional_t<std::numeric_limits<T>::is_signed, std::int64_t, std::uint64_t>;
std::uniform_int_distribution<dist_type> dist {std::numeric_limits<dist_type>::min(), std::numeric_limits<dist_type>::max()};
for (std::size_t i {0}; i < N; ++i)
{
const auto value {dist(gen)};
BOOST_TEST_EQ(numerator / value, numerator);
}
}
int main()
{
test<boost::int128::int128_t>();
test<boost::int128::uint128_t>();
return boost::report_errors();
}