Skip to content

Keep binary prefixes below their exact size thresholds - #71

Merged
wolph merged 1 commit into
wolph:developfrom
ShahadatTest:fix/scale-1024-prefix-boundaries
Nov 1, 2026
Merged

wolph merged 1 commit into
wolph:developfrom
ShahadatTest:fix/scale-1024-prefix-boundaries

Conversation

@ShahadatTest

Copy link
Copy Markdown
Contributor

scale_1024(1024**5 - 1, 9) currently returns (0.9999999999999991, 5), selecting PiB before the input reaches one PiB. The logarithm also rounds the float immediately below 1024 up to the KiB boundary.

Check the estimated prefix against its exact integer threshold before converting the input to float, and lower it when the threshold has not been reached. This preserves the existing scaling calculation, available-prefix limit and handling of small or nonpositive inputs. Document how prefix boundaries are selected.

Regression coverage checks integer and adjacent representable float values below, at and above all eight binary-prefix boundaries, plus a capped-prefix control. Against unchanged develop, 12 of the 17 new parametrized cases fail and 5 pass; all pass after the fix.

Validation on Windows:

  • Python 3.10.20 and 3.12.10: full suite/doctests, 445 passed, 5 skipped each; 100% statement and branch coverage. Skips are existing tests requiring unavailable IANA timezone data.
  • Ruff: full lint and changed-file formatting pass.
  • Whole-project mypy, basedpyright and Pyrefly pass with no errors.
  • Final diff inspected; git diff --check passes.

Checked current contribution instructions and existing issues/PRs; no overlapping open fix was found.

AI assistance: OpenAI Codex investigated, implemented and tested this change at the account owner's request, new 1ta koro (make one new contribution). No independent human review is claimed.

@wolph
wolph merged commit 90973af into wolph:develop Nov 1, 2026
17 checks passed
wolph added a commit that referenced this pull request Nov 1, 2026
#71

#71 compares the input with the exact integer threshold before the
float conversion. A numeric type that defines __le__ and __float__ but
not __lt__ passed on 4.1.4 and raised TypeError on that comparison. Only
an int needs the exact comparison, so every other type goes through
float() as 4.1.4 did. A test pins such a type.
wolph added a commit that referenced this pull request Nov 1, 2026
@wolph

wolph commented Nov 1, 2026

Copy link
Copy Markdown
Owner

Thank you for the fix and the thorough tests! I've kept the exact comparison for ints only, so a numeric type without __lt__ still goes through float() as before (8400a58), and added a changelog entry with the before and after values. Merged beyond that :)

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