Skip to content

Commit

Permalink
Fix compilation on ppc64
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaut committed May 31, 2022
1 parent a2681aa commit 9d60395
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 17 deletions.
17 changes: 6 additions & 11 deletions include/fmt/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,9 @@ struct is_fast_float : bool_constant<std::numeric_limits<T>::is_iec559 &&
sizeof(T) <= sizeof(double)> {};
template <typename T> struct is_fast_float<T, false> : std::false_type {};

template <typename T>
using is_double_double = bool_constant<std::numeric_limits<T>::digits == 106>;

#ifndef FMT_USE_FULL_CACHE_DRAGONBOX
# define FMT_USE_FULL_CACHE_DRAGONBOX 0
#endif
Expand Down Expand Up @@ -1314,15 +1317,9 @@ struct float_info<T, enable_if_t<std::numeric_limits<T>::digits == 64 ||
static const int exponent_bits = 15;
};

template <int> constexpr int check_digits();

// A double-double floating point number.
template <typename T>
struct float_info<T, enable_if_t<!(std::numeric_limits<T>::digits == 64 ||
std::numeric_limits<T>::digits == 113 ||
is_float128<T>::value) &&
std::is_same<T, long double>::value>> {
static constexpr int check = check_digits<std::numeric_limits<T>::digits>();
struct float_info<T, enable_if_t<is_double_double<T>::value>> {
using carrier_uint = detail::uint128_t;
};

Expand Down Expand Up @@ -1400,8 +1397,7 @@ template <typename F> struct basic_fp {
template <typename Float> FMT_CONSTEXPR basic_fp(Float n) { assign(n); }

// Assigns n to this and return true iff predecessor is closer than successor.
template <typename Float,
FMT_ENABLE_IF(std::numeric_limits<Float>::is_iec559)>
template <typename Float, FMT_ENABLE_IF(!is_double_double<Float>::value)>
FMT_CONSTEXPR auto assign(Float n) -> bool {
static_assert(std::numeric_limits<Float>::digits <= 113, "unsupported FP");
// Assume Float is in the format [sign][exponent][significand].
Expand All @@ -1426,8 +1422,7 @@ template <typename F> struct basic_fp {
return is_predecessor_closer;
}

template <typename Float,
FMT_ENABLE_IF(!std::numeric_limits<Float>::is_iec559)>
template <typename Float, FMT_ENABLE_IF(is_double_double<Float>::value)>
FMT_CONSTEXPR auto assign(Float n) -> bool {
static_assert(std::numeric_limits<double>::is_iec559, "unsupported FP");
return assign(static_cast<double>(n));
Expand Down
10 changes: 5 additions & 5 deletions test/format-impl-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -379,17 +379,17 @@ bool operator>=(const double_double& lhs, const double_double& rhs) {
namespace std {
template <> struct is_floating_point<double_double> : std::true_type {};
template <> struct numeric_limits<double_double> {
static constexpr bool is_iec559 = false;
// is_iec559 is true for double-double in libstdc++.
static constexpr bool is_iec559 = true;
static constexpr int digits = 106;
};
} // namespace std

TEST(format_impl_test, write_double_double) {
// TODO: restore
// auto s = std::string();
// fmt::detail::write<char>(std::back_inserter(s), double_double(42), {});
auto s = std::string();
fmt::detail::write<char>(std::back_inserter(s), double_double(42), {});
#ifndef _MSC_VER // MSVC has an issue with specializing is_floating_point.
// EXPECT_EQ(s, "42");
EXPECT_EQ(s, "42");
#endif
}

Expand Down
2 changes: 1 addition & 1 deletion test/format-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1984,7 +1984,7 @@ TEST(format_test, to_string) {
EXPECT_EQ(fmt::to_string(zero), "0");

#if FMT_USE_FLOAT128
EXPECT_EQ(fmt::to_string(__float128(0.42)), "0.42");
EXPECT_EQ(fmt::to_string(__float128(0.5)), "0.5");
#endif
}

Expand Down

0 comments on commit 9d60395

Please sign in to comment.