Scale Factor Needs To Handle Non Binary Numbers#49
Merged
davisadam10 merged 1 commit intodevfrom Apr 16, 2026
Merged
Conversation
The scale factor target/fit (e.g. 3840/6560 = 24/41) can have no exact IEEE 754 representation. Previously value * (target/fit) lost precision, causing incorrect rounding results (e.g. 3838 instead of 3840). Fix: keep the scale factor as a numerator/denominator ratio internally and compute (value * numerator) / denominator. This defers the division so intermediate products are exact for integer inputs within 2^53. Added regression test, updated golden vectors, removed redundant internal scaling functions, and updated documentation.
9603691 to
c7319e6
Compare
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.
Fix floating-point precision loss in template scale factor computation.
Scale factors like 3840/6560 (24/41) have no exact IEEE 754 binary representation.
The old code computed a single double then multiplied, producing values like 3839.999...
instead of 3840).
The fix keeps the scale factor as a numerator/denominator ratio internally and computes (value * numerator) / denominator, deferring the division so intermediate products remain exact for integer inputs.