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

optimize conversion #329

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

optimize conversion #329

wants to merge 1 commit into from

Conversation

decanus
Copy link

@decanus decanus commented Sep 25, 2023

No description provided.

Copy link
Member

@mwoss mwoss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given implementation does not match the function description. BigInt should return integer component of decimal as BigInt and the proposed implementation just returns the underneeth coefficient scaled by 10^Exponent(). It's not the same thing. For example, for decimal 36235.1351 the current implementation return 36235 and yours implementation returns 362351351

i := &big.Int{}
i.SetString(scaledD.String(), 10)
return i
return new(big.Int).Set(d.value)
Copy link
Contributor

@serprex serprex Apr 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return new(big.Int).Set(d.value)
scaledD := d.rescale(0)
return new(big.Int).Set(scaledD.value)

@mwoss this corrects your feedback. btw, why does rescale need to return a new Decimal when exp == d.exp? would expect with non-mutable API it'd be fine to return d

ofc, with d.rescale always allocating a fresh bigint, it'd be safe to return scaledD.value itself

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created #359

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on that :D


btw, why does rescale need to return a new Decimal when exp == d.exp? would expect with non-mutable API it'd be fine to return d

If I remember correctly we have done it because, in a few places in the codebase, we expect that rescale always returns a new decimal, so we can safely perform operations on d.value. It could be improved for sure, but we would need to track down all those places and safely update the code and docs.

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

Successfully merging this pull request may close these issues.

3 participants