Use Long arithmetics in ju.Random, instead of Doubles. #5195
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.
We've come full circle. Back in 5e27def, we had optimized
ju.Random
by usingDouble
s instead ofLong
s. This commit optimizes it further by ... usingLong
s instead ofDouble
s.It is still more complicated than using the spec as is. We compute things in a slightly different way, that allows some internal constant-folding to happen. This way, there are as many underlying int multiplications as there were double multiplications before (namely 4).
Here is the breakdown of how many operations in which category we have before and after.
x | 0
)That's 4 more primitive operations, but we removed 9 operations involving
Double
s to replace them byInt
operations only.I did not do any benchmarks of this. I'm not currently on a machine that is suited to benchmarking. I can do some benchmarks in a week, if that is desirable.
Produced code before:
Produced code after:
Diff of
setSeed
(next
is a complete rewrite, so no useful diff there):