Skip to content

Scale Factor Needs To Handle Non Binary Numbers#49

Merged
davisadam10 merged 1 commit intodevfrom
hotfix/non_binary_numbers
Apr 16, 2026
Merged

Scale Factor Needs To Handle Non Binary Numbers#49
davisadam10 merged 1 commit intodevfrom
hotfix/non_binary_numbers

Conversation

@davisadam10
Copy link
Copy Markdown
Collaborator

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.

@davisadam10 davisadam10 changed the base branch from main to dev April 16, 2026 17:43
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.
@davisadam10 davisadam10 force-pushed the hotfix/non_binary_numbers branch from 9603691 to c7319e6 Compare April 16, 2026 18:46
@davisadam10 davisadam10 merged commit 373fab0 into dev Apr 16, 2026
20 checks passed
@davisadam10 davisadam10 deleted the hotfix/non_binary_numbers branch April 16, 2026 19:37
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.

1 participant