diff --git a/stl/inc/format b/stl/inc/format index 56f5b11bb6c..077f445743d 100644 --- a/stl/inc/format +++ b/stl/inc/format @@ -2864,7 +2864,7 @@ _NODISCARD _OutputIt _Fmt_write( auto _To_upper = false; auto _Format = chars_format::general; - auto _Exponent = '\0'; + auto _Exponent = 'e'; auto _Precision = _Specs._Precision; switch (_Specs._Type) { @@ -2882,8 +2882,7 @@ _NODISCARD _OutputIt _Fmt_write( if (_Precision == -1) { _Precision = 6; } - _Format = chars_format::scientific; - _Exponent = 'e'; + _Format = chars_format::scientific; break; case 'F': _To_upper = true; @@ -2901,8 +2900,7 @@ _NODISCARD _OutputIt _Fmt_write( if (_Precision == -1) { _Precision = 6; } - _Format = chars_format::general; - _Exponent = 'e'; + _Format = chars_format::general; break; } @@ -3015,7 +3013,7 @@ _NODISCARD _OutputIt _Fmt_write( _Zeroes_to_append = _Extra_precision; break; case chars_format::general: - if (_Specs._Alt) { + if (_Specs._Alt && (_Specs._Type == 'g' || _Specs._Type == 'G')) { auto _Digits = static_cast(_Exponent_start - _Buffer_start); if (!_Append_decimal) { diff --git a/tests/libcxx/expected_results.txt b/tests/libcxx/expected_results.txt index 4c39a78d079..9cca579fe71 100644 --- a/tests/libcxx/expected_results.txt +++ b/tests/libcxx/expected_results.txt @@ -1062,11 +1062,7 @@ std/ranges/range.adaptors/range.take/adaptor.pass.cpp FAIL std/ranges/range.factories/range.single.view/cpo.pass.cpp FAIL std/thread/futures/futures.task/futures.task.members/ctor2.compile.pass.cpp FAIL std/utilities/format/format.functions/escaped_output.ascii.pass.cpp FAIL -std/utilities/format/format.functions/format.locale.pass.cpp FAIL -std/utilities/format/format.functions/format.pass.cpp FAIL std/utilities/format/format.functions/locale-specific_form.pass.cpp FAIL -std/utilities/format/format.functions/vformat.locale.pass.cpp FAIL -std/utilities/format/format.functions/vformat.pass.cpp FAIL std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/ctad.static.compile.pass.cpp FAIL std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.inv/invoke.pass.cpp:0 FAIL std/utilities/function.objects/refwrap/refwrap.const/type_conv_ctor.pass.cpp:0 FAIL diff --git a/tests/std/test.lst b/tests/std/test.lst index 822cf153b82..fed37b92022 100644 --- a/tests/std/test.lst +++ b/tests/std/test.lst @@ -218,6 +218,7 @@ tests\GH_002769_handle_deque_block_pointers tests\GH_002789_Hash_vec_Tidy tests\GH_002989_nothrow_unwrappable tests\GH_002992_unwrappable_iter_sent_pairs +tests\GH_003003_format_decimal_point tests\GH_003022_substr_allocator tests\GH_003105_piecewise_densities tests\GH_003119_error_category_ctor diff --git a/tests/std/tests/GH_003003_format_decimal_point/env.lst b/tests/std/tests/GH_003003_format_decimal_point/env.lst new file mode 100644 index 00000000000..d6d824b5879 --- /dev/null +++ b/tests/std/tests/GH_003003_format_decimal_point/env.lst @@ -0,0 +1,4 @@ +# Copyright (c) Microsoft Corporation. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +RUNALL_INCLUDE ..\concepts_20_matrix.lst diff --git a/tests/std/tests/GH_003003_format_decimal_point/test.cpp b/tests/std/tests/GH_003003_format_decimal_point/test.cpp new file mode 100644 index 00000000000..1b5d1e99f92 --- /dev/null +++ b/tests/std/tests/GH_003003_format_decimal_point/test.cpp @@ -0,0 +1,33 @@ +// Copyright (c) Microsoft Corporation. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +#include +#include + +int main() { + assert(std::format("{:#.0}", 0.0) == "0."); + assert(std::format("{:#.1}", 0.0) == "0."); + assert(std::format("{:#.2}", 0.0) == "0."); + + assert(std::format("{:#.0}", 1200.0) == "1.e+03"); + assert(std::format("{:#.1}", 1200.0) == "1.e+03"); + assert(std::format("{:#.2}", 1200.0) == "1.2e+03"); + assert(std::format("{:#.3}", 1200.0) == "1.2e+03"); + assert(std::format("{:#.4}", 1200.0) == "1200."); + assert(std::format("{:#.5}", 1200.0) == "1200."); + assert(std::format("{:#.6}", 1200.0) == "1200."); + + assert(std::format("{:#.0}", 0.123) == "0.1"); + assert(std::format("{:#.1}", 0.123) == "0.1"); + assert(std::format("{:#.2}", 0.123) == "0.12"); + assert(std::format("{:#.3}", 0.123) == "0.123"); + assert(std::format("{:#.4}", 0.123) == "0.123"); + assert(std::format("{:#.5}", 0.123) == "0.123"); + + assert(std::format("{:#.0}", 10.1) == "1.e+01"); + assert(std::format("{:#.1}", 10.1) == "1.e+01"); + assert(std::format("{:#.2}", 10.1) == "10."); + assert(std::format("{:#.3}", 10.1) == "10.1"); + assert(std::format("{:#.4}", 10.1) == "10.1"); + assert(std::format("{:#.5}", 10.1) == "10.1"); +}