memo->clojure.contrib.math
clojure-contrib-1.1.0のmath一覧のメモ
expt,exact-integer-sqrt,sqrt
(use 'clojure.contrib.math) (expt 2 10) ;=>1024 (expt 3 4) ;=>81 (exact-integer-sqrt 15) ;=> [3 6] ;(+ (* 3 3) 6) ;=>15 (exact-integer-sqrt 1024);=> [32 0] ;(+ (* 32 32) 0) ;=>1024 (sqrt 2) ;=> 1.4142135623730951 (sqrt 3) ;=> 1.7320508075688772 (sqrt 5) ;=> 2.23606797749979
abs
絶対値
(abs -3) ;=>3 (abs :a) ;=> java.lang.IllegalArgumentException: abs requires a number (NO_SOURCE_FILE:0)
floor,ceil,round
(floor 3) ;=>3 (floor 3.1) ;=>3.0 (floor 3.9) ;=>3.0 (floor -1.2) ;=>-2.0 (floor (/ 3 2)) ;=>1 (ceil 3) ;=> 3 (ceil 3.1) ;=> 4.0 (ceil 3.9) ;=> 4.0 (ceil -1.2) ;=> -1.0 (ceil (/ 3 2)) ;=> 2 (round 3) ;=> 3 (round 3.1) ;=> 3 (round 3.9) ;=> 4 (round -1.2) ;=> -1 ;(round -1.5) ;=> -1 ;(round -1.6) ;=> -2 (round (/ 3 2)) ;=> 2
*1:どんな時に便利なんだろう