1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-06 06:20:55 -08:00

Prefer '(evenp A)' to '(= 0 (% A 2))'

* lisp/calc/calc-comb.el (math-prime-test):
* lisp/calc/calc-keypd.el (calc-keypad-press):
* lisp/calc/calc-math.el (math-sqrt):
(math-sqrt-raw):
* lisp/calc/calc-misc.el (math-iipow):
(math-iipow-show):
* lisp/calc/calc-stat.el (calcFunc-vmedian):
* lisp/calendar/cal-tex.el (cal-tex-cursor-filofax-2week):
(cal-tex-cursor-filofax-daily):
* lisp/elec-pair.el (electric-pair-post-self-insert-function):
* lisp/emacs-lisp/checkdoc.el (checkdoc-in-example-string-p):
* lisp/emacs-lisp/eieio.el (defclass):
* lisp/emacs-lisp/ert-x.el (ert-propertized-string):
* lisp/emacs-lisp/ert.el (ert--significant-plist-keys):
(ert--plist-difference-explanation):
* lisp/emacs-lisp/helper.el (Helper-help-scroller):
* lisp/emacs-lisp/pcase.el (pcase-setq):
* lisp/files-x.el (setq-connection-local):
* lisp/gnus/gnus-uu.el (gnus-uu-post-encoded):
* lisp/gnus/message.el (message-make-in-reply-to):
* lisp/gnus/nndiary.el (nndiary-last-occurrence):
(nndiary-next-occurrence):
* lisp/mail/rfc2047.el (rfc2047-decode-region):
* lisp/play/5x5.el (5x5-draw-grid):
* lisp/play/gametree.el (gametree-compute-reduced-score):
(gametree-insert-new-leaf):
(gametree-break-line-here):
* lisp/play/zone.el (zone-fret):
* lisp/vc/ediff-ptch.el (ediff-get-patch-buffer):
* lisp/yank-media.el (yank-media--utf-16-p): Prefer '(evenp A)' to
'(= 0 (% A 2))' and variations thereof.
This commit is contained in:
Stefan Kangas 2025-02-17 05:10:33 +01:00
parent e373a6e0d3
commit 89bdb57f24
23 changed files with 35 additions and 35 deletions

View file

