From 1a0c76a81addcb2401c76ea88ef75b2695c3657a Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Wed, 13 Aug 2014 07:51:02 -0700 Subject: [PATCH] Fix formatting of long double. --- format.cc | 10 +++++++++- test/format-test.cc | 4 ++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/format.cc b/format.cc index ac81a3f1..68c58b61 100644 --- a/format.cc +++ b/format.cc @@ -83,6 +83,14 @@ inline int isinfinity(double x) { #endif } +inline int isinfinity(long double x) { +#ifdef isinf + return isinf(x); +#else + return std::isinf(x); +#endif +} + #define FMT_SNPRINTF snprintf #else // _MSC_VER @@ -601,7 +609,7 @@ void fmt::BasicWriter::write_double(T value, const FormatSpec &spec) { return; } - if (isinfinity(static_cast(value))) { + if (isinfinity(value)) { // Format infinity ourselves because sprintf's output is not consistent // across platforms. std::size_t size = 4; diff --git a/test/format-test.cc b/test/format-test.cc index fb4d39f9..84dd725e 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -374,7 +374,11 @@ TEST(WriterTest, WriteLongLong) { TEST(WriterTest, WriteDouble) { CHECK_WRITE(4.2); CHECK_WRITE(-4.2); +} + +TEST(WriterTest, WriteLongDouble) { CHECK_WRITE(4.2l); + CHECK_WRITE(std::numeric_limits::max()); } TEST(WriterTest, WriteDoubleAtBufferBoundary) {