root/trunk/special-functions/logarithm.lisp

Revision 26, 2.2 kB (checked in by lhealy, 9 months ago)

Subversion version stamp.

  • Property svn:keywords set to Id
Line 
1;; Logarithm
2;; Liam Healy, Sun Apr 30 2006 - 22:08
3;; Time-stamp: <2008-02-16 22:34:59EST logarithm.lisp>
4;; $Id$
5
6(in-package :gsl)
7
8(defgeneric gsl-log (x)
9  (:documentation                       ; FDL
10   "The natural logarithm of x, log(x), for x > 0."))
11
12(defmfun gsl-log ((x float))
13  "gsl_sf_log_e"
14  ((x :double) (ret sf-result))
15  :type :method
16  :export t)
17
18(defmfun gsl-log ((x complex))
19  "gsl_sf_complex_log_e"
20  (((realpart x) :double) ((imagpart x) :double)
21   (re-ret sf-result) (im-ret sf-result))
22  :type :method
23  :return
24  ((complex (val re-ret) (val im-ret)) (complex (err re-ret) (err im-ret)))
25  :documentation                        ; FDL
26  "Results are returned as lnr, theta such that
27  exp(lnr + i \theta) = z_r + i z_i, where theta lies in the range [-\pi,\pi].")
28
29(defmfun log-abs (x)
30  "gsl_sf_log_abs_e" ((x :double) (ret sf-result))
31  :documentation                        ; FDL
32  "The natural logarithm of the magnitude of x, log(|x|), for x ne 0.")
33
34(defmfun log-1+x (x)
35  "gsl_sf_log_1plusx_e" ((x :double) (ret sf-result))
36  :documentation                        ; FDL
37  "log(1 + x) for x > -1 using an algorithm that is accurate for small x.")
38
39(defmfun log-1+x-m1 (x)
40  "gsl_sf_log_1plusx_mx_e" ((x :double) (ret sf-result))
41  :documentation                        ; FDL
42  "log(1 + x) - x for x > -1 using an algorithm that is accurate for small x.")
43
44;;; Examples and unit test
45
46#|
47(make-tests logarithm
48  (gsl-log 2.0d0)
49  (gsl-log #C(1.0d0 1.0d0))
50  (log-abs -2.0d0)
51  (log-1+x 1.d-4)
52  (log-1+x-m1 1.d-4))
53|#
54
55(LISP-UNIT:DEFINE-TEST LOGARITHM
56  (LISP-UNIT::ASSERT-NUMERICAL-EQUAL
57   (LIST 0.6931471805599453d0 3.078191837246648d-16)
58   (MULTIPLE-VALUE-LIST (GSL-LOG 2.0d0)))
59  (LISP-UNIT::ASSERT-NUMERICAL-EQUAL
60   (LIST #C(0.34657359027997264d0 0.7853981633974483d0)
61         #C(1.539095918623324d-16 7.69547959311662d-17))
62   (MULTIPLE-VALUE-LIST (GSL-LOG #C(1.0d0 1.0d0))))
63  (LISP-UNIT::ASSERT-NUMERICAL-EQUAL
64   (LIST 0.6931471805599453d0 3.078191837246648d-16)
65   (MULTIPLE-VALUE-LIST (LOG-ABS -2.0d0)))
66  (LISP-UNIT::ASSERT-NUMERICAL-EQUAL
67   (LIST 9.999500033330834d-5 2.2203350343487824d-20)
68   (MULTIPLE-VALUE-LIST (LOG-1+X 1.d-4)))
69  (LISP-UNIT::ASSERT-NUMERICAL-EQUAL
70   (LIST -4.999666691664667d-9 1.1101490153075193d-24)
71   (MULTIPLE-VALUE-LIST (LOG-1+X-M1 1.d-4))))
Note: See TracBrowser for help on using the browser.