From: Paul Eggert Date: Fri, 31 Jul 2015 17:12:37 +0000 (-0700) Subject: Don't overflow if computing approximate percentage X-Git-Tag: emacs-25.0.90~1402 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=eb0f65b4fbbea60100b53cb40a1d7138d47ad0d2;p=emacs.git Don't overflow if computing approximate percentage * lisp/align.el (align-region): * lisp/cedet/semantic.el (semantic-repeat-parse-whole-stream): * lisp/cedet/semantic/wisent.el (wisent-parse-region): * lisp/cus-edit.el (custom-buffer-create-internal): * lisp/emacs-lisp/checkdoc.el (checkdoc-interactive-ispell-loop) (checkdoc-message-interactive-ispell-loop, checkdoc-next-error) (checkdoc-next-message-error): * lisp/emacs-lisp/eieio-opt.el (eieio-display-method-list): * lisp/epa.el (epa-progress-callback-function): * lisp/erc/erc-dcc.el (erc-dcc-do-LIST-command): * lisp/ffap.el (ffap-menu-rescan): * lisp/gnus/nnbabyl.el (nnbabyl-retrieve-headers): * lisp/gnus/nndiary.el (nndiary-retrieve-headers): * lisp/gnus/nneething.el (nneething-retrieve-headers): * lisp/gnus/nnmbox.el (nnmbox-retrieve-headers): * lisp/gnus/nnmh.el (nnmh-retrieve-headers): * lisp/gnus/nnml.el (nnml-retrieve-headers): * lisp/gnus/nnspool.el (nnspool-retrieve-headers): * lisp/gnus/nntp.el (nntp-retrieve-headers) (nntp-retrieve-articles): * lisp/imenu.el (imenu--relative-position): * lisp/international/ja-dic-cnv.el (skkdic-collect-okuri-nasi) (skkdic-convert-okuri-nasi): * lisp/net/ange-ftp.el (ange-ftp-process-handle-hash): * lisp/nxml/rng-valid.el (rng-compute-mode-line-string): * lisp/org/org-list.el (org-update-checkbox-count): * lisp/org/org.el (org-table-map-tables) (org-update-parent-todo-statistics): * lisp/play/decipher.el (decipher-insert-frequency-counts) (decipher-analyze-buffer): * lisp/profiler.el (profiler-format-percent): * lisp/progmodes/cc-cmds.el (c-progress-update): * lisp/progmodes/cpp.el (cpp-highlight-buffer): * lisp/progmodes/idlwave.el (idlwave-convert-xml-system-routine-info) (idlwave-list-load-path-shadows): * lisp/progmodes/opascal.el (opascal-step-progress): * lisp/progmodes/vhdl-mode.el (vhdl-update-progress-info) (vhdl-scan-directory-contents): * lisp/textmodes/bibtex.el (bibtex-progress-message): * lisp/textmodes/flyspell.el (flyspell-small-region) (flyspell-external-point-words): * lisp/textmodes/table.el (table-recognize): Prefer (floor (* 100.0 NUMERATOR) DENOMINATOR) when calculating progress-report percentages and the like. This avoids problems if (* 100 NUMERATOR) would overflow. * lisp/gnus/gnus-registry.el (gnus-registry-import-eld): * lisp/gnus/registry.el (registry-reindex): Use (* 100.0 ...) rather than (* 100 ...) to avoid int overflow issues. * lisp/descr-text.el (describe-char): * lisp/org/org-colview.el (org-nofm-to-completion): * lisp/ps-print.el (ps-plot): * lisp/simple.el (what-cursor-position): Prefer (round (* 100.0 NUMERATOR) DENOMINATOR) to a more-complicated and less-accurate approximation. --- diff --git a/lisp/align.el b/lisp/align.el index 82a55b0feac..ad5be2ae74d 100644 --- a/lisp/align.el +++ b/lisp/align.el @@ -1437,12 +1437,12 @@ aligner would have dealt with are." (message "Aligning `%s' (rule %d of %d) %d%%..." (symbol-name symbol) rule-index rule-count - (/ (* (- (point) real-beg) 100) - (- end-mark real-beg))) + (floor (* (- (point) real-beg) 100.0) + (- end-mark real-beg))) (message "Aligning %d%%..." - (/ (* (- (point) real-beg) 100) - (- end-mark real-beg)))))) + (floor (* (- (point) real-beg) 100.0) + (- end-mark real-beg)))))) ;; if the search ended us on the beginning of ;; the next line, move back to the end of the diff --git a/lisp/cedet/semantic.el b/lisp/cedet/semantic.el index 81a97884554..290cd907beb 100644 --- a/lisp/cedet/semantic.el +++ b/lisp/cedet/semantic.el @@ -769,8 +769,8 @@ This function returns semantic tags without overlays." (eq semantic-working-type 'percent) (progress-reporter-update semantic--progress-reporter - (/ (* 100 (semantic-lex-token-start (car stream))) - (point-max)))))) + (floor (* 100.0 (semantic-lex-token-start (car stream))) + (point-max)))))) result)) ;;; Parsing Warnings: diff --git a/lisp/cedet/semantic/wisent.el b/lisp/cedet/semantic/wisent.el index dfa533c7b26..761bc6812da 100644 --- a/lisp/cedet/semantic/wisent.el +++ b/lisp/cedet/semantic/wisent.el @@ -322,9 +322,9 @@ the standard function `semantic-parse-region'." semantic--progress-reporter (progress-reporter-update semantic--progress-reporter - (/ (* 100 (semantic-lex-token-start - (car wisent-lex-istream))) - (point-max)))))) + (floor (* 100.0 (semantic-lex-token-start + (car wisent-lex-istream))) + (point-max)))))) ;; Return parse tree (nreverse ptree))) diff --git a/lisp/cus-edit.el b/lisp/cus-edit.el index 1d9a9d6d426..a8d1c97e37a 100644 --- a/lisp/cus-edit.el +++ b/lisp/cus-edit.el @@ -1709,7 +1709,7 @@ Operate on all settings in this buffer:\n")) (mapcar (lambda (entry) (prog2 (message "Creating customization items ...%2d%%" - (/ (* 100.0 count) length)) + (floor (* 100.0 count) length)) (widget-create (nth 1 entry) :tag (custom-unlispify-tag-name (nth 0 entry)) diff --git a/lisp/descr-text.el b/lisp/descr-text.el index a0b9ddfe2c9..71233d406e1 100644 --- a/lisp/descr-text.el +++ b/lisp/descr-text.el @@ -542,9 +542,7 @@ relevant to POS." ,(let* ((beg (point-min)) (end (point-max)) (total (buffer-size)) - (percent (if (> total 50000) ; Avoid overflow multiplying by 100 - (/ (+ (/ total 200) (1- pos)) (max (/ total 100) 1)) - (/ (+ (/ total 2) (* 100 (1- pos))) (max total 1)))) + (percent (round (* 100.0 (1- pos)) (max total 1))) (hscroll (if (= (window-hscroll) 0) "" (format ", Hscroll: %d" (window-hscroll)))) diff --git a/lisp/emacs-lisp/checkdoc.el b/lisp/emacs-lisp/checkdoc.el index 0b451ef6b2a..c22aff4cbca 100644 --- a/lisp/emacs-lisp/checkdoc.el +++ b/lisp/emacs-lisp/checkdoc.el @@ -747,7 +747,7 @@ buffer, otherwise searching starts at START-HERE." ;; Loop over docstrings. (while (checkdoc-next-docstring) (message "Searching for doc string spell error...%d%%" - (/ (* 100 (point)) (point-max))) + (floor (* 100.0 (point)) (point-max))) (if (looking-at "\"") (checkdoc-ispell-docstring-engine (save-excursion (forward-sexp 1) (point-marker))))) @@ -767,7 +767,7 @@ buffer, otherwise searching starts at START-HERE." ;; Loop over message strings. (while (checkdoc-message-text-next-string (point-max)) (message "Searching for message string spell error...%d%%" - (/ (* 100 (point)) (point-max))) + (floor (* 100.0 (point)) (point-max))) (if (looking-at "\"") (checkdoc-ispell-docstring-engine (save-excursion (forward-sexp 1) (point-marker))))) @@ -791,7 +791,7 @@ perform the fix." (condition-case nil (while (and (not msg) (checkdoc-next-docstring)) (message "Searching for doc string error...%d%%" - (/ (* 100 (point)) (point-max))) + (floor (* 100.0 (point)) (point-max))) (if (setq msg (checkdoc-this-string-valid)) (setq msg (cons msg (point))))) ;; Quit.. restore position, Other errors, leave alone @@ -813,7 +813,7 @@ assumes that the cursor is already positioned to perform the fix." (setq type (checkdoc-message-text-next-string (point-max)))) (message "Searching for message string error...%d%%" - (/ (* 100 (point)) (point-max))) + (floor (* 100.0 (point)) (point-max))) (if (setq msg (checkdoc-message-text-engine type)) (setq msg (cons msg (point))))) ;; Quit.. restore position, Other errors, leave alone diff --git a/lisp/emacs-lisp/eieio-opt.el b/lisp/emacs-lisp/eieio-opt.el index 9ecc59434e1..0b003360ed5 100644 --- a/lisp/emacs-lisp/eieio-opt.el +++ b/lisp/emacs-lisp/eieio-opt.el @@ -243,13 +243,13 @@ are not abstract." (princ "Methods Primary Only: ") (prin1 primaryonly) (princ "\t") - (princ (format "%d" (* (/ (float primaryonly) (float methidx)) 100))) + (princ (format "%d" (floor (* 100.0 primaryonly) methidx))) (princ "% of total methods") (terpri) (princ "Only One Primary Impl: ") (prin1 oneprimary) (princ "\t") - (princ (format "%d" (* (/ (float oneprimary) (float primaryonly)) 100))) + (princ (format "%d" (floor (* 100.0 oneprimary) primaryonly))) (princ "% of total primary methods") (terpri) )) diff --git a/lisp/epa.el b/lisp/epa.el index d3fec73ecf4..f6d60459777 100644 --- a/lisp/epa.el +++ b/lisp/epa.el @@ -658,7 +658,7 @@ If SECRET is non-nil, list secret keys instead of public keys." (if (= current total) (message "%s...done" prompt) (message "%s...%d%%" prompt - (floor (* (/ current (float total)) 100)))) + (floor (* 100.0 current) total))) (message "%s..." prompt)))) (defun epa-read-file-name (input) diff --git a/lisp/erc/erc-dcc.el b/lisp/erc/erc-dcc.el index 182f1e05921..d4d005d8345 100644 --- a/lisp/erc/erc-dcc.el +++ b/lisp/erc/erc-dcc.el @@ -594,14 +594,9 @@ It lists the current state of `erc-dcc-list' in an easy to read manner." (get-buffer (plist-get elt :file)) (+ (buffer-size) 0.0 erc-dcc-byte-count)))) - (concat " (" - (if (= byte-count 0) - "0" - (number-to-string - (truncate - (* 100 - (/ byte-count (plist-get elt :size)))))) - "%)")))) + (format " (%d%%)" + (floor (* 100.0 byte-count) + (plist-get elt :size)))))) ?f (or (and (plist-member elt :file) (plist-get elt :file)) ""))) (erc-display-message nil 'notice 'active diff --git a/lisp/ffap.el b/lisp/ffap.el index 81cba07d4c3..c0ab1af80f5 100644 --- a/lisp/ffap.el +++ b/lisp/ffap.el @@ -1568,7 +1568,7 @@ Applies `ffap-menu-text-plist' text properties at all matches." (add-text-properties (car ffap-string-at-point-region) (point) ffap-menu-text-plist) (message "Scanning...%2d%% <%s>" - (/ (* 100 (- (point) (point-min))) range) item))) + (floor (* 100.0 (- (point) (point-min))) range) item))) (or mod (restore-buffer-modified-p nil)))) (message "Scanning...done") ;; Remove duplicates. diff --git a/lisp/gnus/gnus-registry.el b/lisp/gnus/gnus-registry.el index 0cb596012c7..50443973a8d 100644 --- a/lisp/gnus/gnus-registry.el +++ b/lisp/gnus/gnus-registry.el @@ -1100,7 +1100,7 @@ only the last one's marks are returned." (when (and (< 0 expected) (= 0 (mod count 100))) (message "importing: %d of %d (%.2f%%)" - count expected (/ (* 100 count) expected))) + count expected (/ (* 100.0 count) expected))) (setq entry (car-safe old) old (cdr-safe old)) (let* ((id (car-safe entry)) diff --git a/lisp/gnus/nnbabyl.el b/lisp/gnus/nnbabyl.el index d060c2a80dd..ae417a0ffe8 100644 --- a/lisp/gnus/nnbabyl.el +++ b/lisp/gnus/nnbabyl.el @@ -105,7 +105,7 @@ (> number nnmail-large-newsgroup) (zerop (% (incf count) 20)) (nnheader-message 5 "nnbabyl: Receiving headers... %d%%" - (/ (* count 100) number)))) + (floor (* count 100.0) number)))) (and (numberp nnmail-large-newsgroup) (> number nnmail-large-newsgroup) diff --git a/lisp/gnus/nndiary.el b/lisp/gnus/nndiary.el index 027d8888705..31344382029 100644 --- a/lisp/gnus/nndiary.el +++ b/lisp/gnus/nndiary.el @@ -423,7 +423,7 @@ all. This may very well take some time.") (> number nnmail-large-newsgroup) (zerop (% count 20)) (nnheader-message 6 "nndiary: Receiving headers... %d%%" - (/ (* count 100) number)))) + (floor (* count 100.0) number)))) (and (numberp nnmail-large-newsgroup) (> number nnmail-large-newsgroup) diff --git a/lisp/gnus/nneething.el b/lisp/gnus/nneething.el index 183e3967632..0d9044fb712 100644 --- a/lisp/gnus/nneething.el +++ b/lisp/gnus/nneething.el @@ -106,7 +106,7 @@ included.") (and large (zerop (% count 20)) (nnheader-message 5 "nneething: Receiving headers... %d%%" - (/ (* count 100) number)))) + (floor (* count 100.0) number)))) (when large (nnheader-message 5 "nneething: Receiving headers...done")) diff --git a/lisp/gnus/nnmbox.el b/lisp/gnus/nnmbox.el index 78983a5cfef..a70a0395f37 100644 --- a/lisp/gnus/nnmbox.el +++ b/lisp/gnus/nnmbox.el @@ -106,7 +106,7 @@ (> number nnmail-large-newsgroup) (zerop (% count 20)) (nnheader-message 5 "nnmbox: Receiving headers... %d%%" - (/ (* count 100) number)))) + (floor (* count 100.0) number)))) (and (numberp nnmail-large-newsgroup) (> number nnmail-large-newsgroup) diff --git a/lisp/gnus/nnmh.el b/lisp/gnus/nnmh.el index 04270a554cf..cdbf38ae62d 100644 --- a/lisp/gnus/nnmh.el +++ b/lisp/gnus/nnmh.el @@ -109,7 +109,7 @@ as unread by Gnus.") (and large (zerop (% count 20)) (nnheader-message 5 "nnmh: Receiving headers... %d%%" - (/ (* count 100) number)))) + (floor (* count 100.0) number)))) (when large (nnheader-message 5 "nnmh: Receiving headers...done")) diff --git a/lisp/gnus/nnml.el b/lisp/gnus/nnml.el index 8275e19f3b6..c825e097481 100644 --- a/lisp/gnus/nnml.el +++ b/lisp/gnus/nnml.el @@ -178,7 +178,7 @@ non-nil.") (> number nnmail-large-newsgroup) (zerop (% count 20)) (nnheader-message 6 "nnml: Receiving headers... %d%%" - (/ (* count 100) number)))) + (floor (* count 100.0) number)))) (and (numberp nnmail-large-newsgroup) (> number nnmail-large-newsgroup) diff --git a/lisp/gnus/nnspool.el b/lisp/gnus/nnspool.el index 9e9537af1f9..f10b1ad6c54 100644 --- a/lisp/gnus/nnspool.el +++ b/lisp/gnus/nnspool.el @@ -174,7 +174,7 @@ there.") (and do-message (zerop (% (incf count) 20)) (nnheader-message 5 "nnspool: Receiving headers... %d%%" - (/ (* count 100) number)))) + (floor (* count 100.0) number)))) (when do-message (nnheader-message 5 "nnspool: Receiving headers...done")) diff --git a/lisp/gnus/nntp.el b/lisp/gnus/nntp.el index 0891dba0387..b617a1beeb2 100644 --- a/lisp/gnus/nntp.el +++ b/lisp/gnus/nntp.el @@ -728,7 +728,7 @@ command whose response triggered the error." (> number nntp-large-newsgroup) (zerop (% received 20)) (nnheader-message 6 "NNTP: Receiving headers... %d%%" - (/ (* received 100) number))) + (floor (* received 100.0) number))) (nntp-accept-response)))) (and (numberp nntp-large-newsgroup) (> number nntp-large-newsgroup) @@ -965,7 +965,7 @@ command whose response triggered the error." (> number nntp-large-newsgroup) (zerop (% received 20)) (nnheader-message 6 "NNTP: Receiving articles... %d%%" - (/ (* received 100) number))) + (floor (* received 100.0) number))) (nntp-accept-response)))) (and (numberp nntp-large-newsgroup) (> number nntp-large-newsgroup) diff --git a/lisp/gnus/registry.el b/lisp/gnus/registry.el index 96a89fca1b7..7bada9f3095 100644 --- a/lisp/gnus/registry.el +++ b/lisp/gnus/registry.el @@ -320,7 +320,7 @@ Errors out if the key exists already." (when (and (< 0 expected) (= 0 (mod count 1000))) (message "reindexing: %d of %d (%.2f%%)" - count expected (/ (* 100 count) expected))) + count expected (/ (* 100.0 count) expected))) (dolist (val (cdr-safe (assq tr v))) (let* ((value-keys (registry-lookup-secondary-value db tr val))) (push key value-keys) diff --git a/lisp/imenu.el b/lisp/imenu.el index 65c52828c47..3a856b88397 100644 --- a/lisp/imenu.el +++ b/lisp/imenu.el @@ -499,10 +499,7 @@ If REVERSE is non-nil then the beginning is 100 and the end is 0." (let ((pos (point)) (total (buffer-size))) (and reverse (setq pos (- total pos))) - (if (> total 50000) - ;; Avoid overflow from multiplying by 100! - (/ (1- pos) (max (/ total 100) 1)) - (/ (* 100 (1- pos)) (max total 1))))) + (floor (* 100.0 (1- pos)) (max total 1)))) (defun imenu--split (list n) "Split LIST into sublists of max length N. diff --git a/lisp/international/ja-dic-cnv.el b/lisp/international/ja-dic-cnv.el index edb6d8900e6..d9c77bf5652 100644 --- a/lisp/international/ja-dic-cnv.el +++ b/lisp/international/ja-dic-cnv.el @@ -280,7 +280,7 @@ (cons (cons kana candidates) skkdic-okuri-nasi-entries) skkdic-okuri-nasi-entries-count (1+ skkdic-okuri-nasi-entries-count)) - (setq ratio (floor (/ (* (point) 100.0) (point-max)))) + (setq ratio (floor (* (point) 100.0) (point-max))) (if (/= (/ prev-ratio 10) (/ ratio 10)) (progn (message "collected %2d%% ..." ratio) @@ -306,7 +306,7 @@ (while l (let ((kana (car (car l))) (candidates (cdr (car l)))) - (setq ratio (/ (* count 100) skkdic-okuri-nasi-entries-count) + (setq ratio (floor (* count 100.0) skkdic-okuri-nasi-entries-count) count (1+ count)) (if (/= (/ prev-ratio 10) (/ ratio 10)) (progn diff --git a/lisp/net/ange-ftp.el b/lisp/net/ange-ftp.el index 1f893a72f8e..0685bac26c7 100644 --- a/lisp/net/ange-ftp.el +++ b/lisp/net/ange-ftp.el @@ -1613,7 +1613,7 @@ good, skip, fatal, or unknown." -6))) (if (zerop ange-ftp-xfer-size) (ange-ftp-message "%s...%dk" ange-ftp-process-msg kbytes) - (let ((percent (/ (* 100 kbytes) ange-ftp-xfer-size))) + (let ((percent (floor (* 100.0 kbytes) ange-ftp-xfer-size))) ;; cut out the redisplay of identical %-age messages. (unless (eq percent ange-ftp-last-percent) (setq ange-ftp-last-percent percent) diff --git a/lisp/nxml/rng-valid.el b/lisp/nxml/rng-valid.el index 2bf8f1dfa63..61a96545a82 100644 --- a/lisp/nxml/rng-valid.el +++ b/lisp/nxml/rng-valid.el @@ -345,17 +345,11 @@ The schema is set like `rng-auto-set-schema'." (defun rng-compute-mode-line-string () (cond (rng-validate-timer - (concat " Validated:" - (number-to-string - ;; Use floor rather than round because we want - ;; to show 99% rather than 100% for changes near - ;; the end. - (floor (if (eq (buffer-size) 0) - 0.0 - (/ (* (- rng-validate-up-to-date-end (point-min)) - 100.0) - (- (point-max) (point-min)))))) - "%%")) + (format " Validated:%d%%" + (if (= 0 (buffer-size)) + 0 + (floor (- rng-validate-up-to-date-end (point-min)) + (- (point-max) (point-min)))))) ((> rng-error-count 0) (concat " " (propertize "Invalid" diff --git a/lisp/org/org-colview.el b/lisp/org/org-colview.el index e14849f68e4..e938ab4ae4b 100644 --- a/lisp/org/org-colview.el +++ b/lisp/org/org-colview.el @@ -1086,7 +1086,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/org-list.el b/lisp/org/org-list.el index 73f24ce7bd8..432e4310fae 100644 --- a/lisp/org/org-list.el +++ b/lisp/org/org-list.el @@ -2555,8 +2555,8 @@ With optional prefix argument ALL, do this for the whole buffer." (checked (car (nth 3 cookie))) (total (cdr (nth 3 cookie))) (new (if percentp - (format "[%d%%]" (/ (* 100 checked) - (max 1 total))) + (format "[%d%%]" (floor (* 100.0 checked) + (max 1 total))) (format "[%d/%d]" checked total)))) (goto-char beg) (insert new) diff --git a/lisp/org/org.el b/lisp/org/org.el index e9dae191b99..b545f9ee1cb 100644 --- a/lisp/org/org.el +++ b/lisp/org/org.el @@ -4346,7 +4346,8 @@ If TABLE-TYPE is non-nil, also check for table.el-type tables." (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 @@ -12679,7 +12680,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 diff --git a/lisp/play/decipher.el b/lisp/play/decipher.el index f42ae90f3c8..c2268a9b057 100644 --- a/lisp/play/decipher.el +++ b/lisp/play/decipher.el @@ -793,7 +793,7 @@ TOTAL is the total number of letters in the ciphertext." (insert (caar temp-list) (format "%4d%3d%% " (cl-cadar temp-list) - (/ (* 100 (cl-cadar temp-list)) total))) + (floor (* 100.0 (cl-cadar temp-list)) total))) (setq temp-list (nthcdr 4 temp-list))) (insert ?\n) (setq freq-list (cdr freq-list) @@ -957,7 +957,7 @@ Creates the statistics buffer if it doesn't exist." ": A B C D E F G H I J K L M N O P Q R S T U V W X Y Z *" (format "%4d %4d %3d%%\n " (cl-third entry) (cl-second entry) - (/ (* 100 (cl-second entry)) total-chars)) + (floor (* 100.0 (cl-second entry)) total-chars)) (decipher--digram-counts (aref decipher--after i)) ?\n)))) (setq buffer-read-only t) (set-buffer-modified-p nil) diff --git a/lisp/profiler.el b/lisp/profiler.el index 2425d8c56a7..f28bbfe2768 100644 --- a/lisp/profiler.el +++ b/lisp/profiler.el @@ -56,7 +56,7 @@ (format "%s" object)))) (defun profiler-format-percent (number divisor) - (concat (number-to-string (/ (* number 100) divisor)) "%")) + (format "%d%%" (floor (* 100.0 number) divisor))) (defun profiler-format-number (number) "Format NUMBER in human readable string." diff --git a/lisp/progmodes/cc-cmds.el b/lisp/progmodes/cc-cmds.el index 94dc34bb20e..c9f59451b7e 100644 --- a/lisp/progmodes/cc-cmds.el +++ b/lisp/progmodes/cc-cmds.el @@ -1809,7 +1809,7 @@ with a brace block." (c-save-buffer-state (beginning-of-defun-function end-of-defun-function where pos name-end case-fold-search) - + (save-restriction (widen) (save-excursion @@ -3412,7 +3412,7 @@ Otherwise reindent just the current line." (if (< c-progress-interval (- now lastsecs)) (progn (message "Indenting region... (%d%% complete)" - (/ (* 100 (- (point) start)) (- end start))) + (floor (* 100.0 (- (point) start)) (- end start))) (aset c-progress-info 2 now))) ))) diff --git a/lisp/progmodes/cpp.el b/lisp/progmodes/cpp.el index bf8458e725a..0a51add68b6 100644 --- a/lisp/progmodes/cpp.el +++ b/lisp/progmodes/cpp.el @@ -234,7 +234,8 @@ A prefix arg suppresses display of that buffer." (cpp-progress-message "Parsing...") (while (re-search-forward cpp-parse-regexp nil t) (cpp-progress-message "Parsing...%d%%" - (/ (* 100 (- (point) (point-min))) (buffer-size))) + (floor (* 100.0 (- (point) (point-min))) + (buffer-size))) (let ((match (buffer-substring (match-beginning 0) (match-end 0)))) (cond ((or (string-equal match "'") (string-equal match "\"")) diff --git a/lisp/progmodes/idlwave.el b/lisp/progmodes/idlwave.el index 8e30aa29502..d7594428e8d 100644 --- a/lisp/progmodes/idlwave.el +++ b/lisp/progmodes/idlwave.el @@ -4881,7 +4881,7 @@ Cache to disk for quick recovery." props (car (cdr elem))) (if (= (mod elem-cnt msg-cnt) 0) (message "Converting XML routine info...%2d%%" - (/ (* elem-cnt 100) nelem))) + (floor (* elem-cnt 100.0) nelem))) (cond ((eq type 'ROUTINE) (if (setq alias (assq 'alias_to props)) @@ -8694,7 +8694,7 @@ can be used to detect possible name clashes during this process." (erase-buffer) (while (setq routine (pop routines)) (if (= (mod (setq n (1+ n)) step) 0) - (message "Compiling list...(%2d%%)" (/ (* n 100) nroutines))) + (message "Compiling list...(%2d%%)" (floor (* n 100.0) nroutines))) ;; Get a list of all twins (setq twins (idlwave-routine-twins routine (or lroutines routines))) diff --git a/lisp/progmodes/opascal.el b/lisp/progmodes/opascal.el index 2eba620ceb2..ef3433f003b 100644 --- a/lisp/progmodes/opascal.el +++ b/lisp/progmodes/opascal.el @@ -368,7 +368,7 @@ routine.") ;; Report the percentage complete. (setq opascal-progress-last-reported-point p) (message "%s %s ... %d%%" - desc (buffer-name) (/ (* 100 p) (point-max)))))) + desc (buffer-name) (floor (* 100.0 p) (point-max)))))) (defun opascal-next-line-start (&optional from-point) ;; Returns the first point of the next line. diff --git a/lisp/progmodes/vhdl-mode.el b/lisp/progmodes/vhdl-mode.el index 5ed0ff0ebed..16e4e8ed53d 100644 --- a/lisp/progmodes/vhdl-mode.el +++ b/lisp/progmodes/vhdl-mode.el @@ -7383,11 +7383,11 @@ only-lines." (- (nth 1 (current-time)) (aref vhdl-progress-info 2)))) (let ((delta (- (aref vhdl-progress-info 1) (aref vhdl-progress-info 0)))) - (if (= 0 delta) - (message (concat string "... (100%s)") "%") - (message (concat string "... (%2d%s)") - (/ (* 100 (- pos (aref vhdl-progress-info 0))) - delta) "%"))) + (message "%s... (%2d%%)" string + (if (= 0 delta) + 100 + (floor (* 100.0 (- pos (aref vhdl-progress-info 0))) + delta)))) (aset vhdl-progress-info 2 (nth 1 (current-time))))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -13881,10 +13881,10 @@ hierarchy otherwise.") ;; do for all files (while file-list (unless noninteractive - (message "Scanning %s %s\"%s\"... (%2d%s)" + (message "Scanning %s %s\"%s\"... (%2d%%)" (if is-directory "directory" "files") (or num-string "") name - (/ (* 100 (- no-files (length file-list))) no-files) "%")) + (floor (* 100.0 (- no-files (length file-list))) no-files))) (let ((file-name (abbreviate-file-name (car file-list))) ent-list arch-list arch-ent-list conf-list pack-list pack-body-list inst-list inst-ent-list) diff --git a/lisp/ps-print.el b/lisp/ps-print.el index e76b332ee3c..0ba470be68c 100644 --- a/lisp/ps-print.el +++ b/lisp/ps-print.el @@ -6043,10 +6043,7 @@ XSTART YSTART are the relative position for the first page in a sheet.") (progn (setq ps-razchunk q-done) (message "Formatting...%3d%%" - (if (< q-todo 100) - (/ (* 100 q-done) q-todo) - (/ q-done (/ q-todo 100))) - )))))) + (floor (* 100.0 q-done) q-todo))))))) (defvar ps-last-font nil) diff --git a/lisp/simple.el b/lisp/simple.el index 7eed279ed59..1a4bcf124db 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -1255,10 +1255,7 @@ in *Help* buffer. See also the command `describe-char'." (end (point-max)) (pos (point)) (total (buffer-size)) - (percent (if (> total 50000) - ;; Avoid overflow from multiplying by 100! - (/ (+ (/ total 200) (1- pos)) (max (/ total 100) 1)) - (/ (+ (/ total 2) (* 100 (1- pos))) (max total 1)))) + (percent (round (* 100.0 (1- pos)) (max 1 total))) (hscroll (if (= (window-hscroll) 0) "" (format " Hscroll=%d" (window-hscroll)))) diff --git a/lisp/textmodes/bibtex.el b/lisp/textmodes/bibtex.el index 9d6d19e6e1e..b1232d4c0a0 100644 --- a/lisp/textmodes/bibtex.el +++ b/lisp/textmodes/bibtex.el @@ -2099,7 +2099,7 @@ If FLAG is nil, a message is echoed if point was incremented at least (let* ((size (- (point-max) (point-min))) (perc (if (= size 0) 100 - (/ (* 100 (- (point) (point-min))) size)))) + (floor (* 100.0 (- (point) (point-min))) size)))) (when (>= perc (+ bibtex-progress-lastperc bibtex-progress-interval)) (setq bibtex-progress-lastperc perc) diff --git a/lisp/textmodes/flyspell.el b/lisp/textmodes/flyspell.el index e0749180611..64aa3de146e 100644 --- a/lisp/textmodes/flyspell.el +++ b/lisp/textmodes/flyspell.el @@ -1350,7 +1350,7 @@ that may be included as part of a word (see `ispell-dictionary-alist')." (if (and flyspell-issue-message-flag (= count 100)) (progn (message "Spell Checking...%d%%" - (* 100 (/ (float (- (point) beg)) (- end beg)))) + (floor (* 100.0 (- (point) beg)) (- end beg))) (setq count 0)) (setq count (+ 1 count))) (flyspell-word) @@ -1403,7 +1403,7 @@ The buffer to mark them in is `flyspell-large-region-buffer'." ;; be unnecessary too. -- rms. (if flyspell-issue-message-flag (message "Spell Checking...%d%% [%s]" - (* 100 (/ (float (point)) (point-max))) + (floor (* 100.0 (point)) (point-max)) word)) (with-current-buffer flyspell-large-region-buffer (goto-char buffer-scan-pos) diff --git a/lisp/textmodes/table.el b/lisp/textmodes/table.el index edc78e52efa..fa9f0fa638a 100644 --- a/lisp/textmodes/table.el +++ b/lisp/textmodes/table.el @@ -1893,7 +1893,9 @@ all the table specific features." (while (and (re-search-forward border3 (point-max) t) (not (and (input-pending-p) table-abort-recognition-when-input-pending))) - (message "Recognizing tables...(%d%%)" (/ (* 100 (match-beginning 0)) (- (point-max) (point-min)))) + (message "Recognizing tables...(%d%%)" + (floor (* 100.0 (match-beginning 0)) + (- (point-max) (point-min)))) (let ((beg (match-beginning 0)) end) (if (re-search-forward non-border (point-max) t)