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

Mantissa retrieval? #156

Closed
jordanlewis opened this issue Dec 1, 2020 · 3 comments
Closed

Mantissa retrieval? #156

jordanlewis opened this issue Dec 1, 2020 · 3 comments

Comments

@jordanlewis
Copy link

Hi,

We're revisiting potential use of this library for https://github.com/cockroachdb/cockroach. https://github.com/cockroachdb/apd has served our needs well so far, but we're taking another look here because of performance. apd.Decimal always uses an "inflated" representation, which is good for code simplicity, but not for performance. Now that this library is tested against GDA (#117), we'd like to reconsider using it for the improved performance offered by the decimal.Big compact representation.

One difficulty (that I think was raised long ago, back in 2016) is that we rely on retrieving the mantissa of a decimal in order to encode it on disk. I'm not sure how to retrieve the mantissa of a decimal.Big when its either in compact or inflated form.

Would you be able to offer some advice, please? Perhaps this is a simple question - I'm by no means an expert on decimal representation.

Here's the exponent/mantissa retrieval code that we'd need to implement against decimal.Big, for reference:

https://github.com/cockroachdb/cockroach/blob/master/pkg/util/encoding/decimal.go#L96-L148

@ericlagergren
Copy link
Owner

Commenting here to remind myself to read this when I get home today.

@ericlagergren
Copy link
Owner

Immediately, you could use Raw. If the uint64 is not 1<<64-1, then it's "valid." Otherwise, the big.Int is. Or even Decompose could work.

However, like I mentioned before I am open to a more specific API.

@jordanlewis
Copy link
Author

Thanks. After spending time playing with the code, I now understand something I didn't before, which is that the compact and inflated representations are both "just" the mantissa, without any special encoding. I think the Raw access method is perfectly fine for our use case, so I'll just close this.

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

No branches or pull requests

2 participants