exp-aux.lsp 530 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Mon Sep  1 21:30:38 2003
;;;; Contains: Aux. functions for testing EXP, EXPT

(in-package :cl-test)

(defun my-exp (x n)
  "Compute e^x in the appropriate float result type, summing
   the first n terms of the Taylor series."
  (assert (realp x))
  (let ((result 1)
sds's avatar
sds committed
13
        (xrat (rational x)))
14 15 16 17 18 19 20 21
    (loop
     for i from (1- n) downto 1
     do (setq result (+ 1 (/ (* xrat result) i))))
    (if (floatp x)
      (float result x)
      (float result 1.0f0))))


sds's avatar
sds committed
22

23 24