aboutsummaryrefslogtreecommitdiffstats
path: root/lispref
diff options
context:
space:
mode:
authorRichard M. Stallman2005-02-14 10:19:36 +0000
committerRichard M. Stallman2005-02-14 10:19:36 +0000
commit4182ecfc37b3cf6051321ae7bef4e8a4dce1f94b (patch)
treeec17308c959bc88438f1af0a54120554cdba214e /lispref
parente37d6e4c86bad93161edcc5f52594e6d26662eda (diff)
downloademacs-4182ecfc37b3cf6051321ae7bef4e8a4dce1f94b.tar.gz
emacs-4182ecfc37b3cf6051321ae7bef4e8a4dce1f94b.zip
(Integer Basics): Clarify radix explanation.
(Predicates on Numbers): Minor clarification. (Comparison of Numbers): Minor clarification. Clarify eql. Typos in min, max. (Math Functions): Clarify overflow in expt.
Diffstat (limited to 'lispref')
-rw-r--r--lispref/numbers.texi62
1 files changed, 34 insertions, 28 deletions
diff --git a/lispref/numbers.texi b/lispref/numbers.texi
index 53435da081b..776251e4933 100644
--- a/lispref/numbers.texi
+++ b/lispref/numbers.texi
@@ -73,14 +73,21 @@ initial sign and optional final period.
73@cindex hex numbers 73@cindex hex numbers
74@cindex octal numbers 74@cindex octal numbers
75@cindex reading numbers in hex, octal, and binary 75@cindex reading numbers in hex, octal, and binary
76 In addition, the Lisp reader recognizes a syntax for integers in 76 The syntax for integers in bases other than 10 uses @samp{#}
77bases other than 10: @samp{#B@var{integer}} reads @var{integer} in 77followed by a letter that specifies the radix: @samp{b} for binary,
78binary (radix 2), @samp{#O@var{integer}} reads @var{integer} in octal 78@samp{o} for octal, @samp{x} for hex, or @samp{@var{radix}r} to
79(radix 8), @samp{#X@var{integer}} reads @var{integer} in hexadecimal 79specify radix @var{radix}. Case is not significant for the letter
80(radix 16), and @samp{#@var{radix}r@var{integer}} reads @var{integer} 80that specifies the radix. Thus, @samp{#b@var{integer}} reads
81in radix @var{radix} (where @var{radix} is between 2 and 36, 81@var{integer} in binary, and @samp{#@var{radix}r@var{integer}} reads
82inclusively). Case is not significant for the letter after @samp{#} 82@var{integer} in radix @var{radix}. Allowed values of @var{radix} run
83(@samp{B}, @samp{O}, etc.) that denotes the radix. 83from 2 to 36. For example:
84
85@example
86#b101100 @result{} 44
87#o54 @result{} 44
88#x2c @result{} 44
89#24r1k @result{} 44
90@end example
84 91
85 To understand how various functions work on integers, especially the 92 To understand how various functions work on integers, especially the
86bitwise operators (@pxref{Bitwise Operations}), it is often helpful to 93bitwise operators (@pxref{Bitwise Operations}), it is often helpful to
@@ -211,13 +218,12 @@ down to an integer.
211@node Predicates on Numbers 218@node Predicates on Numbers
212@section Type Predicates for Numbers 219@section Type Predicates for Numbers
213 220
214 The functions in this section test whether the argument is a number or 221 The functions in this section test for numbers, or for a specific
215whether it is a certain sort of number. The functions @code{integerp} 222type of number. The functions @code{integerp} and @code{floatp} can
216and @code{floatp} can take any type of Lisp object as argument (the 223take any type of Lisp object as argument (they would not be of much
217predicates would not be of much use otherwise); but the @code{zerop} 224use otherwise), but the @code{zerop} predicate requires a number as
218predicate requires a number as its argument. See also 225its argument. See also @code{integer-or-marker-p} and
219@code{integer-or-marker-p} and @code{number-or-marker-p}, in 226@code{number-or-marker-p}, in @ref{Predicates on Markers}.
220@ref{Predicates on Markers}.
221 227
222@defun floatp object 228@defun floatp object
223This predicate tests whether its argument is a floating point 229This predicate tests whether its argument is a floating point
@@ -251,7 +257,7 @@ considered non-negative.
251This predicate tests whether its argument is zero, and returns @code{t} 257This predicate tests whether its argument is zero, and returns @code{t}
252if so, @code{nil} otherwise. The argument must be a number. 258if so, @code{nil} otherwise. The argument must be a number.
253 259
254These two forms are equivalent: @code{(zerop x)} @equiv{} @code{(= x 0)}. 260@code{(zerop x)} is equivalent to @code{(= x 0)}.
255@end defun 261@end defun
256 262
257@node Comparison of Numbers 263@node Comparison of Numbers
@@ -275,10 +281,11 @@ numbers or markers. However, it is a good idea to use @code{=} if you
275can, even for comparing integers, just in case we change the 281can, even for comparing integers, just in case we change the
276representation of integers in a future Emacs version. 282representation of integers in a future Emacs version.
277 283
278 Sometimes it is useful to compare numbers with @code{equal}; it treats 284 Sometimes it is useful to compare numbers with @code{equal}; it
279two numbers as equal if they have the same data type (both integers, or 285treats two numbers as equal if they have the same data type (both
280both floating point) and the same value. By contrast, @code{=} can 286integers, or both floating point) and the same value. By contrast,
281treat an integer and a floating point number as equal. 287@code{=} can treat an integer and a floating point number as equal.
288@xref{Equality Predicates}.
282 289
283 There is another wrinkle: because floating point arithmetic is not 290 There is another wrinkle: because floating point arithmetic is not
284exact, it is often a bad idea to check for equality of two floating 291exact, it is often a bad idea to check for equality of two floating
@@ -309,10 +316,10 @@ returns @code{t} if so, @code{nil} otherwise.
309@end defun 316@end defun
310 317
311@defun eql value1 value2 318@defun eql value1 value2
312This function compares two floating point numbers like @code{=}, and 319This function acts like @code{eq} except when both arguments are
313compares two integers like @code{=}, and acts like @code{eq} in all 320numbers. It compares numbers by type and numberic value, so that
314other cases. Thus, @code{(eql 1.0 1)} returns @code{nil}, but 321@code{(eql 1.0 1)} returns @code{nil}, but @code{(eql 1.0 1.0)} and
315@code{(eql 1.0 1.0)} and @code{(eql 1 1)} both return @code{t}. 322@code{(eql 1 1)} both return @code{t}.
316@end defun 323@end defun
317 324
318@defun /= number-or-marker1 number-or-marker2 325@defun /= number-or-marker1 number-or-marker2
@@ -345,7 +352,7 @@ otherwise.
345 352
346@defun max number-or-marker &rest numbers-or-markers 353@defun max number-or-marker &rest numbers-or-markers
347This function returns the largest of its arguments. 354This function returns the largest of its arguments.
348If any of the argument is floating-point, the value is returned 355If any of the arguments is floating-point, the value is returned
349as floating point, even if it was given as an integer. 356as floating point, even if it was given as an integer.
350 357
351@example 358@example
@@ -360,7 +367,7 @@ as floating point, even if it was given as an integer.
360 367
361@defun min number-or-marker &rest numbers-or-markers 368@defun min number-or-marker &rest numbers-or-markers
362This function returns the smallest of its arguments. 369This function returns the smallest of its arguments.
363If any of the argument is floating-point, the value is returned 370If any of the arguments is floating-point, the value is returned
364as floating point, even if it was given as an integer. 371as floating point, even if it was given as an integer.
365 372
366@example 373@example
@@ -1147,8 +1154,7 @@ approximately.
1147@defun expt x y 1154@defun expt x y
1148This function returns @var{x} raised to power @var{y}. If both 1155This function returns @var{x} raised to power @var{y}. If both
1149arguments are integers and @var{y} is positive, the result is an 1156arguments are integers and @var{y} is positive, the result is an
1150integer; in this case, it is truncated to fit the range of possible 1157integer; in this case, overflow causes truncation, so watch out.
1151integer values.
1152@end defun 1158@end defun
1153 1159
1154@defun sqrt arg 1160@defun sqrt arg