@@ -2367,6 +2367,7 @@ void format_test_floating_point_default_precision(TestFunction check) {
2367
2367
2368
2368
// *** alternate form **
2369
2369
// When precision is zero there's no decimal point except when the alternate form is specified.
2370
+ // Note unlike the g and G option the trailing zeros are still removed.
2370
2371
check (SV (" answer is '0'" ), SV (" answer is '{:.0}'" ), F (0 ));
2371
2372
check (SV (" answer is '0.'" ), SV (" answer is '{:#.0}'" ), F (0 ));
2372
2373
@@ -2449,6 +2450,57 @@ void format_test_floating_point_default_precision(TestFunction check) {
2449
2450
// See locale-specific_form.pass.cpp
2450
2451
}
2451
2452
2453
+ template <class F , class CharT , class TestFunction >
2454
+ void format_test_floating_point_PR58714 (TestFunction check) {
2455
+ check (SV (" +1234" ), SV (" {:+}" ), F (1234.0 ));
2456
+ check (SV (" +1.348p+10" ), SV (" {:+a}" ), F (1234.0 ));
2457
+ check (SV (" +1.234000e+03" ), SV (" {:+e}" ), F (1234.0 ));
2458
+ check (SV (" +1234.000000" ), SV (" {:+f}" ), F (1234.0 ));
2459
+ check (SV (" +1234" ), SV (" {:+g}" ), F (1234.0 ));
2460
+
2461
+ check (SV (" 1234." ), SV (" {:#}" ), F (1234.0 ));
2462
+ check (SV (" 1.348p+10" ), SV (" {:#a}" ), F (1234.0 ));
2463
+ check (SV (" 1.234000e+03" ), SV (" {:#e}" ), F (1234.0 ));
2464
+ check (SV (" 1234.000000" ), SV (" {:#f}" ), F (1234.0 ));
2465
+ check (SV (" 1234.00" ), SV (" {:#g}" ), F (1234.0 ));
2466
+
2467
+ check (SV (" 4.e+30" ), SV (" {:#}" ), F (4.0e+30 ));
2468
+ check (SV (" 1.p+102" ), SV (" {:#a}" ), F (0x4 .0p+100 ));
2469
+ check (SV (" 4.000000e+30" ), SV (" {:#e}" ), F (4.0e+30 ));
2470
+ check (SV (" 5070602400912917605986812821504.000000" ), SV (" {:#f}" ), F (0x4 .0p+100 ));
2471
+ check (SV (" 4.00000e+30" ), SV (" {:#g}" ), F (4.0e+30 ));
2472
+
2473
+ check (SV (" 1234." ), SV (" {:#.6}" ), F (1234.0 )); // # does not restore zeros
2474
+ check (SV (" 1.348000p+10" ), SV (" {:#.6a}" ), F (1234.0 ));
2475
+ check (SV (" 1.234000e+03" ), SV (" {:#.6e}" ), F (1234.0 ));
2476
+ check (SV (" 1234.000000" ), SV (" {:#.6f}" ), F (1234.0 ));
2477
+ check (SV (" 1234.00" ), SV (" {:#.6g}" ), F (1234.0 ));
2478
+
2479
+ check (SV (" -1234." ), SV (" {:#}" ), F (-1234.0 ));
2480
+ check (SV (" -1.348p+10" ), SV (" {:#a}" ), F (-1234.0 ));
2481
+ check (SV (" -1.234000e+03" ), SV (" {:#e}" ), F (-1234.0 ));
2482
+ check (SV (" -1234.000000" ), SV (" {:#f}" ), F (-1234.0 ));
2483
+ check (SV (" -1234.00" ), SV (" {:#g}" ), F (-1234.0 ));
2484
+
2485
+ check (SV (" -1234." ), SV (" {:#.6}" ), F (-1234.0 )); // # does not restore zeros
2486
+ check (SV (" -1.348000p+10" ), SV (" {:#.6a}" ), F (-1234.0 ));
2487
+ check (SV (" -1.234000e+03" ), SV (" {:#.6e}" ), F (-1234.0 ));
2488
+ check (SV (" -1234.000000" ), SV (" {:#.6f}" ), F (-1234.0 ));
2489
+ check (SV (" -1234.00" ), SV (" {:#.6g}" ), F (-1234.0 ));
2490
+
2491
+ check (SV (" +1234." ), SV (" {:+#}" ), F (1234.0 ));
2492
+ check (SV (" +1.348p+10" ), SV (" {:+#a}" ), F (1234.0 ));
2493
+ check (SV (" +1.234000e+03" ), SV (" {:+#e}" ), F (1234.0 ));
2494
+ check (SV (" +1234.000000" ), SV (" {:+#f}" ), F (1234.0 ));
2495
+ check (SV (" +1234.00" ), SV (" {:+#g}" ), F (1234.0 ));
2496
+
2497
+ check (SV (" +1234." ), SV (" {:+#.6}" ), F (1234.0 )); // # does not restore zeros
2498
+ check (SV (" +1.348000p+10" ), SV (" {:+#.6a}" ), F (1234.0 ));
2499
+ check (SV (" +1.234000e+03" ), SV (" {:+#.6e}" ), F (1234.0 ));
2500
+ check (SV (" +1234.000000" ), SV (" {:+#.6f}" ), F (1234.0 ));
2501
+ check (SV (" +1234.00" ), SV (" {:+#.6g}" ), F (1234.0 ));
2502
+ }
2503
+
2452
2504
template <class F , class CharT , class TestFunction , class ExceptionTest >
2453
2505
void format_test_floating_point (TestFunction check, ExceptionTest check_exception) {
2454
2506
format_test_floating_point_hex_lower_case<F, CharT>(check);
@@ -2468,6 +2520,8 @@ void format_test_floating_point(TestFunction check, ExceptionTest check_exceptio
2468
2520
format_test_floating_point_default<F, CharT>(check);
2469
2521
format_test_floating_point_default_precision<F, CharT>(check);
2470
2522
2523
+ format_test_floating_point_PR58714<F, CharT>(check);
2524
+
2471
2525
// *** type ***
2472
2526
for (const auto & fmt : invalid_types<CharT>(" aAeEfFgG" ))
2473
2527
check_exception (" The format-spec type has a type not supported for a floating-point argument" , fmt, F (1 ));
0 commit comments