Function: math-nest-calls

math-nest-calls is a byte-compiled function defined in calc-map.el.gz.

Signature

(math-nest-calls FUNC BASE ITERS ACCUM TOL)

Source Code

;; Defined in /usr/src/emacs/lisp/calc/calc-map.el.gz
(defun math-nest-calls (func base iters accum tol)
  (or (symbolp tol)
      (if (math-realp tol)
	  (or (math-numberp base) (math-reject-arg base 'numberp))
	(math-reject-arg tol 'realp)))
  (setq func (math-var-to-calcFunc func))
  (or (null iters)
      (if (equal iters '(var inf var-inf))
	  (setq iters nil)
	(progn
	  (if (math-messy-integerp iters)
	      (setq iters (math-trunc iters)))
	  (or (integerp iters) (math-reject-arg iters 'fixnump))
	  (or (not tol) (natnump iters) (math-reject-arg iters 'fixnatnump))
	  (if (< iters 0)
	      (let* ((dummy '(var DummyArg var-DummyArg))
		     (dummy2 '(var DummyArg2 var-DummyArg2))
		     (finv (math-solve-for (math-build-call func (list dummy2))
					   dummy dummy2 nil)))
		(or finv (math-reject-arg nil "*Unable to find an inverse"))
		(if (and (= (length finv) 2)
			 (equal (nth 1 finv) dummy))
		    (setq func (car finv))
		  (setq func (list 'calcFunc-lambda dummy finv)))
		(setq iters (- iters)))))))
  (math-with-extra-prec 1
    (let ((value base)
	  (ovalue nil)
	  (avalues (list base))
	  (math-working-step 0)
	  (math-working-step-2 iters))
      (while (and (or (null iters)
		      (>= (setq iters (1- iters)) 0))
		  (or (null tol)
		      (null ovalue)
		      (if (eq tol t)
			  (not (if (and (Math-numberp value)
					(Math-numberp ovalue))
				   (math-nearly-equal value ovalue)
				 (Math-equal value ovalue)))
			(if (math-numberp value)
			    (Math-lessp tol (math-abs (math-sub value ovalue)))
			  (math-reject-arg value 'numberp)))))
	(setq ovalue value
	      math-working-step (1+ math-working-step)
	      value (math-normalize (math-build-call func (list value))))
	(if accum
	    (setq avalues (cons value avalues))))
      (if accum
	  (cons 'vec (nreverse avalues))
	value))))