Skip to content

Simplify midpoint computation in AbstractDiscreteDistribution.solveInverseCumulativeProbability#2

Closed
leventov wants to merge 3 commits intoapache:masterfrom
leventov:patch-1
Closed

Simplify midpoint computation in AbstractDiscreteDistribution.solveInverseCumulativeProbability#2
leventov wants to merge 3 commits intoapache:masterfrom
leventov:patch-1

Conversation

@leventov
Copy link
Member

@leventov leventov commented Mar 16, 2019

Avoiding a cumbersome branch inside the loop in AbstractDiscreteDistribution.solveInverseCumulativeProbability() by using long variables.

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/
@leventov leventov changed the title Simplify midpoint computation in solveInverseCumulativeProbability Simplify midpoint computation in AbstractDiscreteDistribution.solveInverseCumulativeProbability Mar 16, 2019
chtompki pushed a commit to chtompki/commons-statistics that referenced this pull request Jul 8, 2019
…tive_module

Statistics 7 descriptive module
* There will never be an overflow in both calculation methods
* for xm at the same time
*/
xm = lower + (upper - lower) / 2;
Copy link
Contributor

Choose a reason for hiding this comment

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

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.

@asfgit asfgit closed this in 494b551 Sep 27, 2021
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.

2 participants