-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Fix for minimal-printf when printing sign of double between 0.0 and -1.0 #13872
Fix for minimal-printf when printing sign of double between 0.0 and -1.0 #13872
Conversation
I thought it would be worth submitting my pull request for consideration. It's only my second pull request ever, so I'm not sure if I've done it right, feel free to edit it. |
@helpfulchicken, thank you for your changes. |
d2bfc11
to
105c39e
Compare
I saw that it failed a style check, so I've fixed that and squashed the commits back down to a single commit. |
Thank you! We will review |
@Linguanghsou Please review this alternative |
@helpfulchicken can you add a test case to catch this bug: https://github.com/ARMmbed/mbed-os/tree/105c39e693e48f6bfe6a0ef8f1a608f4652b59d5/platform/tests/TESTS/mbed_platform/minimal-printf/compliance ? There are tests for minimal printf. We must have missed this use case if the test passed previously. |
@0xc0170 I think helpfulchicken's fix is also good. |
I will do this. It's been a busy time for me lately, but I haven't forgotten about this. |
Hi @helpfulchicken thank you for your fix. I reviewed #13548 and your fix will need to be adapted in that PR which adds support for width modifier, see my comment #13548 (comment) Thank you very much for finding the issue and providing a solution; this is much appreciated. |
This PR should be closed in favour of #13548 |
Summary of changes
Fixes "minimal-printf doesn't display decimals between -1 to 0 correctly" listed in #13783
This is pull request is a suggested alternative to #13865, which also succeeds in fixing the above issue.
In mbed_minimal_formatted_string_double(), a given value of type double is printed in two parts, first the integer part and then the decimal part. The integer part is printed using mbed_minimal_formatted_string_signed(), by first casting the double datatype value into an integer datatype. For any values between 0.0 and -1.0, this casting produces the integer 0. Print the integer 0 does not result in a '-' sign, so the overall printing function for the double datatype prints values between 0.0 and -1.0 as positive values. E.g. printing the double value "-0.0567" produces a positive value "0.0567".
Impact of changes
Migration actions required
Documentation
None
Pull request type
Test results
--->
Reviewers
@0xc0170