spec: math completeness — trig, quotient, gcd/lcm, radix number<->string
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Has been cancelled

Phase 15 implementation:
- spec/primitives.sx: stdlib.math module — sin/cos/tan/asin/acos/atan/exp/log/expt/quotient/gcd/lcm/number->string/string->number (13 primitives)
- JS platform: stdlib.math module; strict string->number parsing (rejects partial matches like "fg" in base 16)
- OCaml: expt, quotient, gcd, lcm, number->string (radix), string->number (radix); atan updated to accept optional 2nd arg (atan2 form)
- spec/tests/test-math.sx: 44 tests — trig/inverse trig, expt, quotient semantics, gcd/lcm, radix formatting/parsing, tower integration
- JS: 2311/4801 (+2 net); OCaml: 4547/5629 (+1 net); zero regressions in math area

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-01 16:23:40 +00:00
parent ab3c3693c0
commit be2b11acc2
5 changed files with 387 additions and 2 deletions

View File

@@ -948,4 +948,90 @@
:returns "boolean"
:doc "True if a char is immediately available on the port.")
(define-module :stdlib.math)
(define-primitive
"sin"
:params ((x :as number))
:returns "float"
:doc "Sine of x (radians).")
(define-primitive
"cos"
:params ((x :as number))
:returns "float"
:doc "Cosine of x (radians).")
(define-primitive
"tan"
:params ((x :as number))
:returns "float"
:doc "Tangent of x (radians).")
(define-primitive
"asin"
:params ((x :as number))
:returns "float"
:doc "Arc sine of x; result in radians.")
(define-primitive
"acos"
:params ((x :as number))
:returns "float"
:doc "Arc cosine of x; result in radians.")
(define-primitive
"atan"
:params ((x :as number) &rest (y :as number))
:returns "float"
:doc "Arc tangent. (atan x) → radians in (-π/2, π/2). (atan y x) → atan2(y, x).")
(define-primitive
"exp"
:params ((x :as number))
:returns "float"
:doc "e raised to the power x.")
(define-primitive
"log"
:params ((x :as number))
:returns "float"
:doc "Natural logarithm of x.")
(define-primitive
"expt"
:params ((base :as number) (exp :as number))
:returns "number"
:doc "base raised to the power exp. Alias: pow.")
(define-primitive
"quotient"
:params ((a :as number) (b :as number))
:returns "integer"
:doc "Integer quotient: truncate(a / b) toward zero. Sign follows dividend.")
(define-primitive
"gcd"
:params ((a :as number) (b :as number))
:returns "integer"
:doc "Greatest common divisor of a and b.")
(define-primitive
"lcm"
:params ((a :as number) (b :as number))
:returns "integer"
:doc "Least common multiple of a and b.")
(define-primitive
"number->string"
:params ((n :as number) &rest (radix :as number))
:returns "string"
:doc "Convert number n to string. Optional radix (default 10). E.g. (number->string 255 16) → \"ff\".")
(define-primitive
"string->number"
:params ((s :as string) &rest (radix :as number))
:returns "any"
:doc "Parse string s as a number. Optional radix (default 10). Returns nil on failure.")
(define-module :stdlib.hash-table)