Procházet zdrojové kódy

org-plot.el: avoid arithmetic overflow error

* lisp/org-plot.el (org--plot/values-stats): A set of numbers with the
same value (i.e. 0 range) should not produce an arithmetic overflow
error.

This error was caused by taking the log of 0 (when the range is
0).  This is mitigated by explicit checking against this case.
TEC před 4 roky
rodič
revize
c2fdf424a6
1 změnil soubory, kde provedl 6 přidání a 3 odebrání
  1. 6 3
      lisp/org-plot.el

+ 6 - 3
lisp/org-plot.el

@@ -193,10 +193,13 @@ values, namely regarding the range."
   (let* ((minimum (or hard-min (apply #'min nums)))
 	 (maximum (or hard-max (apply #'max nums)))
 	 (range (- maximum minimum))
-	 (rangeOrder (ceiling (- 1 (log10 range))))
+	 (rangeOrder (if (= range 0) 0
+			 (ceiling (- 1 (log10 range)))))
 	 (range-factor (expt 10 rangeOrder))
-	 (nice-min (/ (float (floor (* minimum range-factor))) range-factor))
-	 (nice-max (/ (float (ceiling (* maximum range-factor))) range-factor)))
+	 (nice-min (if (= range 0) (car nums)
+		     (/ (float (floor (* minimum range-factor))) range-factor)))
+	 (nice-max (if (= range 0) (car nums)
+		     (/ (float (ceiling (* maximum range-factor))) range-factor))))
     `(:min ,minimum :max ,maximum :range ,range
       :range-factor ,range-factor
       :nice-min ,nice-min :nice-max ,nice-max :nice-range ,(- nice-max nice-min))))