lua: math.mod (alias) + math.frexp + math.ldexp
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Has been cancelled
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Has been cancelled
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user