@ -826,8 +826,8 @@
'(t)))) '(t))))
((not (equal n (car math-prime-test-cache))) ((not (equal n (car math-prime-test-cache)))
(cond ((if (consp n) (cond ((if (consp n)
(= (% (nth 1 n) 2) 0) (evenp (nth 1 n))
(= (% n 2) 0)) (evenp n))
'(nil 2)) '(nil 2))
((if (consp n) ((if (consp n)
(= (% (nth 1 n) 5) 0) (= (% (nth 1 n) 5) 0)

View file

@ -411,7 +411,7 @@
(if invhyp (calc-wrapper)) ; clear Inv and Hyp flags (if invhyp (calc-wrapper)) ; clear Inv and Hyp flags
(unwind-protect (unwind-protect
(cond ((or (null cmd) (cond ((or (null cmd)
(= (% row 2) 0)) (evenp row))
(beep)) (beep))
((and (> (minibuffer-depth) 0)) ((and (> (minibuffer-depth) 0))
(cond (isstring (cond (isstring

View file

@ -402,7 +402,7 @@ If this can't be done, return NIL."
(math-div (math-float num-sqrt) den-sqrt)))))) (math-div (math-float num-sqrt) den-sqrt))))))
(and (eq (car-safe a) 'float) (and (eq (car-safe a) 'float)
(if calc-symbolic-mode (if calc-symbolic-mode
(if (= (% (nth 2 a) 2) 0) (if (evenp (nth 2 a))
(let ((res (cl-isqrt (nth 1 a)))) (let ((res (cl-isqrt (nth 1 a))))
(if (= (* res res) (nth 1 a)) (if (= (* res res) (nth 1 a))
(math-make-float res (/ (nth 2 a) 2)) (math-make-float res (/ (nth 2 a) 2))
@ -468,7 +468,7 @@ If this can't be done, return NIL."
(t (t
(if (null guess) (if (null guess)
(let ((ldiff (- (math-numdigs (nth 1 a)) 6))) (let ((ldiff (- (math-numdigs (nth 1 a)) 6)))
(or (= (% (+ (nth 2 a) ldiff) 2) 0) (setq ldiff (1+ ldiff))) (or (evenp (+ (nth 2 a) ldiff)) (setq ldiff (1+ ldiff)))
(setq guess (math-make-float (cl-isqrt (setq guess (math-make-float (cl-isqrt
(math-scale-int (nth 1 a) (- ldiff))) (math-scale-int (nth 1 a) (- ldiff)))
(/ (+ (nth 2 a) ldiff) 2))))) (/ (+ (nth 2 a) ldiff) 2)))))

View file

@ -898,7 +898,7 @@ loaded and the keystroke automatically re-typed."
(defun math-iipow (a n) ; [O O S] (defun math-iipow (a n) ; [O O S]
(cond ((= n 0) 1) (cond ((= n 0) 1)
((= n 1) a) ((= n 1) a)
((= (% n 2) 0) (math-iipow (math-mul a a) (/ n 2))) ((evenp n) (math-iipow (math-mul a a) (/ n 2)))
(t (math-mul a (math-iipow (math-mul a a) (/ n 2)))))) (t (math-mul a (math-iipow (math-mul a a) (/ n 2))))))
(defun math-iipow-show (a n) ; [O O S] (defun math-iipow-show (a n) ; [O O S]
@ -906,7 +906,7 @@ loaded and the keystroke automatically re-typed."
(let ((val (cond (let ((val (cond
((= n 0) 1) ((= n 0) 1)
((= n 1) a) ((= n 1) a)
((= (% n 2) 0) (math-iipow-show (math-mul a a) (/ n 2))) ((evenp n) (math-iipow-show (math-mul a a) (/ n 2)))
(t (math-mul a (math-iipow-show (math-mul a a) (/ n 2))))))) (t (math-mul a (math-iipow-show (math-mul a a) (/ n 2)))))))
(math-working "pow" val) (math-working "pow" val)
val)) val))

View file

@ -390,7 +390,7 @@
(math-reject-arg (car p) 'anglep)) (math-reject-arg (car p) 'anglep))
(setq p (cdr p))) (setq p (cdr p)))
(setq flat (sort flat 'math-lessp)) (setq flat (sort flat 'math-lessp))
(if (= (% len 2) 0) (if (evenp len)
(math-div (math-add (nth (1- hlen) flat) (nth hlen flat)) 2) (math-div (math-add (nth (1- hlen) flat) (nth hlen flat)) 2)
(nth hlen flat)))))) (nth hlen flat))))))

View file

@ -1295,7 +1295,7 @@ Optional EVENT indicates a buffer position to use instead of point."
(cal-tex-b-document) (cal-tex-b-document)
(cal-tex-cmd "\\pagestyle" "empty") (cal-tex-cmd "\\pagestyle" "empty")
(dotimes (i n) (dotimes (i n)
(if (zerop (mod i 2)) (if (evenp i)
(insert "\\righthead") (insert "\\righthead")
(insert "\\lefthead")) (insert "\\lefthead"))
(cal-tex-arg (cal-tex-arg
@ -1318,7 +1318,7 @@ Optional EVENT indicates a buffer position to use instead of point."
(calendar-extract-year d)))))) (calendar-extract-year d))))))
(insert "%\n") (insert "%\n")
(dotimes (_jdummy 7) (dotimes (_jdummy 7)
(if (zerop (mod i 2)) (if (evenp i)
(insert "\\rightday") (insert "\\rightday")
(insert "\\leftday")) (insert "\\leftday"))
(cal-tex-arg (cal-tex-LaTeXify-string (calendar-day-name date))) (cal-tex-arg (cal-tex-LaTeXify-string (calendar-day-name date)))
@ -1388,7 +1388,7 @@ Optional EVENT indicates a buffer position to use instead of point."
(cal-tex-cmd "\\pagestyle" "empty") (cal-tex-cmd "\\pagestyle" "empty")
(dotimes (i n) (dotimes (i n)
(dotimes (j 4) (dotimes (j 4)
(let ((even (zerop (% j 2)))) (let ((even (evenp j)))
(insert (if even (insert (if even
"\\righthead" "\\righthead"
"\\lefthead")) "\\lefthead"))

View file

@ -558,7 +558,7 @@ The decision is taken by order of preference:
;; Backslash-escaped: no pairing, no skipping. ;; Backslash-escaped: no pairing, no skipping.
((save-excursion ((save-excursion
(goto-char beg) (goto-char beg)
(not (zerop (% (skip-syntax-backward "\\") 2)))) (not (evenp (skip-syntax-backward "\\"))))
(let ((current-prefix-arg (1- num))) (let ((current-prefix-arg (1- num)))
(electric-pair-post-self-insert-function))) (electric-pair-post-self-insert-function)))
;; Skip self. ;; Skip self.

View file

@ -2109,7 +2109,7 @@ The text checked is between START and LIMIT."
(goto-char start) (goto-char start)
(while (and (< (point) p) (re-search-forward "\\\\\"" limit t)) (while (and (< (point) p) (re-search-forward "\\\\\"" limit t))
(setq c (1+ c))) (setq c (1+ c)))
(and (< 0 c) (= (% c 2) 0)))))) (and (< 0 c) (evenp c))))))
(defun checkdoc-in-abbreviation-p (begin) (defun checkdoc-in-abbreviation-p (begin)
"Return non-nil if point is at an abbreviation. "Return non-nil if point is at an abbreviation.

View file

@ -115,7 +115,7 @@ and reference them using the function `class-option'."
(cl-check-type superclasses list) (cl-check-type superclasses list)
(cond ((and (stringp (car options-and-doc)) (cond ((and (stringp (car options-and-doc))
(/= 1 (% (length options-and-doc) 2))) (evenp (length options-and-doc)))
(error "Too many arguments to `defclass'")) (error "Too many arguments to `defclass'"))
((and (symbolp (car options-and-doc)) ((and (symbolp (car options-and-doc))
(oddp (length options-and-doc))) (oddp (length options-and-doc)))

View file

@ -260,7 +260,7 @@ structure with the plists in ARGS."
(string (let ((begin (point))) (string (let ((begin (point)))
(insert x) (insert x)
(set-text-properties begin (point) current-plist))) (set-text-properties begin (point) current-plist)))
(list (unless (zerop (mod (length x) 2)) (list (unless (evenp (length x))
(error "Odd number of args in plist: %S" x)) (error "Odd number of args in plist: %S" x))
(setq current-plist x)))) (setq current-plist x))))
(buffer-string))) (buffer-string)))

