-
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
minimal-printf: fix display decimals between -1 to 0 incorrect issue. #13784
Conversation
@Linguanghsou, thank you for your changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add details to the commit message? How is this fixing the issue, I am interested in how the casting here (changing argument type and later casting it) works
In original mbed_minimal_formatted_string_signed() above, the type of agument 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 modification listed below, 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.
|
Thanks for the explanation, can you amend the commit message as requested? |
…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.
Done, please check the commit message. |
@Linguanghsou I can see two commits and one merge commit, can you rebase to squash all three into one ? |
There was a different suggestion to fix this: #13783 (comment) . isn't this better than what is proposed here? |
…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 Please noted that I created #13865 to replace current PR to have only one commit message. |
Summary of changes
Fixes "minimal-printf doesn't display decimals between -1 to 0 correctly" listed in #13783
Impact of changes
Migration actions required
Documentation
Pull request type
Test results
double d = -0.00139;
printf("d = %f\r\n",d);
--->
d = -0.001391
Reviewers