Skip to content

Commit 3f7ca67

Browse files
<format>: Alternate form general floating-point width handling (#5261)
Co-authored-by: alexprabhatbara <[email protected]>
1 parent f953153 commit 3f7ca67

File tree

2 files changed

+3
-0
lines changed
  • stl/inc
  • tests/std/tests/P0645R10_text_formatting_formatting

2 files changed

+3
-0
lines changed

stl/inc/format

+2
Original file line numberDiff line numberDiff line change
@@ -2145,6 +2145,8 @@ _NODISCARD _OutputIt _Fmt_write(
21452145
case 'g':
21462146
if (_Precision == -1) {
21472147
_Precision = 6;
2148+
} else if (_Precision == 0) {
2149+
_Precision = 1;
21482150
}
21492151
_Format = chars_format::general;
21502152
break;

tests/std/tests/P0645R10_text_formatting_formatting/test.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -835,6 +835,7 @@ void test_float_specs() {
835835
assert(format(STR("{:3}"), Float{0}) == STR(" 0"));
836836
assert(format(STR("{:#9G}"), Float{12.2}) == STR(" 12.2000"));
837837
assert(format(STR("{:#12g}"), Float{1'000'000}) == STR(" 1.00000e+06"));
838+
assert(format(STR("[{:#6.0g}]"), 1.234e-37) == STR("[1.e-37]"));
838839

839840
// Precision
840841
Float value = 1234.52734375;

0 commit comments

Comments
 (0)