-
Notifications
You must be signed in to change notification settings - Fork 83
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
Improve averageBigInteger and sumBigInteger precision/conversion #286
Conversation
cc @Sunshow, I actually discovered a few drawbacks with your original approach and went a slightly different direction. |
awesome. |
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
@simonbasle this PR seems to have been merged on a maintenance branch, please ensure the change is merge-forwarded to intermediate maintenance branches and up to |
This commit adapts to changes in precision in addons' sumBigInteger that were introduced in the previously referenced snapshot (3.4.8). It also upgrades the dependency to reflect the latest core and addons snapshots, as the project was previously out of sync. For the change in sumBigInteger, see reactor/reactor-addons#286: Now the loss of precision is only triggered at the end of the sum, avoiding lossy conversion of each floating point number that is being summed.
This commit adapts to changes in precision in addons' sumBigInteger that were introduced in the previously referenced snapshot (3.4.8). It also upgrades the dependency to reflect the latest core and addons snapshots, as the project was previously out of sync. For the change in sumBigInteger, see reactor/reactor-addons#286: Now the loss of precision is only triggered at the end of the sum, avoiding lossy conversion of each floating point number that is being summed.
This commit improves the precision and conversion behavior of
MathFlux
sumBigInteger
andaverageBigInteger
methods. These method better deal withfractional types by internally summing using a
BigDecimal
rather than aBigInteger
. As a result, the only lossy step is at the end when the result iseffectively presented as a
BigInteger
:sum
: remaining fractional part of the BigDecimal sum is droppedaverage
: the division bycount
is applied, then the result's fractionalpart is dropped
Previously the fractional part would be progressively dropped by implicit
conversion of each incoming element to
long
.Similar to precision improvement done in #260/#261 and earlier iteration done
in #284.