73 |
@cindex hex numbers |
@cindex hex numbers |
74 |
@cindex octal numbers |
@cindex octal numbers |
75 |
@cindex reading numbers in hex, octal, and binary |
@cindex reading numbers in hex, octal, and binary |
76 |
In addition, the Lisp reader recognizes a syntax for integers in |
The syntax for integers in bases other than 10 uses @samp{#} |
77 |
bases other than 10: @samp{#B@var{integer}} reads @var{integer} in |
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 |
@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 |
specify radix @var{radix}. Case is not significant for the letter |
80 |
(radix 16), and @samp{#@var{radix}r@var{integer}} reads @var{integer} |
that specifies the radix. Thus, @samp{#b@var{integer}} reads |
81 |
in radix @var{radix} (where @var{radix} is between 2 and 36, |
@var{integer} in binary, and @samp{#@var{radix}r@var{integer}} reads |
82 |
inclusively). Case is not significant for the letter after @samp{#} |
@var{integer} in radix @var{radix}. Allowed values of @var{radix} run |
83 |
(@samp{B}, @samp{O}, etc.) that denotes the radix. |
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 |
91 |
|
|
92 |
To understand how various functions work on integers, especially the |
To understand how various functions work on integers, especially the |
93 |
bitwise operators (@pxref{Bitwise Operations}), it is often helpful to |
bitwise operators (@pxref{Bitwise Operations}), it is often helpful to |
218 |
@node Predicates on Numbers |
@node Predicates on Numbers |
219 |
@section Type Predicates for Numbers |
@section Type Predicates for Numbers |
220 |
|
|
221 |
The functions in this section test whether the argument is a number or |
The functions in this section test for numbers, or for a specific |
222 |
whether it is a certain sort of number. The functions @code{integerp} |
type of number. The functions @code{integerp} and @code{floatp} can |
223 |
and @code{floatp} can take any type of Lisp object as argument (the |
take any type of Lisp object as argument (they would not be of much |
224 |
predicates would not be of much use otherwise); but the @code{zerop} |
use otherwise), but the @code{zerop} predicate requires a number as |
225 |
predicate requires a number as its argument. See also |
its argument. See also @code{integer-or-marker-p} and |
226 |
@code{integer-or-marker-p} and @code{number-or-marker-p}, in |
@code{number-or-marker-p}, in @ref{Predicates on Markers}. |
|
@ref{Predicates on Markers}. |
|
227 |
|
|
228 |
@defun floatp object |
@defun floatp object |
229 |
This predicate tests whether its argument is a floating point |
This predicate tests whether its argument is a floating point |
257 |
This predicate tests whether its argument is zero, and returns @code{t} |
This predicate tests whether its argument is zero, and returns @code{t} |
258 |
if so, @code{nil} otherwise. The argument must be a number. |
if so, @code{nil} otherwise. The argument must be a number. |
259 |
|
|
260 |
These two forms are equivalent: @code{(zerop x)} @equiv{} @code{(= x 0)}. |
@code{(zerop x)} is equivalent to @code{(= x 0)}. |
261 |
@end defun |
@end defun |
262 |
|
|
263 |
@node Comparison of Numbers |
@node Comparison of Numbers |
281 |
can, even for comparing integers, just in case we change the |
can, even for comparing integers, just in case we change the |
282 |
representation of integers in a future Emacs version. |
representation of integers in a future Emacs version. |
283 |
|
|
284 |
Sometimes it is useful to compare numbers with @code{equal}; it treats |
Sometimes it is useful to compare numbers with @code{equal}; it |
285 |
two numbers as equal if they have the same data type (both integers, or |
treats two numbers as equal if they have the same data type (both |
286 |
both floating point) and the same value. By contrast, @code{=} can |
integers, or both floating point) and the same value. By contrast, |
287 |
treat an integer and a floating point number as equal. |
@code{=} can treat an integer and a floating point number as equal. |
288 |
|
@xref{Equality Predicates}. |
289 |
|
|
290 |
There is another wrinkle: because floating point arithmetic is not |
There is another wrinkle: because floating point arithmetic is not |
291 |
exact, it is often a bad idea to check for equality of two floating |
exact, it is often a bad idea to check for equality of two floating |
316 |
@end defun |
@end defun |
317 |
|
|
318 |
@defun eql value1 value2 |
@defun eql value1 value2 |
319 |
This function compares two floating point numbers like @code{=}, and |
This function acts like @code{eq} except when both arguments are |
320 |
compares two integers like @code{=}, and acts like @code{eq} in all |
numbers. It compares numbers by type and numberic value, so that |
321 |
other cases. Thus, @code{(eql 1.0 1)} returns @code{nil}, but |
@code{(eql 1.0 1)} returns @code{nil}, but @code{(eql 1.0 1.0)} and |
322 |
@code{(eql 1.0 1.0)} and @code{(eql 1 1)} both return @code{t}. |
@code{(eql 1 1)} both return @code{t}. |
323 |
@end defun |
@end defun |
324 |
|
|
325 |
@defun /= number-or-marker1 number-or-marker2 |
@defun /= number-or-marker1 number-or-marker2 |
352 |
|
|
353 |
@defun max number-or-marker &rest numbers-or-markers |
@defun max number-or-marker &rest numbers-or-markers |
354 |
This function returns the largest of its arguments. |
This function returns the largest of its arguments. |
355 |
If any of the argument is floating-point, the value is returned |
If any of the arguments is floating-point, the value is returned |
356 |
as floating point, even if it was given as an integer. |
as floating point, even if it was given as an integer. |
357 |
|
|
358 |
@example |
@example |
367 |
|
|
368 |
@defun min number-or-marker &rest numbers-or-markers |
@defun min number-or-marker &rest numbers-or-markers |
369 |
This function returns the smallest of its arguments. |
This function returns the smallest of its arguments. |
370 |
If any of the argument is floating-point, the value is returned |
If any of the arguments is floating-point, the value is returned |
371 |
as floating point, even if it was given as an integer. |
as floating point, even if it was given as an integer. |
372 |
|
|
373 |
@example |
@example |
1154 |
@defun expt x y |
@defun expt x y |
1155 |
This function returns @var{x} raised to power @var{y}. If both |
This function returns @var{x} raised to power @var{y}. If both |
1156 |
arguments are integers and @var{y} is positive, the result is an |
arguments are integers and @var{y} is positive, the result is an |
1157 |
integer; in this case, it is truncated to fit the range of possible |
integer; in this case, overflow causes truncation, so watch out. |
|
integer values. |
|
1158 |
@end defun |
@end defun |
1159 |
|
|
1160 |
@defun sqrt arg |
@defun sqrt arg |