aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Eggert2020-01-24 16:57:31 -0800
committerPaul Eggert2020-01-24 16:58:41 -0800
commit7f5069850529f37e44939ce612e20d85be25af5c (patch)
treecc085d23f0aa6d18ac2d20a66df990af642ac3b3
parente5327a569c4db8f53b1497057bbac58f77330389 (diff)
downloademacs-7f5069850529f37e44939ce612e20d85be25af5c.tar.gz
emacs-7f5069850529f37e44939ce612e20d85be25af5c.zip
Improve doc of eq on bignums etc.
* doc/lispref/numbers.texi (Integer Basics): * doc/lispref/objects.texi (Integer Type, Equality Predicates): Be clearer about eq vs eql vs = on bignums, floats, and strings.
-rw-r--r--doc/lispref/numbers.texi4
-rw-r--r--doc/lispref/objects.texi32
2 files changed, 19 insertions, 17 deletions
diff --git a/doc/lispref/numbers.texi b/doc/lispref/numbers.texi
index e952980f26f..c8941eab736 100644
--- a/doc/lispref/numbers.texi
+++ b/doc/lispref/numbers.texi
@@ -39,8 +39,8 @@ numbers have a fixed amount of precision.
39 Under the hood, though, there are two kinds of integers: smaller 39 Under the hood, though, there are two kinds of integers: smaller
40ones, called @dfn{fixnums}, and larger ones, called @dfn{bignums}. 40ones, called @dfn{fixnums}, and larger ones, called @dfn{bignums}.
41Some functions in Emacs accept only fixnums. Also, while fixnums can 41Some functions in Emacs accept only fixnums. Also, while fixnums can
42always be compared for numeric equality with @code{eq}, bignums 42be compared for numeric equality with @code{eq}, bignums require
43require more-heavyweight equality predicates like @code{eql}. 43more-heavyweight equality predicates like @code{eql} and @code{=}.
44 44
45 The range of values for bignums is limited by the amount of main 45 The range of values for bignums is limited by the amount of main
46memory, by machine characteristics such as the size of the word used 46memory, by machine characteristics such as the size of the word used
diff --git a/doc/lispref/objects.texi b/doc/lispref/objects.texi
index 4be2eb6918b..1c4e7e4d4e3 100644
--- a/doc/lispref/objects.texi
+++ b/doc/lispref/objects.texi
@@ -266,8 +266,8 @@ but many machines provide a wider range.
266 Bignums can have arbitrary precision. Operations that overflow a 266 Bignums can have arbitrary precision. Operations that overflow a
267fixnum will return a bignum instead. 267fixnum will return a bignum instead.
268 268
269 Fixnums can be compared with @code{eq}, but bignums require 269 All numbers can be compared with @code{eql} or @code{=}; fixnums can
270@code{eql} or @code{=}. To test whether an integer is a fixnum or a 270also be compared with @code{eq}. To test whether an integer is a fixnum or a
271bignum, you can compare it to @code{most-negative-fixnum} and 271bignum, you can compare it to @code{most-negative-fixnum} and
272@code{most-positive-fixnum}, or you can use the convenience predicates 272@code{most-positive-fixnum}, or you can use the convenience predicates
273@code{fixnump} and @code{bignump} on any object. 273@code{fixnump} and @code{bignump} on any object.
@@ -2167,17 +2167,20 @@ appropriate chapter describing the data type.
2167This function returns @code{t} if @var{object1} and @var{object2} are 2167This function returns @code{t} if @var{object1} and @var{object2} are
2168the same object, and @code{nil} otherwise. 2168the same object, and @code{nil} otherwise.
2169 2169
2170If @var{object1} and @var{object2} are fixnums with the same value, 2170If @var{object1} and @var{object2} are symbols with the
2171they are considered to be the same object (i.e., @code{eq} returns
2172@code{t}). If @var{object1} and @var{object2} are symbols with the
2173same name, they are normally the same object---but see @ref{Creating 2171same name, they are normally the same object---but see @ref{Creating
2174Symbols} for exceptions. For other types (e.g., lists, vectors, 2172Symbols} for exceptions. For other non-numeric types (e.g., lists, vectors,
2175strings), two arguments with the same contents or elements are not 2173strings), two arguments with the same contents or elements are not
2176necessarily @code{eq} to each other: they are @code{eq} only if they 2174necessarily @code{eq} to each other: they are @code{eq} only if they
2177are the same object, meaning that a change in the contents of one will 2175are the same object, meaning that a change in the contents of one will
2178be reflected by the same change in the contents of the other. 2176be reflected by the same change in the contents of the other.
2179For other types of objects whose contents cannot be changed (e.g., 2177
2180bignums and floats), two arguments with the same contents might or might not be 2178If @var{object1} and @var{object2} are numbers with differing types or values,
2179then they cannot be the same object and @code{eq} returns @code{nil}.
2180If they are fixnums with the same value,
2181then they are the same object and @code{eq} returns @code{t}.
2182If they were computed separately but happen to have the same value
2183and the same non-fixnum numeric type, then they might or might not be
2181the same object, and @code{eq} returns @code{t} or @code{nil} 2184the same object, and @code{eq} returns @code{t} or @code{nil}
2182depending on whether the Lisp interpreter created one object or two. 2185depending on whether the Lisp interpreter created one object or two.
2183 2186
@@ -2188,26 +2191,25 @@ depending on whether the Lisp interpreter created one object or two.
2188@end group 2191@end group
2189 2192
2190@group 2193@group
2191(eq 456 456) 2194(eq ?A ?A)
2192 @result{} t 2195 @result{} t
2193@end group 2196@end group
2194 2197
2195@group 2198@group
2196(eq 3.0 3.0) 2199(eq 3.0 3.0)
2197 @result{} t @r{or} nil 2200 @result{} t @r{or} nil
2198;; @r{The result is implementation-dependent.} 2201;; @r{Equal floats may or may not be the same object.}
2199@end group 2202@end group
2200 2203
2201@group 2204@group
2202(eq "asdf" "asdf") 2205(eq (make-string 3 ?A) (make-string 3 ?A))
2203 @result{} nil 2206 @result{} nil
2204@end group 2207@end group
2205 2208
2206@group 2209@group
2207(eq "" "") 2210(eq "asdf" "asdf")
2208 @result{} t 2211 @result{} t @r{or} nil
2209;; @r{This exception occurs because Emacs Lisp} 2212;; @r{Equal string constants or may not be the same object.}
2210;; @r{makes just one multibyte empty string, to save space.}
2211@end group 2213@end group
2212 2214
2213@group 2215@group