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

Improve averageBigInteger and sumBigInteger precision/conversion #286

Merged
merged 1 commit into from
Apr 11, 2022

Conversation

simonbasle
Copy link
Member

This commit improves the precision and conversion behavior of MathFlux
sumBigInteger and averageBigInteger methods. These method better deal with
fractional types by internally summing using a BigDecimal rather than a
BigInteger. As a result, the only lossy step is at the end when the result is
effectively presented as a BigInteger:

  • sum: remaining fractional part of the BigDecimal sum is dropped
  • average: the division by count is applied, then the result's fractional
    part 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.

@simonbasle simonbasle added this to the 3.4.8 milestone Apr 8, 2022
@simonbasle simonbasle added area/reactor-extra This belongs to the reactor-extra module type/enhancement A general enhancement labels Apr 8, 2022
@simonbasle simonbasle self-assigned this Apr 8, 2022
@simonbasle simonbasle requested a review from a team April 8, 2022 14:28
@simonbasle
Copy link
Member Author

cc @Sunshow, I actually discovered a few drawbacks with your original approach and went a slightly different direction.

@Sunshow
Copy link

Sunshow commented Apr 8, 2022

awesome.

Copy link
Contributor

@OlegDokuka OlegDokuka left a comment

Choose a reason for hiding this comment

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

LGTM

@simonbasle simonbasle merged commit 0bcce82 into 3.4.x Apr 11, 2022
@simonbasle simonbasle deleted the fixBigInteger branch April 11, 2022 16:34
@reactorbot
Copy link

@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 main 🙇

simonbasle added a commit that referenced this pull request Apr 11, 2022
simonbasle added a commit to reactor/reactor-kotlin-extensions that referenced this pull request Jun 17, 2022
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.
simonbasle added a commit to reactor/reactor-kotlin-extensions that referenced this pull request Jun 17, 2022
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/reactor-extra This belongs to the reactor-extra module type/enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants