summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2015-07-31 10:12:37 -0700
committerKyle Meyer <kyle@kyleam.com>2015-08-04 22:58:47 -0400
commitff92583e42db9730c307e001619a828219470908 (patch)
tree83212377e5c393964a537f5eba5bd69c48eadc70
parent74e35a9154233676c8355068bea32d43490ce077 (diff)
downloadorg-mode-ff92583e42db9730c307e001619a828219470908.tar.gz
Backport commit eb0f65b from Emacs master branch
Don't overflow if computing approximate percentage eb0f65b4fbbea60100b53cb40a1d7138d47ad0d2 Paul Eggert Fri Jul 31 10:13:38 2015 -0700 * lisp/org-list.el (org-update-checkbox-count): * lisp/org.el (org-table-map-tables) (org-update-parent-todo-statistics): Prefer (floor (* 100.0 NUMERATOR) DENOMINATOR) when calculating progress-report percentages and the like. This avoids problems if (* 100 NUMERATOR) would overflow. * lisp/org-colview.el (org-nofm-to-completion): Prefer (round (* 100.0 NUMERATOR) DENOMINATOR) to a more-complicated and less-accurate approximation.
-rw-r--r--lisp/org-colview.el2
-rw-r--r--lisp/org-list.el3
-rwxr-xr-xlisp/org.el6
3 files changed, 7 insertions, 4 deletions
diff --git a/lisp/org-colview.el b/lisp/org-colview.el
index b88cb77..251f425 100644
--- a/lisp/org-colview.el
+++ b/lisp/org-colview.el
@@ -1068,7 +1068,7 @@ display, or in the #+COLUMNS line of the current buffer."
(defun org-nofm-to-completion (n m &optional percent)
(if (not percent)
(format "[%d/%d]" n m)
- (format "[%d%%]"(floor (+ 0.5 (* 100. (/ (* 1.0 n) m)))))))
+ (format "[%d%%]" (round (* 100.0 n) m))))
(defun org-columns-string-to-number (s fmt)
diff --git a/lisp/org-list.el b/lisp/org-list.el
index ee9d7c1..b23f49b 100644
--- a/lisp/org-list.el
+++ b/lisp/org-list.el
@@ -2573,7 +2573,8 @@ With optional prefix argument ALL, do this for the whole buffer."
(total (nth 4 cookie)))
(goto-char beg)
(insert
- (if percent (format "[%d%%]" (/ (* 100 checked) (max 1 total)))
+ (if percent (format "[%d%%]" (floor (* 100.0 checked)
+ (max 1 total)))
(format "[%d/%d]" checked total)))
(delete-region (point) (+ (point) (- end beg)))
(when org-auto-align-tags (org-fix-tags-on-the-fly)))))))
diff --git a/lisp/org.el b/lisp/org.el
index a49c1da..b6f1da7 100755
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -4549,7 +4549,8 @@ is nil, return nil unconditionally."
(goto-char (point-min))
(while (re-search-forward org-table-any-line-regexp nil t)
(unless quietly
- (message "Mapping tables: %d%%" (/ (* 100.0 (point)) (buffer-size))))
+ (message "Mapping tables: %d%%"
+ (floor (* 100.0 (point)) (buffer-size))))
(beginning-of-line 1)
(when (and (looking-at org-table-line-regexp)
;; Exclude tables in src/example/verbatim/clocktable blocks
@@ -12966,7 +12967,8 @@ statistics everywhere."
(outline-next-heading)))
(setq new
(if is-percent
- (format "[%d%%]" (/ (* 100 cnt-done) (max 1 cnt-all)))
+ (format "[%d%%]" (floor (* 100.0 cnt-done)
+ (max 1 cnt-all)))
(format "[%d/%d]" cnt-done cnt-all))
ndel (- (match-end 0) checkbox-beg))
;; handle overlays when updating cookie from column view