mirror of
https://github.com/fmtlib/fmt.git
synced 2024-12-25 15:21:54 +00:00
Fix formatting of long double.
This commit is contained in:
parent
18f1e08685
commit
1a0c76a81a
10
format.cc
10
format.cc
@ -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) {
|
|||||||
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) {
|
|||||||
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) {
|
||||||
|
Loading…
Reference in New Issue
Block a user