# Diff of /src/code/irrat.lisp

revision 1.56 by rtoy, Wed Oct 8 17:03:07 2008 UTC revision 1.57 by rtoy, Wed Oct 22 14:02:27 2008 UTC
# Line 287  Line 287
287
288  (defparameter *intexp-maximum-exponent* 10000)  (defparameter *intexp-maximum-exponent* 10000)
289
290    (define-condition intexp-limit-error (error)
291      ((base :initarg :base :reader intexp-base)
292       (power :initarg :power :reader intexp-power))
293      (:report (lambda (condition stream)
294                 (format stream "The absolute value of ~S exceeds limit ~S."
295                         (intexp-power condition)
296                         *intexp-maximum-exponent*))))
297
298  ;;; This function precisely calculates base raised to an integral power.  It  ;;; This function precisely calculates base raised to an integral power.  It
299  ;;; separates the cases by the sign of power, for efficiency reasons, as powers  ;;; separates the cases by the sign of power, for efficiency reasons, as powers
300  ;;; can be calculated more efficiently if power is a positive integer.  Values  ;;; can be calculated more efficiently if power is a positive integer.  Values
# Line 300  Line 308
308      (return-from intexp base))      (return-from intexp base))
309
310    (when (> (abs power) *intexp-maximum-exponent*)    (when (> (abs power) *intexp-maximum-exponent*)
311      (cerror "Continue with calculation."      ;; Allow user the option to continue with calculation, possibly
312              "The absolute value of ~S exceeds ~S."      ;; increasing the limit to the given power.
313              power '*intexp-maximum-exponent* base power))      (restart-case
314            (error 'intexp-limit-error
315                   :base base
316                   :power power)
317          (continue ()
318            :report "Continue with calculation")
319          (new-limit ()
320            :report "Continue with calculation, update limit"
321            (setq *intexp-maximum-exponent* power))))
322    (cond ((minusp power)    (cond ((minusp power)
323           (/ (intexp base (- power))))           (/ (intexp base (- power))))
324          ((eql base 2)          ((eql base 2)

Legend:
 Removed from v.1.56 changed lines Added in v.1.57