View file

@ -576,7 +576,7 @@ Return nil if they are."
(defun ert--significant-plist-keys (plist) (defun ert--significant-plist-keys (plist)
"Return the keys of PLIST that have non-null values, in order." "Return the keys of PLIST that have non-null values, in order."
(cl-assert (zerop (mod (length plist) 2)) t) (cl-assert (evenp (length plist)) t)
(cl-loop for (key value . rest) on plist by #'cddr (cl-loop for (key value . rest) on plist by #'cddr
unless (or (null value) (memq key accu)) collect key into accu unless (or (null value) (memq key accu)) collect key into accu
finally (cl-return accu))) finally (cl-return accu)))
@ -587,8 +587,8 @@ Return nil if they are."
Returns nil if they are equivalent, i.e., have the same value for Returns nil if they are equivalent, i.e., have the same value for
each key, where absent values are treated as nil. The order of each key, where absent values are treated as nil. The order of
key/value pairs in each list does not matter." key/value pairs in each list does not matter."
(cl-assert (zerop (mod (length a) 2)) t) (cl-assert (evenp (length a)) t)
(cl-assert (zerop (mod (length b) 2)) t) (cl-assert (evenp (length b)) t)
;; Normalizing the plists would be another way to do this but it ;; Normalizing the plists would be another way to do this but it
;; requires a total ordering on all lisp objects (since any object ;; requires a total ordering on all lisp objects (since any object
;; is valid as a text property key). Perhaps defining such an ;; is valid as a text property key). Perhaps defining such an

View file

