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 incorrect result for decimal division #963

Merged
merged 3 commits into from
Jun 12, 2019

Conversation

martint
Copy link
Member

@martint martint commented Jun 11, 2019

When the first divisor doesn't fit in the first "32-bit" digit of the
dividend and the whole 64-bit dividend is too big to fit in an unsigned
long, the value becomes negative and regular division breaks down.

Fixes #958

@cla-bot cla-bot bot added the cla-signed label Jun 11, 2019
Simplify the implementation based on Hacker's Delight 9-3
When the first divisor doesn't fit in the first "32-bit" digit of the
dividend and the whole 64-bit dividend is too big to fit in an unsigned
long, the value becomes negative and regular division breaks down.
@martint
Copy link
Member Author

martint commented Jun 11, 2019

I updated the code to use the existing divideUnsigned, which is more efficient than Java's Long.divideUnsigned when one of the numbers is large (i.e., negative).

@martint martint merged commit 3726e22 into trinodb:master Jun 12, 2019
@electrum electrum added this to the 315 milestone Jun 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

Incorrect result for decimal division
3 participants