Skip to content
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

minimal-printf: fix display decimals between -1 to 0 incorrect issue #13865

Closed
wants to merge 1 commit into from

Conversation

Linguanghsou
Copy link

@Linguanghsou Linguanghsou commented Nov 5, 2020

Summary of changes

Fixes "minimal-printf doesn't display decimals between -1 to 0 correctly" listed in #13783

In original mbed_minimal_formatted_string_signed(), the type of augment value is a signed integer. Given a double value -0.00139 being printed, its integer part is 0 (-0 is equal to 0), so the condition "if (value < 0)" is false and it was handled as a positive decimal like 0.00139. In the fix, the value is a double type. Given a double value -0.00139, the condition "if (value < (double)0)" is true and it is handled as a negative decimal as expected.

Impact of changes

Migration actions required

Documentation


Pull request type

[x] Patch update (Bug fix / Target update / Docs update / Test update / Refactor)
[] Feature update (New feature / Functionality change / New API)
[] Major update (Breaking change E.g. Return code change / API behaviour change)

Test results

double d = -0.00139;
printf("d = %f\r\n",d);

--->
d = -0.001391

[] No Tests required for this change (E.g docs only update)
[] Covered by existing mbed-os tests (Greentea or Unittest)
[x] Tests / results supplied as part of this PR

Reviewers


…In original mbed_minimal_formatted_string_signed(), the type of augment value is a signed integer. Given a double value -0.00139 being printed, its integer part is 0 (-0 is equal to 0), so the condition "if (value < 0)" is false and it was handled as a positive decimal like 0.00139. In the fix, the value is a double type. Given a double value -0.00139, the condition "if (value < (double)0)" is true and it is handled as a negative decimal as expected.
@0xc0170 0xc0170 changed the title minimal-printf: fix display decimals between -1 to 0 incorrect issue. In original mbed_minimal_formatted_string_signed(), the type of augment value is a signed integer. Given a double value -0.00139 being printed, its integer part is 0 (-0 is equal to 0), so the condition "if (value < 0)" is false and it was handled as a positive decimal like 0.00139. In the fix, the value is a double type. Given a double value -0.00139, the condition "if (value < (double)0)" is true and it is handled as a negative decimal as expected. minimal-printf: fix display decimals between -1 to 0 incorrect issue Nov 5, 2020
@0xc0170 0xc0170 requested review from a team November 5, 2020 09:30
@0xc0170 0xc0170 added needs: review release-type: patch Indentifies a PR as containing just a patch labels Nov 5, 2020
@0xc0170
Copy link
Contributor

0xc0170 commented Nov 12, 2020

We should continue with 13872. It does not have a test case yet.

I'll close this one.

@0xc0170 0xc0170 closed this Nov 12, 2020
@mergify mergify bot removed needs: review release-type: patch Indentifies a PR as containing just a patch labels Nov 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants