Skip to content

Commit

Permalink
Disable usage of long double in static_assert with clang
Browse files Browse the repository at this point in the history
Signed-off-by: Ian <[email protected]>
  • Loading branch information
Rinzii committed Jan 13, 2025
1 parent f49b868 commit 6804429
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 26 deletions.
2 changes: 1 addition & 1 deletion include/ccmath/internal/support/bits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace ccm::support
{

template <typename To, typename From>
inline constexpr std::enable_if_t<
constexpr std::enable_if_t<
sizeof(To) == sizeof(From) && std::is_trivially_constructible_v<To> && std::is_trivially_copyable_v<To> && std::is_trivially_copyable_v<From>, To>
bit_cast(const From & from)
{
Expand Down
18 changes: 2 additions & 16 deletions include/ccmath/internal/support/fp/fp_bits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ namespace ccm::support::fp
/// All supported floating point types
enum class FPType : std::uint8_t
{
eBinary16, // TODO: Currently don't handle float16 but might in the future
eBinary32,
eBinary64,
eBinary80,
Expand All @@ -49,16 +48,6 @@ namespace ccm::support::fp
{
};

template <>
struct FPLayout<FPType::eBinary16>
{
using storage_type = std::uint16_t;
static constexpr std::int_fast32_t sign_length = 1;
static constexpr std::int_fast32_t exponent_length = 5;
static constexpr std::int_fast32_t significand_length = 10;
static constexpr std::int_fast32_t fraction_length = significand_length;
};

template <>
struct FPLayout<FPType::eBinary32>
{
Expand Down Expand Up @@ -827,9 +816,6 @@ namespace ccm::support::fp
else if constexpr (LDBL_MANT_DIG == 64) { return FPType::eBinary80; } // long double is 80-bits
else if constexpr (LDBL_MANT_DIG == 113) { return FPType::eBinary128; } // long double is 128-bits
}
#if defined(CCM_TYPES_HAS_FLOAT128)
else if constexpr (std::is_same_v<UnqualT, types::float128>) { return FPType::eBinary128; }
#endif
else { static_assert(support::always_false<UnqualT>, "Unsupported type"); }
return FPType::eBinary32; // This will never be reached due to assert. Only here to appease the compiler.
}
Expand All @@ -841,7 +827,7 @@ namespace ccm::support::fp
template <typename T>
struct FPBits final : internal::FPRepImpl<get_fp_type<T>(), FPBits<T>>
{
static_assert(std::is_floating_point_v<T>, "FPBits instantiated with invalid type.");
static_assert(support::traits::ccm_is_floating_point_v<T>, "FPBits instantiated with invalid type.");
using BASE = internal::FPRepImpl<get_fp_type<T>(), FPBits<T>>;
using storage_type = typename BASE::storage_type;

Expand All @@ -850,7 +836,7 @@ namespace ccm::support::fp
template <typename XType>
inline constexpr explicit FPBits(XType x)
{
using UnQual = std::remove_cv_t<XType>;
using UnQual = typename std::remove_cv_t<XType>;
if constexpr (std::is_same_v<UnQual, T>) { BASE::bits = support::bit_cast<storage_type>(x); }
else if constexpr (std::is_same_v<UnQual, storage_type>) { BASE::bits = x; }
else
Expand Down
9 changes: 3 additions & 6 deletions include/ccmath/internal/types/big_int.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,7 @@ namespace ccm::types
}
#endif
#ifdef CCM_TYPES_HAS_INT128
else if constexpr (std::is_same_v<word, std::uint64_t>)
{
return split<__uint128_t>(static_cast<__uint128_t>(lhs) * static_cast<__uint128_t>(rhs));
}
else if constexpr (std::is_same_v<word, std::uint64_t>) { return split<__uint128_t>(__uint128_t(lhs) * __uint128_t(rhs)); }
#endif
else
{
Expand Down Expand Up @@ -725,7 +722,7 @@ namespace ccm::types
*/
[[nodiscard]] constexpr bool is_neg() const { return SIGNED && get_msb(); }

template <size_t OtherBits, bool OtherSigned, typename OtherWordType>
template <std::size_t OtherBits, bool OtherSigned, typename OtherWordType>
constexpr explicit operator BigInt<OtherBits, OtherSigned, OtherWordType>() const
{
return BigInt<OtherBits, OtherSigned, OtherWordType>(this);
Expand Down Expand Up @@ -1491,7 +1488,7 @@ namespace ccm::support
(sizeof(To) == sizeof(From)) && std::is_trivially_copyable_v<To> && std::is_trivially_copyable_v<From> && types::is_big_int<To>::value, To>
bit_cast(const From & from)
{
To out;
To out{};
using Storage = decltype(out.val);
out.val = support::bit_cast<Storage>(from);
return out;
Expand Down
4 changes: 1 addition & 3 deletions include/ccmath/internal/types/int128_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@

#include "ccmath/internal/config/type_support.hpp"

#ifndef CCM_TYPES_HAS_INT128
#include "ccmath/internal/types/big_int.hpp"
#endif
#include "ccmath/internal/types/big_int.hpp"

namespace ccm::types
{
Expand Down
7 changes: 7 additions & 0 deletions test/fmanip/ldexp_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,14 @@ TYPED_TEST_SUITE(CcmathFmanipTests, TestTypes);

TYPED_TEST(CcmathFmanipTests, LdexpStaticAssert)
{
#if defined(__clang__) // long double does not really work on static_assert for clang. This is due to how __builtin_bit_cast works on clang.
if constexpr (!std::is_same_v<long double, TypeParam>)
{
static_assert(ccm::ldexp(static_cast<TypeParam>(1.0), 0) == ccm::ldexp(static_cast<TypeParam>(1.0), 0));
}
#else
static_assert(ccm::ldexp(static_cast<TypeParam>(1.0), 0) == ccm::ldexp(static_cast<TypeParam>(1.0), 0));
#endif
}

TYPED_TEST(CcmathFmanipTests, LdexpBasic)
Expand Down

0 comments on commit 6804429

Please sign in to comment.