Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions stl/inc/format
Original file line number Diff line number Diff line change
Expand Up @@ -2864,7 +2864,7 @@ _NODISCARD _OutputIt _Fmt_write(

auto _To_upper = false;
auto _Format = chars_format::general;
auto _Exponent = '\0';
auto _Exponent = 'e';
Comment thread
StephanTLavavej marked this conversation as resolved.
auto _Precision = _Specs._Precision;

switch (_Specs._Type) {
Expand All @@ -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;
Expand All @@ -2901,8 +2900,7 @@ _NODISCARD _OutputIt _Fmt_write(
if (_Precision == -1) {
_Precision = 6;
}
_Format = chars_format::general;
_Exponent = 'e';
_Format = chars_format::general;
break;
}

Expand Down Expand Up @@ -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<int>(_Exponent_start - _Buffer_start);

if (!_Append_decimal) {
Expand Down
4 changes: 0 additions & 4 deletions tests/libcxx/expected_results.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/std/test.lst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions tests/std/tests/GH_003003_format_decimal_point/env.lst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright (c) Microsoft Corporation.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

RUNALL_INCLUDE ..\concepts_20_matrix.lst
33 changes: 33 additions & 0 deletions tests/std/tests/GH_003003_format_decimal_point/test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (c) Microsoft Corporation.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#include <cassert>
#include <format>

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");
}