mirror of
https://github.com/fmtlib/fmt.git
synced 2024-11-26 04:00:05 +00:00
Fix handling of hexfloat
This commit is contained in:
parent
92a44db11c
commit
cbbee1b385
@ -786,7 +786,7 @@ void sprintf_format(Double value, internal::buffer<char>& buf,
|
||||
// Find the decimal point.
|
||||
auto p = buf.data(), end = p + n;
|
||||
if (*p == '+' || *p == '-') ++p;
|
||||
if (spec.type == 'a' || spec.type == 'A') p += 2; // Skip "0x".
|
||||
if (spec.type != 'a' && spec.type != 'A') {
|
||||
while (p < end && *p >= '0' && *p <= '9') ++p;
|
||||
if (p < end && *p != 'e' && *p != 'E') {
|
||||
if (*p != '.') *p = '.';
|
||||
@ -803,6 +803,7 @@ void sprintf_format(Double value, internal::buffer<char>& buf,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
buf.resize(n);
|
||||
break; // The buffer is large enough - continue with formatting.
|
||||
}
|
||||
|
@ -1506,6 +1506,8 @@ TEST(FormatterTest, FormatLongDouble) {
|
||||
safe_sprintf(buffer, "%Le", 392.65l);
|
||||
EXPECT_EQ(buffer, format("{0:e}", 392.65l));
|
||||
EXPECT_EQ("+0000392.6", format("{0:+010.4g}", 392.64l));
|
||||
safe_sprintf(buffer, "%La", 3.31l);
|
||||
EXPECT_EQ(buffer, format("{:a}", 3.31l));
|
||||
}
|
||||
|
||||
TEST(FormatterTest, FormatChar) {
|
||||
|
Loading…
Reference in New Issue
Block a user