From 27c2e880d05442deeb312b83ebbc372416c8d01e Mon Sep 17 00:00:00 2001 From: Ingo van Lil Date: Mon, 2 Nov 2015 13:43:46 +0100 Subject: [PATCH] Fix warning when building with -Wfloat-equal --- format.h | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/format.h b/format.h index 6852d0b5..ac918e26 100644 --- a/format.h +++ b/format.h @@ -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; @@ -607,6 +616,10 @@ inline int isinfinity(double x) { return !_finite(x); } inline int isinfinity(long double x) { return !_finite(static_cast(x)); } +inline int isnotanumber(double x) { return _isnan(x); } +inline int isnotanumber(long double x) { + return _isnan(static_cast(x)); +} #endif template @@ -2378,7 +2391,7 @@ void BasicWriter::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;