-
Notifications
You must be signed in to change notification settings - Fork 351
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
Decimal
- add checked_div_euclid
#1365
Conversation
f4626c8
to
7ebbe29
Compare
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.
Okay, it took me a bit to figure out what euclid division actually does. It seems to be relatively straight forward as long as no negative numbers are involved. I found https://www.probabilisticworld.com/euclidean-division-integer-division-with-remainders/ useful.
Looking at the Decimal implementation, it is possible to trigger unnecessary errors in the current implementation (fails with panicked at 'called Result::unwrap()
on an Err
value: Overflow'):
// The regular division result (340282366920938463463.6) would be out of range.
assert_eq!(
dec("170141183460469231731.8")
.checked_div_euclid(dec("0.5"))
.unwrap(),
dec("340282366920938463463")
);
I suggest splitting the uint implementations and the decimal implementation in two PRs and try to find a better implementation for decimals.
Decimal
/Uint
- add checked_div_euclid
Decimal
- add checked_div_euclid
@webmaster128 Euclidean division seems to be defined as an operation between two integers. See here. Since we're dealing with decimals here, it doesn't seem applicable. |
Ah, good point. Thanks for pointing that out! It is also not implemented for float types in Rust (https://doc.rust-lang.org/std/?search=checked_div_euclid). |
Closing due to #1365 (comment). The int implementations are here: #1376 |
part of #1186