Commit 1a0c76a8 authored by Victor Zverovich's avatar Victor Zverovich

Fix formatting of long double.

parent 18f1e086
...@@ -83,6 +83,14 @@ inline int isinfinity(double x) { ...@@ -83,6 +83,14 @@ inline int isinfinity(double x) {
#endif #endif
} }
inline int isinfinity(long double x) {
#ifdef isinf
return isinf(x);
#else
return std::isinf(x);
#endif
}
#define FMT_SNPRINTF snprintf #define FMT_SNPRINTF snprintf
#else // _MSC_VER #else // _MSC_VER
...@@ -601,7 +609,7 @@ void fmt::BasicWriter<Char>::write_double(T value, const FormatSpec &spec) { ...@@ -601,7 +609,7 @@ void fmt::BasicWriter<Char>::write_double(T value, const FormatSpec &spec) {
return; return;
} }
if (isinfinity(static_cast<double>(value))) { if (isinfinity(value)) {
// Format infinity ourselves because sprintf's output is not consistent // Format infinity ourselves because sprintf's output is not consistent
// across platforms. // across platforms.
std::size_t size = 4; std::size_t size = 4;
......
...@@ -374,7 +374,11 @@ TEST(WriterTest, WriteLongLong) { ...@@ -374,7 +374,11 @@ TEST(WriterTest, WriteLongLong) {
TEST(WriterTest, WriteDouble) { TEST(WriterTest, WriteDouble) {
CHECK_WRITE(4.2); CHECK_WRITE(4.2);
CHECK_WRITE(-4.2); CHECK_WRITE(-4.2);
}
TEST(WriterTest, WriteLongDouble) {
CHECK_WRITE(4.2l); CHECK_WRITE(4.2l);
CHECK_WRITE(std::numeric_limits<long double>::max());
} }
TEST(WriterTest, WriteDoubleAtBufferBoundary) { TEST(WriterTest, WriteDoubleAtBufferBoundary) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment