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

@@ -407,6 +407,13 @@ _Newest first._
binary search tree (`type 'a tree = Leaf | Node of 'a * 'a tree *
'a tree`) with insert + in-order traversal. Tests parametric ADT,
recursive match, List.append, List.fold_left.
- 2026-05-09 Phase 4 — integer `/` is now truncate-toward-zero on
ints, IEEE on floats. Both operands integral → host floor/ceil based
on sign; otherwise host `/`. Fixes `Int.rem` (which was returning 0
for `Int.rem 17 5` because `a / b` was producing a float). Also adds
Int.{max_int,min_int,zero,one,minus_one,succ,pred,neg,add,sub,mul,
div,rem,equal,compare} and global max_int/min_int/abs_float/
float_of_int/int_of_float (+5 tests, 525 total).
- 2026-05-09 Phase 6 — Array.sort/stable_sort/fast_sort + sub +
append + exists + for_all + mem (+5 tests, 520 total). All
delegate to the corresponding List operation on the cell's