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

Floating inputs for round() should return a Floating output when ndigit is 0 #217

Merged
merged 4 commits into from
Feb 27, 2024

Conversation

faze-geek
Copy link
Contributor

On main -

>>> round(12.3,0)
12
>>> round(12.7,0)
13

On branch -

# This is inline with cpython
>>> round(12.3,0)
12.0
>>> round(12.7,0)
13.0
>>> round(-12.7,0)
-13.0
>>> round(-12.3,0)
-12.0

@faze-geek
Copy link
Contributor Author

faze-geek commented Feb 26, 2024

Ideally negative ndigit should also behave differently (in pocketpy an error message is returned). I'm not sure if it is intended due to performance, so I have not modified it.
Python -

>>> round(123.45,-1)
120.0
>>> round(123.45,-2)
100.0

@blueloveTH
Copy link
Collaborator

If is_int(args[0]), round should return it directly.

>>> round(1123,0)
1123
>>> round(1123,2)
1123
>>> round(1123,214)
1123

@blueloveTH blueloveTH merged commit 5100f4e into pocketpy:main Feb 27, 2024
8 checks passed
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