Skip to content

Commit

Permalink
Fix warning when building with -Wfloat-equal
Browse files Browse the repository at this point in the history
  • Loading branch information
inguin committed Nov 2, 2015
1 parent b4b13ee commit a47ce41
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion format.h
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,15 @@ inline int isinfinity(long double x) { return isinf(x); }
inline int isinfinity(double x) { return std::isinf(x); }
inline int isinfinity(long double x) { return std::isinf(x); }
# endif

// Portable version of isnan.
# ifdef isnan
inline int isnotanumber(double x) { return isnan(x); }
inline int isnotanumber(long double x) { return isnan(x); }
# else
inline int isnotanumber(double x) { return std::isnan(x); }
inline int isnotanumber(long double x) { return std::isnan(x); }
# endif
#else
inline int getsign(double value) {
if (value < 0) return 1;
Expand All @@ -607,6 +616,10 @@ inline int isinfinity(double x) { return !_finite(x); }
inline int isinfinity(long double x) {
return !_finite(static_cast<double>(x));
}
inline int isnotanumber(double x) { _isnan(x); }
inline int isnotanumber(long double x) {
return _isnan(static_cast<double>(x));
}
#endif

template <typename Char>
Expand Down Expand Up @@ -2378,7 +2391,7 @@ void BasicWriter<Char>::write_double(
sign = spec.flag(PLUS_FLAG) ? '+' : ' ';
}

if (value != value) {
if (internal::isnotanumber(value)) {
// Format NaN ourselves because sprintf's output is not consistent
// across platforms.
std::size_t nan_size = 4;
Expand Down

0 comments on commit a47ce41

Please sign in to comment.