r5246: *** empty log message ***
[kmrcl.git] / math.lisp
1 ;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
4 ;;;;
5 ;;;; Name:          math.lisp
6 ;;;; Purpose:       General purpose math functions
7 ;;;; Programmer:    Kevin M. Rosenberg
8 ;;;; Date Started:  Nov 2002
9 ;;;;
10 ;;;; $Id: math.lisp,v 1.4 2003/06/06 21:59:29 kevin Exp $
11 ;;;;
12 ;;;; This file, part of KMRCL, is Copyright (c) 2002 by Kevin M. Rosenberg
13 ;;;;
14 ;;;; KMRCL users are granted the rights to distribute and use this software
15 ;;;; as governed by the terms of the Lisp Lesser GNU Public License
16 ;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL.
17 ;;;; *************************************************************************
18
19
20 (in-package #:kmrcl)
21
22 (defun deriv (f dx)
23   #'(lambda (x)
24       (/ (- (funcall f (+ x dx)) (funcall f x))
25          dx)))
26
27 (defun sin^ (x)
28     (funcall (deriv #'sin 1d-8) x))
29
30 ;;; (sin^ pi)
31
32 (defmacro ensure-integer (obj)
33   "Ensure object is an integer. If it is a string, then parse it"
34   `(if (stringp ,obj)
35       (parse-integer ,obj)
36      ,obj))