Skip to content

Commit

Permalink
Merge pull request #205 from chfast/cleanup_mul
Browse files Browse the repository at this point in the history
Obsolete constexpr_mul<uint128>()
  • Loading branch information
chfast authored Mar 7, 2021
2 parents 81e01d5 + 6c35580 commit 6894b62
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
7 changes: 3 additions & 4 deletions include/intx/int128.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ inline constexpr uint128 umul(uint64_t x, uint64_t y) noexcept
return {hi, lo};
}

inline uint128 operator*(uint128 x, uint128 y) noexcept
inline constexpr uint128 operator*(uint128 x, uint128 y) noexcept
{
auto p = umul(x.lo, y.lo);
p.hi += (x.lo * y.hi) + (x.hi * y.lo);
Expand All @@ -411,9 +411,8 @@ inline uint128 operator*(uint128 x, uint128 y) noexcept

inline constexpr uint128 constexpr_mul(uint128 x, uint128 y) noexcept
{
auto p = umul(x.lo, y.lo);
p.hi += (x.lo * y.hi) + (x.hi * y.lo);
return {p.hi, p.lo};
// FIXME: Remove this function.
return x * y;
}

/// @}
Expand Down
4 changes: 3 additions & 1 deletion test/unittests/test_intx_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ static_assert(uint128{2} - uint128{1} == 1, "");
static_assert(uint256{2} - uint256{1} == 1, "");
static_assert(uint512{2} - uint512{1} == 1, "");

static_assert(constexpr_mul(uint128{2}, uint128{2}) == 4, "");
static_assert(uint128{2} * uint128{2} == 4, "");
static_assert(constexpr_mul(uint256{2}, uint256{2}) == 4, "");
static_assert(constexpr_mul(uint512{2}, uint512{2}) == 4, "");

static_assert(umul(uint256{2}, uint256{3}) == 6, "");

static_assert(0_u256 == 0, "");
static_assert(-1_u256 == ~0_u256, "");
static_assert(
Expand Down

0 comments on commit 6894b62

Please sign in to comment.