ocaml: phase 5.1 pi_leibniz.ml baseline + int_of_float fix (1000 terms x 100 = 314)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 24s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 24s
pi_leibniz.ml: Leibniz formula for pi.
pi/4 = 1 - 1/3 + 1/5 - 1/7 + ...
pi ~= 4 * sum_{k=0}^{n-1} (-1)^k / (2k+1)
For n=1000, pi ~= 3.140593. Multiply by 100 and int_of_float -> 314.
Side-quest: int_of_float was wrongly defined as identity in
iteration 94. Fixed to:
let int_of_float f =
if f < 0.0 then _float_ceil f else _float_floor f
(truncate toward zero, mirroring real OCaml's int_of_float). The
identity definition was a stub from when integer/float dispatch was
not yet split — now they're separate, the stub is wrong.
Float.to_int still uses floor since OCaml's docs say the result is
unspecified for nan / out-of-range; close enough for our scope.
32 baseline programs total.
This commit is contained in:
@@ -407,6 +407,14 @@ _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 5.1 — pi_leibniz.ml baseline (Leibniz formula,
|
||||
1000 terms × 100 → 314). Side-quest: `int_of_float` was wrong —
|
||||
defined as identity in iteration 94 instead of truncation. Fixed
|
||||
to `if f < 0.0 then ceil else floor` (truncate toward zero, real
|
||||
OCaml semantics). Float.to_int still uses floor since OCaml's
|
||||
documentation says "result is unspecified if the argument is nan
|
||||
or falls outside the int range" — close enough for our scope. 32
|
||||
baseline programs total.
|
||||
- 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,
|
||||
|
||||
Reference in New Issue
Block a user