haskell: Phase 10 — Floating stub: pi, exp, log, sin, cos, ** (+6 tests, 37/37)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Has been cancelled

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-07 08:28:11 +00:00
parent e27daee4a8
commit 882815e612
3 changed files with 25 additions and 1 deletions

View File

@@ -440,6 +440,7 @@
((= op "div") (floor (/ lv rv)))
((= op "rem") (mod lv rv))
((= op "quot") (truncate (/ lv rv)))
((= op "**") (pow lv rv))
((= op ">>=")
(if
(and (list? lv) (= (first lv) "IO"))
@@ -814,6 +815,11 @@
env
"fromRational"
(hk-mk-builtin "fromRational" (fn (x) x) 1))
(dict-set! env "pi" 3.14159)
(dict-set! env "exp" (hk-mk-builtin "exp" (fn (x) (exp x)) 1))
(dict-set! env "log" (hk-mk-builtin "log" (fn (x) (log x)) 1))
(dict-set! env "sin" (hk-mk-builtin "sin" (fn (x) (sin x)) 1))
(dict-set! env "cos" (hk-mk-builtin "cos" (fn (x) (cos x)) 1))
(let
((--sx-to-hk-- (fn (lst) (if (empty? lst) (list "[]") (list ":" (first lst) (--sx-to-hk-- (rest lst))))))
(--words--

View File

@@ -165,4 +165,16 @@
(hk-deep-force (hk-run "main = fromRational 0.5"))
0.5)
(hk-test "pi ≈ 3.14159" (hk-deep-force (hk-run "main = pi")) 3.14159)
(hk-test "exp 0 = 1" (hk-deep-force (hk-run "main = exp 0")) 1)
(hk-test "sin 0 = 0" (hk-deep-force (hk-run "main = sin 0")) 0)
(hk-test "cos 0 = 1" (hk-deep-force (hk-run "main = cos 0")) 1)
(hk-test "2 ** 10 = 1024" (hk-deep-force (hk-run "main = 2 ** 10")) 1024)
(hk-test "log (exp 5) ≈ 5" (hk-deep-force (hk-run "main = log (exp 5)")) 5)
{:fails hk-test-fails :pass hk-test-pass :fail hk-test-fail}

View File

@@ -165,7 +165,7 @@ No OCaml changes are needed. The view type is fully representable as an SX dict.
- [x] `Fractional` typeclass stub: `(/)`, `recip`, `fromRational`. _(/)
already a binop; `recip x = 1 / x` and `fromRational x = x` registered as
builtins in the post-prelude block._
- [ ] `Floating` typeclass stub: `pi`, `exp`, `log`, `sin`, `cos`, `(**)`
- [x] `Floating` typeclass stub: `pi`, `exp`, `log`, `sin`, `cos`, `(**)`
(power operator, maps to SX exponentiation).
- [ ] Tests in `lib/haskell/tests/numeric.sx` (≥ 15 tests: fromIntegral
identity, sqrt/floor/ceiling/round on known values, Float literal show,
@@ -303,6 +303,12 @@ No OCaml changes are needed. The view type is fully representable as an SX dict.
_Newest first._
**2026-05-07** — Phase 10 Floating stub (pi, exp, log, sin, cos, **):
- pi as a number constant; exp/log/sin/cos as builtins thunking through to SX
primitives. `(**)` added as a binop case in `hk-binop` mapping to SX `pow`.
6 new tests in `numerics.sx` (now 37/37). `2 ** 10 = 1024`, `log (exp 5) = 5`,
`sin 0 = 0`, `cos 0 = 1`, `pi ≈ 3.14159`, `exp 0 = 1`.
**2026-05-07** — Phase 10 Fractional stub (recip, fromRational):
- `(/)` already a binop. Added `recip` and `fromRational` as builtins
post-prelude. 3 new tests in `numerics.sx` (now 31/31).