-
Notifications
You must be signed in to change notification settings - Fork 177
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
NumericDecodeUtils.decodeBinary(byteBuf)
returns wrong result for BigDecimal
between 1 and -1
#556
Comments
One can give a look to the jdbc version to understand how to handle a negative weight: I forgot to say that the bug occurs only with FORMAT_BINARY |
possible fix, not sure, not tested, if it works when scale > 4 |
Based on my understanding of the algorithm descripted in this paper, the same used by postgres as documented in numeric.c, I implemented decodeBinary from scratch as follows:
The unit-tests below runs sucessfully:
Looking forward for you feedback and hope my suggestion can help fixing the bug. |
NumericDecodeUtils.decodeBinary(byteBuf)
returns wrong result for BigDecimal
between 1 and -1
Thanks for reporting the issue and your effort to provide a fix. I confirm that this is a bug that we haven't caught because we didn't had it tested with the appropriate data. Are you interested in submitting a pull request? If so, we have release week this week so we can include a fix. |
…wrong result for BigDecimal between 1 and -1
Yes, I've just submitted the pull request. |
Replace String.format(…) with our own digit rendering and padding to reduce computation on hot code paths. [resolves #558][#556] Signed-off-by: Mark Paluch <[email protected]>
Replace String.format(…) with our own digit rendering and padding to reduce computation on hot code paths. [resolves #558][#556] Signed-off-by: Mark Paluch <[email protected]>
Bug Report
Versions
Current Behavior
The BigDecimal 0.99 is decoded as 9900.00. The problem occurs for each big decimal between -1 and 1.
In the other cases works correctly.
Steps to reproduce
To reproduce, please run
short[] array = new short[]{1, -1, 0, 2, 9900}
Expected behavior/code
0.99 istead of 9900.00
Possible Solution
The problem is that a negative weight is not handled.
As stated in https://github.com/postgres/postgres/blob/master/src/backend/utils/adt/numeric.c#L263
The text was updated successfully, but these errors were encountered: