Skip to content

Implement round(number, digits) for digits != 0 - #1521

Merged
windelbouwman merged 4 commits into
RustPython:masterfrom
janrg:round_to_n_decimals
Oct 14, 2019
Merged

windelbouwman merged 4 commits into
RustPython:masterfrom
janrg:round_to_n_decimals

Conversation

@janrg

@janrg janrg commented Oct 13, 2019

Copy link
Copy Markdown
Contributor

For most cases uses rust's round function to round via:
round(number, decimals) = round(number * 10^decimals) / 10^decimals

  • skips rounding if rounding would not affect digits within double precision (also covers cases where the above implementation would overflow the f64 exponent)
  • also handles arbitrarily negative values for decimals

@youknowone

Copy link
Copy Markdown
Member

Thanks for contributing! Will you add some test cases about new code? There are python test snippets about float in tests/snippets/floats.py.

@janrg

janrg commented Oct 13, 2019

Copy link
Copy Markdown
Contributor Author

Will do. Might be a few days though as I won't be home before wednesday

@janrg
janrg force-pushed the round_to_n_decimals branch from 01dc6cc to 4fd38e6 Compare October 14, 2019 15:06
@janrg

janrg commented Oct 14, 2019

Copy link
Copy Markdown
Contributor Author

Found some time to write a few tests and also noticed a range of input values where it wasn't working properly yet. Fixed.

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.

3 participants