-
Notifications
You must be signed in to change notification settings - Fork 21
Add decimals parameter to sc.round function
#3793
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
Conversation
Co-authored-by: MridulS <5363860+MridulS@users.noreply.github.com>
Co-authored-by: MridulS <5363860+MridulS@users.noreply.github.com>
decimals parameter to sc.round function
| factor = 10**decimals | ||
| result = _call_cpp_func(_cpp.rint, factor * x) / factor |
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.
I'd be worried about overflows here.
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.
@copilot what do you think?
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.
Valid concern. The implementation uses rint(x * 10^d) / 10^d, which can indeed overflow for very large values combined with large positive decimals. However, this is the same algorithm that NumPy uses (as documented in their docstring), and they accept this limitation.
I've added a note in the docstring (7560eb4) to document this behavior explicitly, referencing that it matches NumPy's approach.
Co-authored-by: MridulS <5363860+MridulS@users.noreply.github.com>
|
@copilot I see these errors in the CI: |
Co-authored-by: MridulS <5363860+MridulS@users.noreply.github.com>
sc.roundfunction in/src/scipp/core/math.pynp.roundAPI signature (acceptsdecimalsparameter)/tests/core/math_test.pysc.roundfunction to acceptdecimalsparameterDataGroup.roundmethod to pass the decimals parametercpp_classes.pyidecimalsparameterOriginal prompt
decimalstosc.roundfunction #3327💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.