Skip to content

Commit 5204fa2

Browse files
committed
Fix handling of negative values
1 parent 4b0f5ff commit 5204fa2

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

include/boost/int128/numeric.hpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,7 @@ constexpr uint128_t gcd(uint128_t a, uint128_t b) noexcept
283283

284284
constexpr int128_t gcd(const int128_t a, const int128_t b) noexcept
285285
{
286-
const auto res {static_cast<int128_t>(gcd(static_cast<uint128_t>(abs(a)), static_cast<uint128_t>(abs(b))))};
287-
return (a < 0) != (b < 0) ? -res : res;
286+
return static_cast<int128_t>(gcd(static_cast<uint128_t>(abs(a)), static_cast<uint128_t>(abs(b))));
288287
}
289288

290289
constexpr uint128_t lcm(const uint128_t a, const uint128_t b) noexcept
@@ -303,8 +302,7 @@ constexpr uint128_t lcm(const uint128_t a, const uint128_t b) noexcept
303302

304303
constexpr int128_t lcm(const int128_t a, const int128_t b) noexcept
305304
{
306-
const auto res {static_cast<int128_t>(lcm(static_cast<uint128_t>(abs(a)), static_cast<uint128_t>(abs(b))))};
307-
return (a < 0) != (b < 0) ? -res : res;
305+
return static_cast<int128_t>(lcm(static_cast<uint128_t>(abs(a)), static_cast<uint128_t>(abs(b))));
308306
}
309307

310308
} // namespace int128

0 commit comments

Comments
 (0)