diff options
| author | Richard M. Stallman | 2005-02-14 10:19:36 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 2005-02-14 10:19:36 +0000 |
| commit | 4182ecfc37b3cf6051321ae7bef4e8a4dce1f94b (patch) | |
| tree | ec17308c959bc88438f1af0a54120554cdba214e | |
| parent | e37d6e4c86bad93161edcc5f52594e6d26662eda (diff) | |
| download | emacs-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.
| -rw-r--r-- | lispref/numbers.texi | 62 |
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{#} |
| 77 | bases other than 10: @samp{#B@var{integer}} reads @var{integer} in | 77 | followed by a letter that specifies the radix: @samp{b} for binary, |
| 78 | binary (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 | 79 | specify radix @var{radix}. Case is not significant for the letter |
| 80 | (radix 16), and @samp{#@var{radix}r@var{integer}} reads @var{integer} | 80 | that specifies the radix. Thus, @samp{#b@var{integer}} reads |
| 81 | in radix @var{radix} (where @var{radix} is between 2 and 36, | 81 | @var{integer} in binary, and @samp{#@var{radix}r@var{integer}} reads |
| 82 | inclusively). 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. | 83 | from 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 |
| 86 | bitwise operators (@pxref{Bitwise Operations}), it is often helpful to | 93 | bitwise 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 |
| 215 | whether it is a certain sort of number. The functions @code{integerp} | 222 | type of number. The functions @code{integerp} and @code{floatp} can |
| 216 | and @code{floatp} can take any type of Lisp object as argument (the | 223 | take any type of Lisp object as argument (they would not be of much |
| 217 | predicates would not be of much use otherwise); but the @code{zerop} | 224 | use otherwise), but the @code{zerop} predicate requires a number as |
| 218 | predicate requires a number as its argument. See also | 225 | its 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 |
| 223 | This predicate tests whether its argument is a floating point | 229 | This predicate tests whether its argument is a floating point |
| @@ -251,7 +257,7 @@ considered non-negative. | |||
| 251 | This predicate tests whether its argument is zero, and returns @code{t} | 257 | This predicate tests whether its argument is zero, and returns @code{t} |
| 252 | if so, @code{nil} otherwise. The argument must be a number. | 258 | if so, @code{nil} otherwise. The argument must be a number. |
| 253 | 259 | ||
| 254 | These 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 | |||
| 275 | can, even for comparing integers, just in case we change the | 281 | can, even for comparing integers, just in case we change the |
| 276 | representation of integers in a future Emacs version. | 282 | representation 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 |
| 279 | two numbers as equal if they have the same data type (both integers, or | 285 | treats two numbers as equal if they have the same data type (both |
| 280 | both floating point) and the same value. By contrast, @code{=} can | 286 | integers, or both floating point) and the same value. By contrast, |
| 281 | treat 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 |
| 284 | exact, it is often a bad idea to check for equality of two floating | 291 | exact, 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 |
| 312 | This function compares two floating point numbers like @code{=}, and | 319 | This function acts like @code{eq} except when both arguments are |
| 313 | compares two integers like @code{=}, and acts like @code{eq} in all | 320 | numbers. It compares numbers by type and numberic value, so that |
| 314 | other 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 |
| 347 | This function returns the largest of its arguments. | 354 | This function returns the largest of its arguments. |
| 348 | If any of the argument is floating-point, the value is returned | 355 | If any of the arguments is floating-point, the value is returned |
| 349 | as floating point, even if it was given as an integer. | 356 | as 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 |
| 362 | This function returns the smallest of its arguments. | 369 | This function returns the smallest of its arguments. |
| 363 | If any of the argument is floating-point, the value is returned | 370 | If any of the arguments is floating-point, the value is returned |
| 364 | as floating point, even if it was given as an integer. | 371 | as 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 |
| 1148 | This function returns @var{x} raised to power @var{y}. If both | 1155 | This function returns @var{x} raised to power @var{y}. If both |
| 1149 | arguments are integers and @var{y} is positive, the result is an | 1156 | arguments are integers and @var{y} is positive, the result is an |
| 1150 | integer; in this case, it is truncated to fit the range of possible | 1157 | integer; in this case, overflow causes truncation, so watch out. |
| 1151 | integer values. | ||
| 1152 | @end defun | 1158 | @end defun |
| 1153 | 1159 | ||
| 1154 | @defun sqrt arg | 1160 | @defun sqrt arg |