1
0
mirror of https://git.savannah.gnu.org/git/emacs/org-mode.git synced 2025-02-06 21:29:25 +00:00

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.
This commit is contained in:
Paul Eggert 2015-07-31 10:12:37 -07:00 committed by Kyle Meyer
parent 74e35a9154
commit ff92583e42
3 changed files with 7 additions and 4 deletions

View File

@ -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)

View File

@ -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)))))))

View File

@ -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