Commit 1704c621

1704c621b8ebMerged

Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 1 file · ~1 modified

Description

README: document --int-overflow=promote

Integer overflow raising (rather than promoting to Bignum) in the default mode is by design -- it is safe, never silently wrong. For CRuby-compatible arbitrary-precision behavior, --int-overflow=promote escalates every integer operation to Bigint. Document the three modes (raise/wrap/promote) under Options and cross-reference from the Bigint feature note.

Closes #1250

Co-Authored-By: Claude Opus 4.8 [email protected]

Details

Commit
1704c621b8eb
Parent
2008568b153b

README.mdmodifiedView file

@@ -82,8 +82,25 @@
8282 ./spinel app.rb -c # generates app.c only
8383 ./spinel app.rb -S # prints C to stdout
8484 ./spinel app.rb --rbs sig # seed inference from .rbs files under sig/
85+./spinel app.rb --int-overflow=promote # overflow promotes to Bigint (CRuby-compatible)
8586 ```
8687
88+#### Integer overflow
89+
90+Integers are native fixed-width words. `--int-overflow=MODE` selects how
91+`+`/`-`/`*` behave when a result exceeds that width:
92+
93+- `raise` (default) -- raise on overflow. Safe (never silently wrong or
94+ undefined), but `9223372036854775807 + 1` raises instead of returning a
95+ Bignum.
96+- `wrap` -- silent two's-complement wrap. Fastest, no check.
97+- `promote` -- escalate to arbitrary-precision `Integer` (Bigint), matching
98+ CRuby. `9223372036854775807 + 1` returns `9223372036854775808`.
99+
100+In the default mode, integer locals that an obvious growth pattern would
101+overflow (e.g. a `q = q * k` accumulator) are still auto-promoted to Bigint;
102+`promote` extends that to every integer operation.
103+
87104 ### RBS type signatures
88105
89106 Spinel can read RBS files to seed the analyzer. When invoked with
@@ -245,8 +262,9 @@
245262 `scan(/re/)`, `split(/re/)`.
246263
247264 **Bigint**: Arbitrary precision integers via mruby-bigint. Auto-promoted
248-from loop multiplication patterns (e.g. `q = q * k`). Linked as static
249-library -- only included when used.
265+from loop multiplication patterns (e.g. `q = q * k`), or from every integer
266+operation under `--int-overflow=promote` (see [Integer overflow](#integer-overflow)).
267+Linked as static library -- only included when used.
250268
251269 **Fiber**: Cooperative concurrency via `ucontext_t`. `Fiber.new`,
252270 `Fiber#resume`, `Fiber.yield` with value passing. Captures free