mirror of
https://github.com/open-goal/jak-project.git
synced 2024-10-20 21:27:52 -04:00
460ec874bb
* add support for stack integers * update documentation * revise value type stack variables
48 lines
985 B
Common Lisp
48 lines
985 B
Common Lisp
(start-test "approx-pi")
|
|
|
|
(defun test-approx-pi ((res integer))
|
|
(let ((rad (* res res))
|
|
(count 0))
|
|
(dotimes (x res)
|
|
(dotimes (y res)
|
|
(if (> rad (+ (* x x) (* y y)))
|
|
(+! count 1)
|
|
)
|
|
)
|
|
)
|
|
(* 4.0 (/ (the float count) (the float rad)))
|
|
)
|
|
)
|
|
|
|
(let ((approx-pi (test-approx-pi 1000)))
|
|
(expect-true (> approx-pi 3.14))
|
|
(expect-true (< approx-pi 3.15))
|
|
)
|
|
|
|
|
|
(defun test-approx-pi-float ((res float))
|
|
(let* ((rad (the float (* res res)))
|
|
(count (the float 0))
|
|
(x (the float 0))
|
|
(y (the float 0))
|
|
(scale (/ 1.0 rad)))
|
|
(while (< x res)
|
|
(set! y 0.0)
|
|
(while (< y res)
|
|
(if (> rad (+ (* x x) (* y y)))
|
|
(+! count scale)
|
|
)
|
|
(+! y 1.0)
|
|
)
|
|
(+! x 1.0)
|
|
)
|
|
(* 4.0 count)
|
|
)
|
|
)
|
|
|
|
(let ((approx-pi (test-approx-pi-float 500.0)))
|
|
(expect-true (> approx-pi 3.14))
|
|
(expect-true (< approx-pi 3.15))
|
|
)
|
|
|
|
(finish-test) |