Skip to content

Commit

Permalink
fix: silence warning: [-Wfloat-equal] (fmtlib#2848)
Browse files Browse the repository at this point in the history
  • Loading branch information
abdes committed Apr 1, 2022
1 parent 288c3b9 commit f3dcc52
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
12 changes: 12 additions & 0 deletions include/fmt/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -2299,6 +2299,13 @@ FMT_CONSTEXPR20 bool isfinite(T value) {
if (is_constant_evaluated()) return value - value == 0;
return std::isfinite(value);
}
#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wfloat-equal"
#elif defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wfloat-equal"
#endif
template <typename T, FMT_ENABLE_IF(is_float128<T>::value)>
constexpr bool isfinite(T value) {
return value - value == 0; // std::isfinite doesn't support __float128.
Expand All @@ -2307,6 +2314,11 @@ constexpr bool isfinite(T value) {
template <typename T> constexpr bool isnan(T value) {
return value != value; // std::isnan doesn't support __float128.
}
#if defined(__clang__)
#pragma clang diagnostic pop
#elif defined(__GNUC__)
#pragma GCC diagnostic pop
#endif

template <typename T, FMT_ENABLE_IF(is_floating_point<T>::value)>
FMT_INLINE FMT_CONSTEXPR bool signbit(T value) {
Expand Down
12 changes: 12 additions & 0 deletions test/xchar-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -479,9 +479,21 @@ template <class charT> struct formatter<std::complex<double>, charT> {
fmt::runtime("{:" + specs + "}"), c.imag());
auto fill_align_width = std::string();
if (specs_.width > 0) fill_align_width = fmt::format(">{}", specs_.width);
#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wfloat-equal"
#elif defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wfloat-equal"
#endif
return format_to(ctx.out(), runtime("{:" + fill_align_width + "}"),
c.real() != 0 ? fmt::format("({}+{}i)", real, imag)
: fmt::format("{}i", imag));
#if defined(__clang__)
#pragma clang diagnostic pop
#elif defined(__GNUC__)
#pragma GCC diagnostic pop
#endif
}
};
FMT_END_NAMESPACE
Expand Down

0 comments on commit f3dcc52

Please sign in to comment.