Fix formatting of long double.

This commit is contained in:
Victor Zverovich 2014-08-13 07:51:02 -07:00
parent 18f1e08685
commit 1a0c76a81a
2 changed files with 13 additions and 1 deletions

View File

@ -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<Char>::write_double(T value, const FormatSpec &spec) {
return;
}
if (isinfinity(static_cast<double>(value))) {
if (isinfinity(value)) {
// Format infinity ourselves because sprintf's output is not consistent
// across platforms.
std::size_t size = 4;

View File

@ -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<long double>::max());
}
TEST(WriterTest, WriteDoubleAtBufferBoundary) {