Skip to content

Commit 340b14d

Browse files
committed
Optimize operator==
1 parent 7a903b0 commit 340b14d

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

include/boost/decimal/decimal128_fast.hpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -351,9 +351,19 @@ template <typename T1, typename T2, std::enable_if_t<detail::is_integral_v<T1> &
351351
#endif
352352
constexpr decimal128_fast::decimal128_fast(T1 coeff, T2 exp, bool sign) noexcept
353353
{
354+
// Older compilers have issues with conversions from __uint128, so we skip all that and use our uint128
355+
#if defined(BOOST_DECIMAL_HAS_INT128) && (!defined(__GNUC__) || (defined(__GNUC__) && !defined(__clang__) && __GNUC__ < 10)) && (!defined(__clang__) || (defined(__clang__) && __clang_major__ < 13))
356+
using Unsigned_Integer_1 = detail::make_unsigned_t<T1>;
357+
using Unsigned_Integer = std::conditional_t<std::is_same<Unsigned_Integer_1, detail::uint128_t>::value, detail::uint128, Unsigned_Integer_1>;
358+
#else
359+
using Unsigned_Integer = detail::make_unsigned_t<T1>;
360+
#endif
361+
362+
using Basis_Unsigned_Integer = std::conditional_t<std::numeric_limits<Unsigned_Integer>::digits10 < std::numeric_limits<significand_type>::digits10, significand_type, Unsigned_Integer>;
363+
354364
const bool isneg {coeff < static_cast<T1>(0) || sign};
355365
sign_ = isneg;
356-
auto unsigned_coeff {static_cast<significand_type>(detail::make_positive_unsigned(coeff))};
366+
auto unsigned_coeff {static_cast<Basis_Unsigned_Integer>(detail::make_positive_unsigned(coeff))};
357367

358368
// Normalize the significand in the constructor, so we don't have
359369
// to calculate the number of digits for operationss
@@ -478,8 +488,9 @@ constexpr auto operator==(const decimal128_fast& lhs, const decimal128_fast& rhs
478488
}
479489
#endif
480490

481-
return equal_parts_impl(lhs.significand_, lhs.biased_exponent(), lhs.sign_,
482-
rhs.significand_, rhs.biased_exponent(), rhs.sign_);
491+
return lhs.sign_ == rhs.sign_ &&
492+
lhs.exponent_ == rhs.exponent_ &&
493+
lhs.significand_ == rhs.significand_;
483494
}
484495

485496
template <typename Integer>

0 commit comments

Comments
 (0)