Created on 2019-07-31.00:00:00 last changed 46 months ago
Proposed resolution:
This wording is relative to N4849.
Modify the sign options Table [tab:format.sign] in [format.string.std] as indicated:
Table 58: Meaning of sign options [tab:format.sign] Option Meaning '+' Indicates that a sign should be used for both non-negative and negative numbers. '-' Indicates that a sign should be used onlyfor negative numbers and negative zero only (this is the default behavior).space Indicates that a leading space should be used for non-negative numbers other than negative zero, and a minus sign for negative numbers and negative zero.
[ 2020-02 Status to Immediate on Thursday night in Prague. ]
[ 2020-02-13, Prague ]
Rebased and some wording finetuning by LWG.
[ 2019-08-17 Priority set to 2 based on reflector discussion ]
Previous resolution [SUPERSEDED]:This wording is relative to N4830.
Modify the sign options Table [tab:format.sign] in [format.string.std] as indicated:
Table 59: Meaning of sign options [tab:format.sign] Option Meaning '+' Indicates that a sign should be used for both non-negative and negative numbers. '-' Indicates that a sign should be used only for negative numbers and negative zero (this is the default behavior). space Indicates that a leading space should be used for non-negative numbers other than negative zero, and a minus sign for negative numbers and negative zero.
What are these:
std::format("{}", -0.0); std::format("{:+}", -0.0); std::format("{:-}", -0.0); std::format("{: }", -0.0);
with
"{:{}} {}"
A negative zero is not a negative number, so I think the answer for an implementation that supports signed zeroes is "0", "-0", "0", " 0". Is that the intent? (Note that this doesn't satisfy to_chars' round-trip guarantee.)
Or should the behavior actually be that "+" means "insert a leading + if to_chars' output does not start with -" and " " actually means "insert a leading space if to_chars' output does not start with -" (that is, the same as "%+f" and "% f") — so that the result of all four calls is "-0"? Victor Zverovich: The latter. std::format is specified in terms of to_chars and the intent is to have similar round trip guarantee here, so the result should be "-0", "-0", "-0", "-0". This has also been extensively discussed in LEWG and the outcome of that discussion was to print '-' for negative zeros. So I think it should be clarified that '-' and space apply to negative numbers and negative zero.History | |||
---|---|---|---|
Date | User | Action | Args |
2021-02-25 10:48:01 | admin | set | status: wp -> c++20 |
2020-02-24 16:02:59 | admin | set | status: immediate -> wp |
2020-02-14 11:24:43 | admin | set | messages: + msg11116 |
2020-02-14 11:24:43 | admin | set | status: new -> immediate |
2020-02-13 19:29:26 | admin | set | messages: + msg11082 |
2019-08-17 10:48:27 | admin | set | messages: + msg10555 |
2019-08-03 17:54:18 | admin | set | messages: + msg10534 |
2019-07-31 00:00:00 | admin | create |