lua: math.mod (alias) + math.frexp + math.ldexp
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Has been cancelled

This commit is contained in:
2026-04-25 00:39:46 +00:00
parent 1b34d41b33
commit f620be096b
4 changed files with 78 additions and 43 deletions

View File

@@ -1425,6 +1425,35 @@
(dict-set! math "min" lua-math-min)
(dict-set! math "max" lua-math-max)
(dict-set! math "fmod" lua-math-fmod)
(dict-set! math "mod" lua-math-fmod)
(define
lua-math-frexp
(fn (x)
(cond
((= x 0) (list (quote lua-multi) 0 0))
(else
(let ((sign (if (< x 0) -1 1)) (ax (abs x)) (e 0))
(begin
(define
fr-up
(fn ()
(when (>= ax 1)
(begin (set! ax (/ ax 2)) (set! e (+ e 1)) (fr-up)))))
(define
fr-dn
(fn ()
(when (< ax 0.5)
(begin (set! ax (* ax 2)) (set! e (- e 1)) (fr-dn)))))
(fr-up)
(fr-dn)
(list (quote lua-multi) (* sign ax) e)))))))
(define
lua-math-ldexp
(fn (m e) (* m (pow 2 e))))
(dict-set! math "frexp" lua-math-frexp)
(dict-set! math "ldexp" lua-math-ldexp)
(dict-set! math "modf" lua-math-modf)
(dict-set! math "random" lua-math-random)
(dict-set! math "randomseed" lua-math-randomseed)