-
Notifications
You must be signed in to change notification settings - Fork 627
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
base: master
Are you sure you want to change the base?
optimize conversion #329
Conversation
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.
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) |
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.
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
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.
Created #359
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.
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.
No description provided.