@ -80,7 +80,7 @@
(recenter)) (recenter))
((and (or (eq continue 'backspace) ((and (or (eq continue 'backspace)
(eq continue ?\177)) (eq continue ?\177))
(zerop (% state 2))) (evenp state))
(scroll-down)) (scroll-down))
(t (setq continue nil)))))))) (t (setq continue nil))))))))

View file

@ -370,7 +370,7 @@ undetected, binding variables to arbitrary values, such as nil.
(cond (cond
(args (args
(let ((arg-length (length args))) (let ((arg-length (length args)))
(unless (= 0 (mod arg-length 2)) (unless (evenp arg-length)
(signal 'wrong-number-of-arguments (signal 'wrong-number-of-arguments
(list 'pcase-setq (+ 2 arg-length))))) (list 'pcase-setq (+ 2 arg-length)))))
(let ((result)) (let ((result))

View file

@ -914,7 +914,7 @@ earlier in the `setq-connection-local'. The return value of the
\(fn [VARIABLE VALUE]...)" \(fn [VARIABLE VALUE]...)"
(declare (debug setq)) (declare (debug setq))
(unless (zerop (mod (length pairs) 2)) (unless (evenp (length pairs))
(error "PAIRS must have an even number of variable/value members")) (error "PAIRS must have an even number of variable/value members"))
(let ((set-expr nil) (let ((set-expr nil)
(profile-vars nil)) (profile-vars nil))

View file

@ -2098,7 +2098,7 @@ If no file has been included, the user will be asked for a file."
(make-string minlen ?-) (make-string minlen ?-)
file-name i parts file-name i parts
(make-string (make-string
(if (= 0 (% whole-len 2)) (1- minlen) minlen) ?-))) (if (evenp whole-len) (1- minlen) minlen) ?-)))
(goto-char (point-min)) (goto-char (point-min))
(when (re-search-forward "^Subject: " nil t) (when (re-search-forward "^Subject: " nil t)

View file

@ -6035,7 +6035,7 @@ In posting styles use `(\"Expires\" (make-expires-date 30))'."
(while (search-forward "\"" nil t) (while (search-forward "\"" nil t)
(when (prog2 (when (prog2
(backward-char) (backward-char)
(zerop (% (skip-chars-backward "\\\\") 2)) (evenp (skip-chars-backward "\\\\"))
(goto-char (match-beginning 0))) (goto-char (match-beginning 0)))
(insert "\\")) (insert "\\"))
(forward-char)) (forward-char))

View file

@ -1353,9 +1353,9 @@ all. This may very well take some time.")
(max (cond ((= month 2) (max (cond ((= month 2)
(if (date-leap-year-p year) 29 28)) (if (date-leap-year-p year) 29 28))
((<= month 7) ((<= month 7)
(if (zerop (% month 2)) 30 31)) (if (evenp month) 30 31))
(t (t
(if (zerop (% month 2)) 31 30)))) (if (evenp month) 31 30))))
(doms dom-list) (doms dom-list)
(dows dow-list) (dows dow-list)
day days) day days)
@ -1456,9 +1456,9 @@ all. This may very well take some time.")
(max (cond ((= month 2) (max (cond ((= month 2)
(if (date-leap-year-p year) 29 28)) (if (date-leap-year-p year) 29 28))
((<= month 7) ((<= month 7)
(if (zerop (% month 2)) 30 31)) (if (evenp month) 30 31))
(t (t
(if (zerop (% month 2)) 31 30)))) (if (evenp month) 31 30))))
(doms dom-list) (doms dom-list)
(dows dow-list) (dows dow-list)
day days) day days)

View file

@ -1076,7 +1076,7 @@ other than `\"' and `\\' in quoted strings."
(while (search-forward "\"" end t) (while (search-forward "\"" end t)
(when (prog2 (when (prog2
(backward-char) (backward-char)
(zerop (% (skip-chars-backward "\\\\") 2)) (evenp (skip-chars-backward "\\\\"))
(goto-char (match-beginning 0))) (goto-char (match-beginning 0)))
(insert "\\")) (insert "\\"))
(forward-char)) (forward-char))

View file

@ -312,7 +312,7 @@ Quit current game \\[5x5-quit-game]"
(forward-char (+ 1 (/ (1+ 5x5-x-scale) 2))) (forward-char (+ 1 (/ (1+ 5x5-x-scale) 2)))
(dotimes (x 5x5-grid-size) (dotimes (x 5x5-grid-size)
(when (5x5-cell solution-grid y x) (when (5x5-cell solution-grid y x)
(if (= 0 (mod 5x5-x-scale 2)) (if (evenp 5x5-x-scale)
(progn (progn
(insert "()") (insert "()")
(delete-region (point) (+ (point) 2)) (delete-region (point) (+ (point) 2))

View file

@ -347,7 +347,7 @@ Subnodes which have been manually scored are honored."
;; be either a leaf child, or a subheading. ;; be either a leaf child, or a subheading.
(let ((running gametree-default-score) (let ((running gametree-default-score)
(minmax (minmax
(if (= 0 (mod (gametree-current-branch-ply) 2)) (if (evenp (gametree-current-branch-ply))
'max 'min))) 'max 'min)))
(while (and (not (eobp)) (while (and (not (eobp))
(= 0 (gametree-current-branch-depth))) ;handle leaves (= 0 (gametree-current-branch-depth))) ;handle leaves
@ -395,7 +395,7 @@ depth AT-DEPTH or smaller is found."
(gametree-current-branch-ply))))) (gametree-current-branch-ply)))))
(goto-char (1- (point))) (goto-char (1- (point)))
(insert "\n") (insert "\n")
(insert (format (if (= 0 (mod starting-plies 2)) (insert (format (if (evenp starting-plies)
gametree-full-ply-format gametree-full-ply-format
gametree-half-ply-format) gametree-half-ply-format)
(/ starting-plies 2)))))) (/ starting-plies 2))))))
@ -450,7 +450,7 @@ only work of Black's moves are explicitly numbered, for instance
gametree-full-ply-regexp "\\|" gametree-full-ply-regexp "\\|"
gametree-half-ply-regexp "\\)"))) gametree-half-ply-regexp "\\)")))
(progn (progn
(insert (format (if (= 0 (mod (gametree-looking-at-ply) 2)) (insert (format (if (evenp (gametree-looking-at-ply))
gametree-full-ply-format gametree-full-ply-format
gametree-half-ply-format) gametree-half-ply-format)
(/ (gametree-looking-at-ply) 2))) (/ (gametree-looking-at-ply) 2)))

View file

@ -454,7 +454,7 @@ run a specific program. The program must be a member of
(dotimes (i 20) (dotimes (i 20)
(goto-char pos) (goto-char pos)
(delete-char 1) (delete-char 1)
(insert (if (= 0 (% i 2)) hmm c-string)) (insert (if (evenp i) hmm c-string))
(zone-park/sit-for wbeg (setq wait (* wait 0.8)))) (zone-park/sit-for wbeg (setq wait (* wait 0.8))))
(delete-char -1) (insert c-string))) (delete-char -1) (insert c-string)))

View file

@ -549,7 +549,7 @@ an optional argument, then use it."
(cond ((ediff-buffer-live-p patch-buf)) (cond ((ediff-buffer-live-p patch-buf))
;; even prefix arg: patch in buffer ;; even prefix arg: patch in buffer
((and (integerp arg) (eq 0 (mod arg 2))) ((and (integerp arg) (evenp arg))
(setq patch-buf (ediff-prompt-for-patch-buffer))) (setq patch-buf (ediff-prompt-for-patch-buffer)))
;; odd prefix arg: get patch from a file ;; odd prefix arg: get patch from a file
((and (integerp arg) (oddp arg)) ((and (integerp arg) (oddp arg))

View file

@ -172,7 +172,7 @@ non-supported selection data types."
data))) data)))
(defun yank-media--utf-16-p (data) (defun yank-media--utf-16-p (data)
(and (zerop (mod (length data) 2)) (and (evenp (length data))
(let ((stats (vector 0 0))) (let ((stats (vector 0 0)))
(dotimes (i (length data)) (dotimes (i (length data))
(when (zerop (elt data i)) (when (zerop (elt data i))