mirror of
https://github.com/fmtlib/fmt.git
synced 2024-12-24 12:14:26 +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
|
||||
}
|
||||
|
||||
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;
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user