kozima #6391(2008/05/30 23:50 GMT) [ Common Lisp ] Rating0/0=0.00
剰余を出す関数には mod と rem がありますが、mod は割って負の無限大、rem は 0 方向に丸めた余りを返します。
1 2 3 4 5 6 7 8 9 10 11 12 13
(defun modular (n low high) (+ low (mod n (- high low -1)))) ;;; test (loop for (n low high ans) in '((0 100 200 100) (50 100 200 150) (100 100 200 200) (101 100 200 100) (-1 100 200 200) (1 -5 200 -4) (-500 -5 -1 -5)) do (assert (= (modular n low high) ans)) finally (princ :ok))
Rating0/0=0.00-0+
[ reply ]
kozima
#6391()
[
Common Lisp
]
Rating0/0=0.00
剰余を出す関数には mod と rem がありますが、mod は割って負の無限大、rem は 0 方向に丸めた余りを返します。
(defun modular (n low high) (+ low (mod n (- high low -1)))) ;;; test (loop for (n low high ans) in '((0 100 200 100) (50 100 200 150) (100 100 200 200) (101 100 200 100) (-1 100 200 200) (1 -5 200 -4) (-500 -5 -1 -5)) do (assert (= (modular n low high) ans)) finally (princ :ok))Rating0/0=0.00-0+
[ reply ]