Merge loops/sx-vm-extensions into architecture: rational cleanup

(/ int int) returns float per spec/host parity (was leaking exact rationals
into arithmetic + CSS, e.g. tw-opacity 1/20); rational operand still yields
exact rational. number?/exact? recognise Rational. test-rationals typo fix.
OCaml conformance 4834->4863, rational/numeric-tower/arithmetic/tw-opacity green.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-29 07:03:30 +00:00
3 changed files with 15 additions and 7 deletions

View File

@@ -218,7 +218,14 @@ let () =
Number (List.fold_left (fun acc a -> acc *. as_number a) 1.0 args));
register "/" (fun args ->
match args with
| [Integer a; Integer b] -> make_rat a b
(* (/ int int): exact when divisible → integer, else inexact float.
Matches spec ("inexact float") + JS host (backward-compatible) +
test-numeric-tower ((/ 6 2)=3, (/ 1 4)=0.25, (/ 5 2)=2.5). Exact
rationals come ONLY from literals / make-rational, so a rational
OPERAND keeps the result exact (cases below) — but two integers do
NOT silently produce a rational (that diverged from the JS host). *)
| [Integer a; Integer b] when b <> 0 && a mod b = 0 -> Integer (a / b)
| [Integer a; Integer b] -> Number (float_of_int a /. float_of_int b)
| [Rational(an,ad); Integer b] -> make_rat an (ad * b)
| [Integer a; Rational(bn,bd)] -> make_rat (a * bd) bn
| [Rational(an,ad); Rational(bn,bd)] -> rat_div (an, ad) (bn, bd)
@@ -397,6 +404,7 @@ let () =
register "exact?" (fun args ->
match args with
| [Integer _] -> Bool true
| [Rational _] -> Bool true (* rationals are exact *)
| [Number _] -> Bool false
| [_] -> Bool false
| _ -> raise (Eval_error "exact?: 1 arg"));
@@ -833,7 +841,7 @@ let () =
match args with [a] -> Bool (is_nil a) | _ -> raise (Eval_error "nil?: 1 arg"));
register "number?" (fun args ->
match args with
| [Integer _] | [Number _] -> Bool true
| [Integer _] | [Number _] | [Rational _] -> Bool true
| [_] -> Bool false
| _ -> raise (Eval_error "number?: 1 arg"));
register "integer?" (fun args ->