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

Remove BigDecimal from HighPrecisionMoney.fromPreciseAmount #443

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

benko-balog
Copy link
Contributor

@benko-balog benko-balog commented Oct 13, 2022

Added 3 rounding algorithms to substitute the methods used on BigDecimal

@benko-balog benko-balog marked this pull request as ready for review October 13, 2022 12:59
@benko-balog benko-balog requested a review from yanns as a code owner October 13, 2022 12:59
Copy link
Contributor

@clemniem clemniem left a comment

Choose a reason for hiding this comment

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

lgtm

// Eg: 4 for 123.456
val mostSignificantDigitOfFraction :: rest = fractionDigitsList

if (mostSignificantDigitOfFraction == 5 && rest.forall(_ == 0))
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure where this number 5 is coming from. Can you explain?

Copy link
Contributor Author

@benko-balog benko-balog Oct 13, 2022

Choose a reason for hiding this comment

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

For the half even rounding we are interested in if we have exactly .5 in the fractional part. If it's lower or bigger it's down or up rounding, but if it's exactly something.5 we need to check for the integer's least significant digit (that's the next line in the code).
So this line is checking if the first digit after the decimal point is 5 and all the others are non-existent or zeros (to handle the cases of .50, .500, etc )

(Maybe firstDigitAfterDecimalPoint would be a better name for mostSignificantDigitOfFraction) 🤔

Copy link
Contributor

@yanns yanns left a comment

Choose a reason for hiding this comment

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

I'm just wondering if we are not optimizing too much.
I let you judge.

We can also look at https://github.com/JavaMoney/jsr354-ri-bp/blob/master/src/main/java/org/javamoney/moneta/FastMoney.java for some possible optimizations. The javadoc also mentions limitations.

@benko-balog
Copy link
Contributor Author

For now, we are keeping this PR without merging to see if the previous changes were enough to improve the performance.
We are checking if there are more tests we could add, to make sure roundings are working correctly.

@clemniem
Copy link
Contributor

@benko-balog Should we just close this for now and re-open if ever needed?

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.

4 participants