Simplify midpoint computation in AbstractDiscreteDistribution.solveInverseCumulativeProbability#2
Closed
leventov wants to merge 3 commits intoapache:masterfrom
Closed
Simplify midpoint computation in AbstractDiscreteDistribution.solveInverseCumulativeProbability#2leventov wants to merge 3 commits intoapache:masterfrom
leventov wants to merge 3 commits intoapache:masterfrom
Conversation
Simplifies midpoint calculation in `AbstractDiscreteDistribution.solveInverseCumulativeProbability()` by leveraging unsigned shift instruction. Not only this allows avoiding a branch, `<<< 1` is also cheaper than `/ 2` in Java, see https://lemire.me/blog/2017/05/09/signed-integer-division-by-a-power-of-two-can-be-expensive/
chtompki
pushed a commit
to chtompki/commons-statistics
that referenced
this pull request
Jul 8, 2019
…tive_module Statistics 7 descriptive module
aherbert
reviewed
Jul 22, 2020
| * There will never be an overflow in both calculation methods | ||
| * for xm at the same time | ||
| */ | ||
| xm = lower + (upper - lower) / 2; |
Contributor
There was a problem hiding this comment.
Why don't we just use this formula all the time and avoid the if statement? This is single extra addition but does not require a branch.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Avoiding a cumbersome branch inside the loop in
AbstractDiscreteDistribution.solveInverseCumulativeProbability()by usinglongvariables.