ocaml: phase 4 integer division semantics + Int module + max_int/min_int (+5 tests, 525 total)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 27s

Three things in this commit:

1. Integer / is now truncate-toward-zero on ints, IEEE on floats. The
   eval-op handler for '/' checks (number? + (= (round x) x)) on both
   sides; if both integral, applies host floor/ceil based on sign;
   otherwise falls through to host '/'.

2. Fixes Int.rem, which was returning 0 because (a - b * (a / b))
   was using float division: 17 - 5 * 3.4 = 0.0. Now Int.rem 17 5 = 2.

3. Int module fleshed out:
   max_int / min_int / zero / one / minus_one,
   succ / pred / neg, add / sub / mul / div / rem,
   equal, compare.

Also adds globals: max_int, min_int, abs_float, float_of_int,
int_of_float (the latter two are identity in our dynamic runtime).

  17 / 5         = 3
  -17 / 5        = -3   (trunc toward zero)
  Int.rem 17 5   = 2
  Int.compare 5 3 = 1
This commit is contained in:
2026-05-09 02:50:21 +00:00
parent 55fe1e4468
commit a0e8b64f5c
4 changed files with 55 additions and 1 deletions

View File

@@ -1298,6 +1298,18 @@ cat > "$TMPFILE" << 'EPOCHS'
(epoch 5044)
(eval "(ocaml-run \"let a = Array.of_list [1;2;3;4;5] in Array.mem 3 a\")")
;; ── Integer division + Int module + max_int ──────────────────
(epoch 5050)
(eval "(ocaml-run \"17 / 5\")")
(epoch 5051)
(eval "(ocaml-run \"-17 / 5\")")
(epoch 5052)
(eval "(ocaml-run \"Int.rem 17 5\")")
(epoch 5053)
(eval "(ocaml-run \"Int.compare 5 3\")")
(epoch 5054)
(eval "(ocaml-run \"max_int + min_int\")")
EPOCHS
OUTPUT=$(timeout 360 "$SX_SERVER" < "$TMPFILE" 2>/dev/null)
@@ -2062,6 +2074,13 @@ check 5042 "Array.append 6-len sum" '21'
check 5043 "Array.exists = 6" 'true'
check 5044 "Array.mem 3 [1..5]" 'true'
# ── Int module + integer division ───────────────────────────────
check 5050 "17 / 5 = 3 (int div)" '3'
check 5051 "-17 / 5 = -3 (trunc-zero)" '-3'
check 5052 "Int.rem 17 5" '2'
check 5053 "Int.compare 5 3" '1'
check 5054 "max_int + min_int (host int)" '0'
TOTAL=$((PASS + FAIL))
if [ $FAIL -eq 0 ]; then
echo "ok $PASS/$TOTAL OCaml-on-SX tests passed"