summaryrefslogtreecommitdiff
path: root/doc/misc/calc.texi
diff options
context:
space:
mode:
authorMattias Engdegård <mattiase@acm.org>2020-10-10 18:02:49 +0200
committerMattias Engdegård <mattiase@acm.org>2020-10-13 11:29:01 +0200
commitcf407958886e46881216a510efebb8bc029de50c (patch)
tree2f67e4b672f10355ad941a39abd58b6c523a3683 /doc/misc/calc.texi
parentadd1314195b193f04164cebe558d7a185b61de96 (diff)
downloademacs-cf407958886e46881216a510efebb8bc029de50c.tar.gz
Calc: allow infinite binary word size (bug#43764)
Setting the word size ("b w") to 0 removes the word size clipping for all bit operations (effectively as if a word size of -∞ had been set). Rotation is disallowed; logical and arithmetic shifts behave identically. After a suggestion by Vincent Belaïche. * lisp/calc/calc-bin.el (calc-word-size, math-binary-arg) (math-binary-modulo-args, calcFunc-lsh, calcFunc-ash, calcFunc-rot) (math-clip, math-format-twos-complement): Allow a word size of 0, meaning -∞. * test/lisp/calc/calc-tests.el (calc-tests--not, calc-tests--and, calc-tests--or, calc-tests--xor) (calc-tests--diff): New functions. (calc-tests--clip, calc-tests--rot, calc-shift-binary): Extend to cover word size 0. (calc-bit-ops): New test. * doc/misc/calc.texi (Binary Functions): Update manual. * etc/NEWS: Announce the change.
Diffstat (limited to 'doc/misc/calc.texi')
-rw-r--r--doc/misc/calc.texi11
1 files changed, 10 insertions, 1 deletions
diff --git a/doc/misc/calc.texi b/doc/misc/calc.texi
index a356cecf2b7..6a6f585ce20 100644
--- a/doc/misc/calc.texi
+++ b/doc/misc/calc.texi
@@ -18077,7 +18077,7 @@ zeros with @kbd{d z}. @xref{Radix Modes}.
@cindex Word size for binary operations
The Calculator maintains a current @dfn{word size} @expr{w}, an
-arbitrary positive or negative integer. For a positive word size, all
+arbitrary integer. For a positive word size, all
of the binary operations described here operate modulo @expr{2^w}. In
particular, negative arguments are converted to positive integers modulo
@expr{2^w} by all binary functions.
@@ -18092,6 +18092,9 @@ to
inclusive. Either mode accepts inputs in any range; the sign of
@expr{w} affects only the results produced.
+If the word size is zero, binary operations work on the entire number
+without clipping, as if the word size had been negative infinity.
+
@kindex b c
@pindex calc-clip
@tindex clip
@@ -18221,6 +18224,10 @@ and @samp{rash} operations is totally independent from whether the word
size is positive or negative.) With a negative prefix argument, this
performs a standard left shift.
+When the word size is zero, logical and arithmetic shift operations
+are identical: a negative value shifted right remains negative, since
+there is an infinite supply of ones to shift in.
+
@kindex b t
@pindex calc-rotate-binary
@tindex rot
@@ -18230,6 +18237,8 @@ word size) is dropped off the left and shifted in on the right. With a
numeric prefix argument, the number is rotated that many bits to the left
or right.
+Rotation is not possible with a zero word size.
+
@xref{Set Operations}, for the @kbd{b p} and @kbd{b u} commands that
pack and unpack binary integers into sets. (For example, @kbd{b u}
unpacks the number @samp{2#11001} to the set of bit-numbers