[libc-commits] [libc] [libc][NFC] Simplify `FPBits` (PR #76835)
Clement Courbet via libc-commits
libc-commits at lists.llvm.org
Wed Jan 3 09:40:09 PST 2024
================
@@ -347,17 +334,18 @@ template <typename T> struct FPBits : public internal::FPRep<get_fp_type<T>()> {
static constexpr StorageType MAX_NORMAL =
((StorageType(MAX_BIASED_EXPONENT) - 1) << FRACTION_LEN) | MAX_SUBNORMAL;
- // We don't want accidental type promotions/conversions, so we require exact
- // type match.
- template <typename XType, cpp::enable_if_t<cpp::is_same_v<T, XType>, int> = 0>
- LIBC_INLINE constexpr explicit FPBits(XType x)
- : UP(cpp::bit_cast<StorageType>(x)) {}
-
- template <typename XType,
- cpp::enable_if_t<cpp::is_same_v<XType, StorageType>, int> = 0>
- LIBC_INLINE constexpr explicit FPBits(XType x) : UP(x) {}
+ LIBC_INLINE constexpr FPBits() = default;
- LIBC_INLINE constexpr FPBits() : UP() {}
+ template <typename XType> LIBC_INLINE constexpr explicit FPBits(XType x) {
+ using Unqual = typename cpp::remove_cv_t<XType>;
+ if constexpr (cpp::is_same_v<Unqual, T>) {
+ bits = cpp::bit_cast<StorageType>(x);
+ } else if constexpr (cpp::is_same_v<Unqual, StorageType>) {
+ bits = x;
+ } else {
+ static_assert(cpp::always_false<XType>);
----------------
legrosbuffle wrote:
You probably want to keep the comment here.
https://github.com/llvm/llvm-project/pull/76835
More information about the libc-commits
mailing list