Merged
Conversation
The value used in the test is subject to discrepancies using apd Ln implementation between amd64 and arm64
5ae2790 to
7e44ce9
Compare
9629afd to
0c2038e
Compare
xmariachi
approved these changes
Apr 2, 2025
fernandofcampos
approved these changes
Apr 3, 2025
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.
Purpose of Changes and their Description
This fixes the natural logarithmic calculation non-deterministic behaviour by switching from apd's implementation to a custom one.
For instance with the following snippet using apd:
It outputs to
0.4876649916811116824516548471782886on arm64 and0.4876649916811116824516548471782887on amd64, which can cause app hash mismatch.The root cause is that apd in some cases uses a first approximation with the standard
math.Log()which is platform dependent, I've raised an issue on apd.To solve the issue I've followed a similar strategy to Osmosis by implementing the binary logarithm algorithm described here, with some adaptations to make it work with
apd.Decimal. The natural logarithm is then derived from it.The precision seems to slightly differ from apd's implementation but in the order of
1ulpon non close to limits values.I've added some benchmark, and here's the benchmark results comparing with old
apdimplementation:It is much slower with more allocations, this seems not to be used intensively in the codebase so I'd tend to consider it ok. There's some perf improvements that can be made using different approaches of ln calculation though.
Are these changes tested and documented?
Unreleasedsection ofCHANGELOG.md?