Skip to content

fix(print): BigInt/Ratio/BigDecimal print past std's 64-limb bound (CLJW-BIGINT-STR-PLACEHOLDER) - #84

Merged
BuddhiLW merged 1 commit into
stagingfrom
swarm/bigint-str
Oct 22, 2026
Merged

BuddhiLW merged 1 commit into
stagingfrom
swarm/bigint-str

Conversation

@BuddhiLW

Copy link
Copy Markdown
Owner

std's big-int {f} formatter renders through a 64-limb stack buffer
(about 1233 digits) and writes the literal "(BigInt)" past it, so
(str (reduce *' (range 1N 1000N))) answered "(BigInt)".

  • runtime/numeric/decimal_text.zig: writeDecimal / decimalAlloc /
    writeFraction, no width ceiling. Every BigInt, Ratio and BigDecimal
    print path (str, pr-str, .toString, print, json, analyzer literal
    round-trip, BigDecimal digit/plain renders) goes through it.
  • rationalize of a BigDecimal computes 10^|scale| exactly instead of a
    1040-byte digit-string round-trip, so it has no digit/scale ceiling.
  • big_decimal/allocFromDecimalString sizes its digit scratch to the
    mantissa (was a 512-digit cap), so bigdec reads any width.
  • format %s of a BigInt/BigDecimal is .toString like clj: no N/M suffix.

Pinned by suites/bignum_print_width_test (3500!, 10887 digits) and the
clj-oracle corpus test/diff/clj_corpus/bignum_print_width.txt (18/18
matched against JVM clj).

std's big-int `{f}` formatter renders through a 64-limb stack buffer
(about 1233 digits) and writes the literal "(BigInt)" past it, so
(str (reduce *' (range 1N 1000N))) answered "(BigInt)".

- runtime/numeric/decimal_text.zig: writeDecimal / decimalAlloc /
  writeFraction, no width ceiling. Every BigInt, Ratio and BigDecimal
  print path (str, pr-str, .toString, print, json, analyzer literal
  round-trip, BigDecimal digit/plain renders) goes through it.
- rationalize of a BigDecimal computes 10^|scale| exactly instead of a
  1040-byte digit-string round-trip, so it has no digit/scale ceiling.
- big_decimal/allocFromDecimalString sizes its digit scratch to the
  mantissa (was a 512-digit cap), so bigdec reads any width.
- format %s of a BigInt/BigDecimal is .toString like clj: no N/M suffix.

Pinned by suites/bignum_print_width_test (3500!, 10887 digits) and the
clj-oracle corpus test/diff/clj_corpus/bignum_print_width.txt (18/18
matched against JVM clj).

Smell-audited: 2: fixed-buffer formatter ceiling swept across all print paths; two sibling width caps (bigdec parse, rationalize) removed in the same sweep
@BuddhiLW
BuddhiLW merged commit 302101f into staging Oct 22, 2026
3 checks passed
@BuddhiLW
BuddhiLW deleted the swarm/bigint-str branch October 22, 2026 22:13
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