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
8 changes: 4 additions & 4 deletions include/boost/int128/cstdlib.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@
namespace boost {
namespace int128 {

struct u128div_t
BOOST_INT128_EXPORT struct u128div_t
{
uint128_t quot;
uint128_t rem;
};

struct i128div_t
BOOST_INT128_EXPORT struct i128div_t
{
int128_t quot;
int128_t rem;
};

constexpr u128div_t div(const uint128_t x, const uint128_t y) noexcept
BOOST_INT128_EXPORT constexpr u128div_t div(const uint128_t x, const uint128_t y) noexcept
{
if (BOOST_INT128_UNLIKELY(x == 0U || y == 0U))
{
Expand Down Expand Up @@ -54,7 +54,7 @@ constexpr u128div_t div(const uint128_t x, const uint128_t y) noexcept
}
}

constexpr i128div_t div(const int128_t x, const int128_t y) noexcept
BOOST_INT128_EXPORT constexpr i128div_t div(const int128_t x, const int128_t y) noexcept
{
if (BOOST_INT128_UNLIKELY(x == 0 || y == 0))
{
Expand Down
9 changes: 9 additions & 0 deletions module/Jamfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,12 @@ project
obj int128 : int128.cxx : <toolset>msvc:<cxxflags>-interface ;

run quick_test.cpp int128 : : : <dependency>int128 ;
run ../test/test_bit.cpp int128 : : : <dependency>int128 ;
run ../test/test_div.cpp int128 : : : <dependency>int128 ;
run ../test/test_gcd_lcm.cpp int128 : : : <dependency>int128 ;
run ../test/test_i128.cpp int128 : : : <dependency>int128 ;
run ../test/test_i128_no_sign_conv.cpp int128 : : : <dependency>int128 ;
run ../test/test_limits_i128.cpp : : : <dependency>int128 ;
run ../test/test_limits_u128.cpp : : : <dependency>int128 ;
run ../test/test_literals.cpp : : : <dependency>int128 ;
run ../test/test_midpoint.cpp : : : <dependency>int128 ;
11 changes: 10 additions & 1 deletion test/test_bit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,19 @@
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt

#include <boost/core/lightweight_test.hpp>

#ifndef BOOST_INT128_BUILD_MODULE

#include <boost/int128/int128.hpp>
#include <boost/int128/bit.hpp>
#include <boost/int128/iostream.hpp>
#include <boost/core/lightweight_test.hpp>

#else

import boost.int128;

#endif

void test_has_single_bit()
{
Expand Down
29 changes: 20 additions & 9 deletions test/test_div.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,18 @@
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt

#include <boost/int128.hpp>
#ifndef BOOST_INT128_BUILD_MODULE

#include <boost/int128/int128.hpp>
#include <boost/int128/cstdlib.hpp>
#include <boost/int128/iostream.hpp>

#else

import boost.int128;

#endif

#include <boost/core/lightweight_test.hpp>
#include <random>

Expand Down Expand Up @@ -48,22 +59,22 @@ void test_unsigned_div()
BOOST_INT128_UNREACHABLE; // LCOV_EXCL_LINE
}

const auto div_res {div(lhs, rhs)};
const auto div_res {boost::int128::div(lhs, rhs)};
BOOST_TEST_EQ(div_res.quot, lhs / rhs);
BOOST_TEST_EQ(div_res.rem, lhs % rhs);

const auto inv_div_res {div(rhs, lhs)};
const auto inv_div_res {boost::int128::div(rhs, lhs)};
BOOST_TEST_EQ(inv_div_res.quot, rhs / lhs);
BOOST_TEST_EQ(inv_div_res.rem, rhs % lhs);
}

uint128_t lhs {dist(rng), dist(rng)};
uint128_t zero {dist(rng) * 0U, dist(rng) * 0U};
const auto lhs_num {div(lhs, zero)};
const auto lhs_num {boost::int128::div(lhs, zero)};
BOOST_TEST_EQ(lhs_num.quot, 0U);
BOOST_TEST_EQ(lhs_num.rem, 0U);

const auto lhs_denom {div(zero, lhs)};
const auto lhs_denom {boost::int128::div(zero, lhs)};
BOOST_TEST_EQ(lhs_denom.quot, 0U);
BOOST_TEST_EQ(lhs_denom.rem, 0U);
}
Expand Down Expand Up @@ -98,22 +109,22 @@ void test_signed_div()
BOOST_INT128_UNREACHABLE; // LCOV_EXCL_LINE
}

const auto div_res {div(lhs, rhs)};
const auto div_res {boost::int128::div(lhs, rhs)};
BOOST_TEST_EQ(div_res.quot, lhs / rhs);
BOOST_TEST_EQ(div_res.rem, lhs % rhs);

const auto inv_div_res {div(rhs, lhs)};
const auto inv_div_res {boost::int128::div(rhs, lhs)};
BOOST_TEST_EQ(inv_div_res.quot, rhs / lhs);
BOOST_TEST_EQ(inv_div_res.rem, rhs % lhs);
}

