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))))
((not (equal n (car math-prime-test-cache)))
(cond ((if (consp n)
(= (% (nth 1 n) 2) 0)
(= (% n 2) 0))
(evenp (nth 1 n))
(evenp n))
'(nil 2))
((if (consp n)
(= (% (nth 1 n) 5) 0)

View file

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

View file

@ -402,7 +402,7 @@ If this can't be done, return NIL."
(math-div (math-float num-sqrt) den-sqrt))))))
(and (eq (car-safe a) 'float)
(if calc-symbolic-mode
(if (= (% (nth 2 a) 2) 0)
(if (evenp (nth 2 a))
(let ((res (cl-isqrt (nth 1 a))))
(if (= (* res res) (nth 1 a))
(math-make-float res (/ (nth 2 a) 2))
@ -468,7 +468,7 @@ If this can't be done, return NIL."
(t
(if (null guess)
(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
(math-scale-int (nth 1 a) (- ldiff)))
(/ (+ (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]
(cond ((= n 0) 1)
((= 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))))))
(defun math-iipow-show (a n) ; [O O S]
@ -906,7 +906,7 @@ loaded and the keystroke automatically re-typed."
(let ((val (cond
((= n 0) 1)
((= 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)))))))
(math-working "pow" val)
val))

View file

@ -390,7 +390,7 @@
(math-reject-arg (car p) 'anglep))
(setq p (cdr p)))
(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)
(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-cmd "\\pagestyle" "empty")
(dotimes (i n)
(if (zerop (mod i 2))
(if (evenp i)
(insert "\\righthead")
(insert "\\lefthead"))
(cal-tex-arg
@ -1318,7 +1318,7 @@ Optional EVENT indicates a buffer position to use instead of point."
(calendar-extract-year d))))))
(insert "%\n")
(dotimes (_jdummy 7)
(if (zerop (mod i 2))
(if (evenp i)
(insert "\\rightday")
(insert "\\leftday"))
(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")
(dotimes (i n)
(dotimes (j 4)
(let ((even (zerop (% j 2))))
(let ((even (evenp j)))
(insert (if even
"\\righthead"
"\\lefthead"))

View file

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

View file

@ -2109,7 +2109,7 @@ The text checked is between START and LIMIT."
(goto-char start)
(while (and (< (point) p) (re-search-forward "\\\\\"" limit t))
(setq c (1+ c)))
(and (< 0 c) (= (% c 2) 0))))))
(and (< 0 c) (evenp c))))))
(defun checkdoc-in-abbreviation-p (begin)
"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)
(cond ((and (stringp (car options-and-doc))
(/= 1 (% (length options-and-doc) 2)))
(evenp (length options-and-doc)))
(error "Too many arguments to `defclass'"))
((and (symbolp (car options-and-doc))
(oddp (length options-and-doc)))

View file

@ -260,7 +260,7 @@ structure with the plists in ARGS."
(string (let ((begin (point)))
(insert x)
(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))
(setq current-plist x))))
(buffer-string)))

View file

@ -576,7 +576,7 @@ Return nil if they are."
(defun ert--significant-plist-keys (plist)
"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
unless (or (null value) (memq key accu)) collect key into 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
each key, where absent values are treated as nil. The order of
key/value pairs in each list does not matter."
(cl-assert (zerop (mod (length a) 2)) t)
(cl-assert (zerop (mod (length b) 2)) t)
(cl-assert (evenp (length a)) t)
(cl-assert (evenp (length b)) t)
;; Normalizing the plists would be another way to do this but it
;; requires a total ordering on all lisp objects (since any object
;; is valid as a text property key). Perhaps defining such an

View file

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

View file

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

View file

@ -914,7 +914,7 @@ earlier in the `setq-connection-local'. The return value of the
\(fn [VARIABLE VALUE]...)"
(declare (debug setq))
(unless (zerop (mod (length pairs) 2))
(unless (evenp (length pairs))
(error "PAIRS must have an even number of variable/value members"))
(let ((set-expr 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 ?-)
file-name i parts
(make-string
(if (= 0 (% whole-len 2)) (1- minlen) minlen) ?-)))
(if (evenp whole-len) (1- minlen) minlen) ?-)))
(goto-char (point-min))
(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)
(when (prog2
(backward-char)
(zerop (% (skip-chars-backward "\\\\") 2))
(evenp (skip-chars-backward "\\\\"))
(goto-char (match-beginning 0)))
(insert "\\"))
(forward-char))

View file

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

View file

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

View file

@ -312,7 +312,7 @@ Quit current game \\[5x5-quit-game]"
(forward-char (+ 1 (/ (1+ 5x5-x-scale) 2)))
(dotimes (x 5x5-grid-size)
(when (5x5-cell solution-grid y x)
(if (= 0 (mod 5x5-x-scale 2))
(if (evenp 5x5-x-scale)
(progn
(insert "()")
(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.
(let ((running gametree-default-score)
(minmax
(if (= 0 (mod (gametree-current-branch-ply) 2))
(if (evenp (gametree-current-branch-ply))
'max 'min)))
(while (and (not (eobp))
(= 0 (gametree-current-branch-depth))) ;handle leaves
@ -395,7 +395,7 @@ depth AT-DEPTH or smaller is found."
(gametree-current-branch-ply)))))
(goto-char (1- (point)))
(insert "\n")
(insert (format (if (= 0 (mod starting-plies 2))
(insert (format (if (evenp starting-plies)
gametree-full-ply-format
gametree-half-ply-format)
(/ starting-plies 2))))))
@ -450,7 +450,7 @@ only work of Black's moves are explicitly numbered, for instance
gametree-full-ply-regexp "\\|"
gametree-half-ply-regexp "\\)")))
(progn
(insert (format (if (= 0 (mod (gametree-looking-at-ply) 2))
(insert (format (if (evenp (gametree-looking-at-ply))
gametree-full-ply-format
gametree-half-ply-format)
(/ (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)
(goto-char pos)
(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))))
(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))
;; 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)))
;; odd prefix arg: get patch from a file
((and (integerp arg) (oddp arg))

View file

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