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

Fix rounding bug when formatting floats with minimal_printf #15152

Merged
merged 3 commits into from
Nov 8, 2021

Conversation

sytsereitsma
Copy link
Contributor

Summary of changes

Fixed error in floating point rounding in minimal_printf implementation:

  • The decimals were 'rounded' after the integer part was printed. For example 6.99 with "%.1f" would be formatted as "6.10" instead of "7.0"
  • Rounding of numbers with 0 decimals only worked for positive numbers. For example -6.99 with "%.0f" would be formatted as "-5" instead of "-7".

Added unit tests for floating point rounding and string padding (aka prepending) in minimal_printf.

Impact of changes

Migration actions required

Documentation

None


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

[] 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


@ciarmcom ciarmcom added the release-type: patch Indentifies a PR as containing just a patch label Oct 23, 2021
@ciarmcom ciarmcom requested a review from a team October 23, 2021 21:00
@ciarmcom
Copy link
Member

@sytsereitsma, thank you for your changes.
@ARMmbed/mbed-os-maintainers please review.

Copy link
Contributor

@0xc0170 0xc0170 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please amend the commit message for 6d58014 (it should explain how is it fixing the bug)

@0xc0170
Copy link
Contributor

0xc0170 commented Oct 25, 2021

@sytsereitsma Thank you for contributing to Mbed OS. I've noticed you added also unit tests, great ! I left a git request above, please review

@mergify mergify bot dismissed 0xc0170’s stale review October 25, 2021 12:58

Pull request has been modified.

@0xc0170
Copy link
Contributor

0xc0170 commented Oct 28, 2021

I enabled to run basic checks (I expect style check to fail, few offenders there, please review once completed).

And added a bonus test for string padding
When decimal_prec is 0 and the value is negative and needs rounding subtract 1, instead of adding 1
When decimal_prec > 0 round before printing the integer part, instead of after
@mergify mergify bot added needs: CI and removed needs: work labels Nov 5, 2021
@mbed-ci
Copy link

mbed-ci commented Nov 6, 2021

Jenkins CI Test : ✔️ SUCCESS

Build Number: 2 | 🔒 Jenkins CI Job | 🌐 Logs & Artifacts

CLICK for Detailed Summary

jobs Status
jenkins-ci/mbed-os-ci_build-cloud-example-ARM ✔️
jenkins-ci/mbed-os-ci_build-cloud-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_unittests ✔️
jenkins-ci/mbed-os-ci_build-greentea-ARM ✔️
jenkins-ci/mbed-os-ci_build-greentea-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_build-example-ARM ✔️
jenkins-ci/mbed-os-ci_build-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_greentea-test ✔️

@0xc0170 0xc0170 merged commit 41744c7 into ARMmbed:master Nov 8, 2021
@mergify mergify bot removed the ready for merge label Nov 8, 2021
@mbedmain mbedmain added release-version: 6.15.1 Release-pending and removed release-type: patch Indentifies a PR as containing just a patch Release-pending labels Nov 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants