ocaml: phase 6 Float module fleshed out (+6 tests, 598 total)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 23s

New Float members:
  zero / one / minus_one
  abs / neg
  add / sub / mul / div     (lift host '+.' '-.' '*.' '/.')
  max / min                 (if-based)
  equal / compare           (Float.compare returns -1 / 0 / 1)
  to_int                    (host floor)
  of_int                    (identity in dynamic runtime)
  of_string                 (delegates to _int_of_string)

Aligns Float with Int's API and lets baselines use Float.add /
Float.compare / etc without lifting the symbols themselves.

  Float.add 3.5 4.5         = 8
  Float.compare 2.5 5.0     = -1
  Float.abs -3.7            = 3.7
  Float.max 3.14 2.71       = 3.14
This commit is contained in:
2026-05-09 07:09:29 +00:00
parent 97a8c06690
commit e42ff3b1f6
3 changed files with 45 additions and 0 deletions

View File

@@ -630,6 +630,7 @@
module Float = struct
let to_string f = _string_of_float f
let of_string s = _int_of_string s
let sqrt f = _float_sqrt f
let sin f = _float_sin f
let cos f = _float_cos f
@@ -638,6 +639,22 @@
let ceil f = _float_ceil f
let round f = _float_round f
let pi = 3.141592653589793
let zero = 0.0
let one = 1.0
let minus_one = -1.0
let abs f = if f < 0.0 then 0.0 -. f else f
let neg f = 0.0 -. f
let add a b = a +. b
let sub a b = a -. b
let mul a b = a *. b
let div a b = a /. b
let max a b = if a > b then a else b
let min a b = if a < b then a else b
let equal a b = a = b
let compare a b =
if a < b then -1 else if a > b then 1 else 0
let to_int f = _float_floor f
let of_int n = n
end ;;
module Printf = struct

View File

@@ -1480,6 +1480,20 @@ cat > "$TMPFILE" << 'EPOCHS'
(epoch 5232)
(eval "(ocaml-run \"Result.compare compare compare (Ok 1) (Error \\\"fail\\\")\")")
;; ── Float module additions ───────────────────────────────────
(epoch 5240)
(eval "(ocaml-run \"Float.add 3.5 4.5\")")
(epoch 5241)
(eval "(ocaml-run \"Float.compare 2.5 5.0\")")
(epoch 5242)
(eval "(ocaml-run \"Float.abs (-3.7)\")")
(epoch 5243)
(eval "(ocaml-run \"Float.max 3.14 2.71\")")
(epoch 5244)
(eval "(ocaml-run \"Float.equal 1.5 1.5\")")
(epoch 5245)
(eval "(ocaml-run \"Float.zero +. Float.one\")")
EPOCHS
OUTPUT=$(timeout 360 "$SX_SERVER" < "$TMPFILE" 2>/dev/null)
@@ -2354,6 +2368,14 @@ check 5230 "Result.equal Ok 1 Ok 1" 'true'
check 5231 "Result.compare Ok 5 Ok 3" '1'
check 5232 "Result.compare Ok < Error" '-1'
# ── Float module additions ──────────────────────────────────────
check 5240 "Float.add 3.5 4.5" '8'
check 5241 "Float.compare 2.5 5.0" '-1'
check 5242 "Float.abs -3.7" '3.7'
check 5243 "Float.max 3.14 2.71" '3.14'
check 5244 "Float.equal 1.5 1.5" 'true'
check 5245 "Float.zero +. Float.one" '1'
TOTAL=$((PASS + FAIL))
if [ $FAIL -eq 0 ]; then
echo "ok $PASS/$TOTAL OCaml-on-SX tests passed"

View File

@@ -407,6 +407,12 @@ _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 6 — Float module fleshed out (+6 tests, 598
total). New Float members: zero, one, minus_one, abs, neg, add,
sub, mul, div, max, min, equal, compare, to_int, of_int,
of_string. Most just lift the host operators (`+.` is already
available as a global). Aligns Float with Int module's API and
unblocks idiomatic float arithmetic in baselines.
- 2026-05-09 Phase 5.1 — balance.ml baseline (paren/bracket/brace
balance using Stack). is_balanced walks a string; on opener push,
on closer check stack non-empty + top matches expected opener (else