3 ;; JSCL is free software: you can redistribute it and/or
4 ;; modify it under the terms of the GNU General Public License as
5 ;; published by the Free Software Foundation, either version 3 of the
6 ;; License, or (at your option) any later version.
8 ;; JSCL is distributed in the hope that it will be useful, but
9 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
10 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 ;; General Public License for more details.
13 ;; You should have received a copy of the GNU General Public License
14 ;; along with JSCL. If not, see <http://www.gnu.org/licenses/>.
16 ;;;; Various numeric functions and constants
18 ;; TODO: Use MACROLET when it exists
19 (defmacro defcomparison (operator)
20 `(defun ,operator (x &rest args)
24 (return-from ,operator nil)))
32 (defconstant pi 3.141592653589793)
34 (defun evenp (x) (= (mod x 2) 0))
35 (defun oddp (x) (not (evenp x)))
37 (flet ((%max-min (x xs func)
39 (setq x (if (funcall func x (car xs)) x y)))
41 (defun max (x &rest xs) (%max-min x xs #'>))
42 (defun min (x &rest xs) (%max-min x xs #'<)))
44 (defun abs (x) (if (> x 0) x (- x)))
46 (defun expt (base power) (expt base power))
47 (defun exp (power) (expt 2.718281828459045 power))