-
Notifications
You must be signed in to change notification settings - Fork 7
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
base: main
Are you sure you want to change the base?
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.
lgtm
// Eg: 4 for 123.456 | ||
val mostSignificantDigitOfFraction :: rest = fractionDigitsList | ||
|
||
if (mostSignificantDigitOfFraction == 5 && rest.forall(_ == 0)) |
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.
I'm not sure where this number 5 is coming from. Can you explain?
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.
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) 🤔
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.
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.
For now, we are keeping this PR without merging to see if the previous changes were enough to improve the performance. |
@benko-balog Should we just close this for now and re-open if ever needed? |
Added 3 rounding algorithms to substitute the methods used on BigDecimal