int128_t lhs {idist(rng), dist(rng)};
int128_t zero {idist(rng) * 0, dist(rng) * 0U};
const auto lhs_num {div(lhs, zero)};
const auto lhs_num {boost::int128::div(lhs, zero)};
BOOST_TEST_EQ(lhs_num.quot, 0);
BOOST_TEST_EQ(lhs_num.rem, 0);

const auto lhs_denom {div(zero, lhs)};
const auto lhs_denom {boost::int128::div(zero, lhs)};
BOOST_TEST_EQ(lhs_denom.quot, 0);
BOOST_TEST_EQ(lhs_denom.rem, 0);
}
Expand Down
10 changes: 10 additions & 0 deletions test/test_gcd_lcm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,17 @@
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt


#ifndef BOOST_INT128_BUILD_MODULE

#include <boost/int128.hpp>

#else

import boost.int128;

#endif

#include <boost/core/lightweight_test.hpp>
#include <limits>

Expand Down
9 changes: 9 additions & 0 deletions test/test_i128.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,18 @@
# define BOOST_INT128_ALLOW_SIGN_CONVERSION
#endif

#ifndef BOOST_INT128_BUILD_MODULE

#include <boost/int128/detail/int128_imp.hpp>
#include <boost/int128/detail/conversions.hpp>
#include <boost/int128/iostream.hpp>

#else

import boost.int128;

#endif

#include <boost/core/lightweight_test.hpp>
#include <boost/mp11.hpp>
#include <cstring>
Expand Down
10 changes: 10 additions & 0 deletions test/test_i128_no_sign_conv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,18 @@
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt

#ifndef BOOST_INT128_BUILD_MODULE

#include <boost/int128/detail/int128_imp.hpp>
#include <boost/int128/detail/conversions.hpp>
#include <boost/int128/iostream.hpp>

#else

import boost.int128;

#endif

#include <boost/core/lightweight_test.hpp>
#include <boost/mp11.hpp>
#include <cstring>
Expand Down
9 changes: 9 additions & 0 deletions test/test_limits_i128.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt

#ifndef BOOST_INT128_BUILD_MODULE

#include <boost/int128/int128.hpp>

#else

import boost.int128;

#endif

#include <boost/core/lightweight_test.hpp>
#include <limits>

Expand Down
9 changes: 9 additions & 0 deletions test/test_limits_u128.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt

#ifndef BOOST_INT128_BUILD_MODULE

#include <boost/int128/int128.hpp>

#else

import boost.int128;

#endif

#include <boost/core/lightweight_test.hpp>
#include <limits>

Expand Down
9 changes: 9 additions & 0 deletions test/test_literals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,18 @@
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt

#ifndef BOOST_INT128_BUILD_MODULE

#include <boost/int128/int128.hpp>
#include <boost/int128/literals.hpp>
#include <boost/int128/iostream.hpp>

#else

import boost.int128;

#endif

#include <boost/core/lightweight_test.hpp>
#include <limits>

Expand Down
9 changes: 9 additions & 0 deletions test/test_midpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt

#ifndef BOOST_INT128_BUILD_MODULE

#include <boost/int128.hpp>

#else

import boost.int128;

#endif

#include <boost/core/lightweight_test.hpp>
#include <numeric>

Expand Down