]> code.delx.au - gnu-emacs/blobdiff - lisp/calc/calc-math.el
Merge from emacs--rel--22
[gnu-emacs] / lisp / calc / calc-math.el
index a4dad15c14e571ffef0c92016d7474e10e3a6630..3a2319e9a2cd8271e173babcf2016c8dd4f98540 100644 (file)
 ;;; is an Emacs float, for acceptable d.dddd....
 
 (defvar math-largest-emacs-expt
-  (let ((x 1))
-    (while (condition-case nil
-               (expt 10.0 x)
-             (error nil))
-      (setq x (* 2 x)))
-    (setq x (/ x 2))
-    (while (condition-case nil
-               (expt 10.0 x)
-             (error nil))
-      (setq x (1+ x)))
-    (- x 2))
+  (let ((x 1)
+        (pow 1e2))
+    ;; The following loop is for efficiency; it should stop when 
+    ;; 10^(2x) is too large.  This could be indicated by a range 
+    ;; error when computing 10^(2x) or an infinite value for 10^(2x).
+    (while (and
+            pow
+            (< pow 1.0e+INF))
+      (setq x (* 2 x))
+      (setq pow (condition-case nil
+                    (expt 10.0 (* 2 x))
+                  (error nil))))
+    ;; The following loop should stop when 10^(x+1) is too large.
+    (setq pow (condition-case nil
+                    (expt 10.0 (1+ x))
+                  (error nil)))
+    (while (and
+            pow
+            (< pow 1.0e+INF))
+      (setq x (1+ x))
+      (setq pow (condition-case nil
+                    (expt 10.0 (1+ x))
+                  (error nil))))
+    (1- x))
   "The largest exponent which Calc will convert to an Emacs float.")
 
 (defvar math-smallest-emacs-expt
   (let ((x -1))
     (while (condition-case nil
-               (expt 10.0 x)
+               (> (expt 10.0 x) 0.0)
              (error nil))
       (setq x (* 2 x)))
     (setq x (/ x 2))
     (while (condition-case nil
-               (expt 10.0 x)
+               (> (expt 10.0 x) 0.0)
              (error nil))
       (setq x (1- x)))
     (+ x 2))
@@ -1794,16 +1807,14 @@ If this can't be done, return NIL."
       (math-lnp1-series nextsum (1+ n) nextx x))))
 
 (defconst math-approx-ln-10
-  (eval-when-compile
-    (math-read-number-simple "2.302585092994045684018"))
+  (math-read-number-simple "2.302585092994045684018")
   "An approximation for ln(10).")
      
 (math-defcache math-ln-10 math-approx-ln-10
   (math-ln-raw-2 '(float 1 1)))
 
 (defconst math-approx-ln-2
-  (eval-when-compile
-    (math-read-number-simple "0.693147180559945309417"))
+  (math-read-number-simple "0.693147180559945309417")
   "An approximation for ln(2).")
 
 (math-defcache math-ln-2 math-approx-ln-2