Commit 63f7f450
63f7f4505469Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 7 files · +3 added · ~4 modified
Description
Raise on Integer#** with a negative exponent
CRuby evaluates a negative integer exponent to a Rational (2 ** -1 => 1/2). Spinel has no Rational and silently truncated the result to 0. Raise RangeError("negative exponent") instead -- a deliberate, documented incompatibility -- so the missing-Rational case is visible rather than silently wrong.
Route Integer ** through a new sp_int_pow helper that checks the exponent, and add the same guard to sp_bigint_pow (promote mode) and sp_poly_pow (poly-dispatched int base). Float ** is unchanged -- 2.0 ** -1 stays 0.5, matching CRuby. Document the divergence in docs/INCOMPATIBILITIES.md, linked from the README Limitations section.
Fixes #1220
Co-Authored-By: Claude Opus 4.8 [email protected]
Details
- Commit
- 63f7f4505469
- Parent
- d7c9c49cbafc
README.mdmodifiedView file
- **No encoding**: assumes UTF-8/ASCII- **No general lambda calculus**: deeply nested `-> x { }` with `[]` callsA few cases deliberately diverge from CRuby because the CRuby behavior needs afeature Spinel does not implement (e.g. `Integer#**` with a negative exponentraises instead of returning a `Rational`). These are listed in[docs/INCOMPATIBILITIES.md](docs/INCOMPATIBILITIES.md).## Dependencies- **Build time**: [libprism](https://github.com/ruby/prism) (C library),docs/INCOMPATIBILITIES.mdaddedView file
Loading diff…
lib/sp_bigint.cmodifiedView file
Loading diff…
lib/sp_runtime.hmodifiedView file
Loading diff…
spinel_codegen.rbmodifiedView file
Loading diff…
test/integer_pow_negative_exponent.rbaddedView file
Loading diff…
test/integer_pow_negative_exponent.rb.expectedaddedView file
Loading diff…