Repository navigation
bpo-45995: add "z" format specifer to coerce negative 0 to zero #30049
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
a633e88
636da05
3f4085d
68a049e
ad32be5
3dcaf5f
6b9ab3b
e243568
be4fda2
043d76a
104e023
61c64df
76d61ae
33fe72c
9393136
f88f7fc
20c9cf1
bf1a891
3f5b392
8d7a745
2a24e61
0cbff6a
8e7b51c
418ab76
3ee6f6b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3360,9 +3360,7 @@ dec_format(PyObject *dec, PyObject *args) | |
| if (no_neg_0 && mpd_isnegative(mpd) && !mpd_isspecial(mpd)) { | ||
| /* Round into a temporary (carefully mirroring the rounding | ||
| of mpd_qformat_spec()), and check if the result is negative zero. | ||
| If so, clear the sign and format this pre-rounded value. | ||
| (The format will then do no additional rounding, which is | ||
| significant for directed rounding cases like ROUND_CEILING.) */ | ||
| If so, clear the sign and format the resulting positive zero. */ | ||
|
Comment on lines
+3389
to
+3392
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. An insight I had recently was that, once negative zero is confirmed somehow, producing the correct output is only a matter of formatting positive zero (which cannot be affected by directed rounding, etc.). As for how to detect negative zero, the options are: 1) round independently of the format function, or 2) analyze the string result of the format function (as Mark suggested). I found the former easier to manage, since it's a matter of duplicating a small amount of proven mpd library code, and is relatively straightforward to test. In contrast, analyzing the format output involves writing a new and perfectly-correct regex or parser, and imagining all the format spec edge cases to test it with. |
||
| mpd_ssize_t prec; | ||
| mpd_qcopy(&tmp, mpd, &status); | ||
| switch (spec.type) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.