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

@@ -534,6 +534,11 @@
534534 - **No encoding**: assumes UTF-8/ASCII
535535 - **No general lambda calculus**: deeply nested `-> x { }` with `[]` calls
536536
537+A few cases deliberately diverge from CRuby because the CRuby behavior needs a
538+feature Spinel does not implement (e.g. `Integer#**` with a negative exponent
539+raises instead of returning a `Rational`). These are listed in
540+[docs/INCOMPATIBILITIES.md](docs/INCOMPATIBILITIES.md).
541+
537542 ## Dependencies
538543
539544 - **Build time**: [libprism](https://github.com/ruby/prism) (C library),