@c -*-texinfo-*-
@c This is part of the GNU Emacs Lisp Reference Manual.
-@c Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1998 Free Software Foundation, Inc.
+@c Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1998, 1999
+@c Free Software Foundation, Inc.
@c See the file elisp.texi for copying conditions.
@setfilename ../info/numbers
@node Numbers, Strings and Characters, Lisp Data Types, Top
The range of values for an integer depends on the machine. The
minimum range is @minus{}134217728 to 134217727 (28 bits; i.e.,
-@ifinfo
+@ifnottex
-2**27
-@end ifinfo
+@end ifnottex
@tex
-$-2^{27}$
+@math{-2^{27}}
@end tex
to
-@ifinfo
+@ifnottex
2**27 - 1),
-@end ifinfo
+@end ifnottex
@tex
-$2^{27}-1$),
+@math{2^{27}-1}),
@end tex
but some machines may provide a wider range. Many examples in this
chapter assume an integer has 28 bits.
-0 ; @r{The integer 0.}
@end example
+@cindex integers in specific radix
+@cindex radix for reading an integer
+@cindex base for reading an integer
+ In addition, the Lisp reader recognizes a syntax for integers in
+bases other than 10: @samp{#B@var{integer}} reads @var{integer} in
+binary (radix 2), @samp{#O@var{integer}} reads @var{integer} in octal
+(radix 8), @samp{#X@var{integer}} reads @var{integer} in hexadecimal
+(radix 16), and @samp{#@var{radix}r@var{integer}} reads @var{integer}
+in radix @var{radix} (where @var{radix} is between 2 and 36,
+inclusivley). Case is not significant for the letter after @samp{#}
+(@samp{B}, @samp{O}, etc.) that denotes the radix.
+
To understand how various functions work on integers, especially the
bitwise operators (@pxref{Bitwise Operations}), it is often helpful to
view the numbers in their binary form.
@defun max number-or-marker &rest numbers-or-markers
This function returns the largest of its arguments.
+If any of the argument is floating-point, the value is returned
+as floating point, even if it was given as an integer.
@example
(max 20)
(max 1 2.5)
@result{} 2.5
(max 1 3 2.5)
- @result{} 3
+ @result{} 3.0
@end example
@end defun
@defun min number-or-marker &rest numbers-or-markers
This function returns the smallest of its arguments.
+If any of the argument is floating-point, the value is returned
+as floating point, even if it was given as an integer.
@example
(min -4 1)
@defun truncate number
This returns @var{number}, converted to an integer by rounding towards
zero.
+
+@example
+(truncate 1.2)
+ @result{} 1
+(truncate 1.7)
+ @result{} 1
+(truncate -1.2)
+ @result{} -1
+(truncate -1.7)
+ @result{} -1
+@end example
@end defun
@defun floor number &optional divisor
This returns @var{number}, converted to an integer by rounding downward
(towards negative infinity).
-If @var{divisor} is specified, @var{number} is divided by @var{divisor}
-before the floor is taken; this uses the kind of division operation that
-corresponds to @code{mod}, rounding downward. An @code{arith-error}
-results if @var{divisor} is 0.
+If @var{divisor} is specified, @code{floor} divides @var{number} by
+@var{divisor} and then converts to an integer; this uses the kind of
+division operation that corresponds to @code{mod}, rounding downward.
+An @code{arith-error} results if @var{divisor} is 0.
+
+@example
+(floor 1.2)
+ @result{} 1
+(floor 1.7)
+ @result{} 1
+(floor -1.2)
+ @result{} -2
+(floor -1.7)
+ @result{} -2
+(floor 5.99 3)
+ @result{} 1
+@end example
@end defun
@defun ceiling number
This returns @var{number}, converted to an integer by rounding upward
(towards positive infinity).
+
+@example
+(ceiling 1.2)
+ @result{} 2
+(ceiling 1.7)
+ @result{} 2
+(ceiling -1.2)
+ @result{} -1
+(ceiling -1.7)
+ @result{} -1
+@end example
@end defun
@defun round number
nearest integer. Rounding a value equidistant between two integers
may choose the integer closer to zero, or it may prefer an even integer,
depending on your machine.
+
+@example
+(round 1.2)
+ @result{} 1
+(round 1.7)
+ @result{} 2
+(round -1.2)
+ @result{} -1
+(round -1.7)
+ @result{} -2
+@end example
@end defun
@node Arithmetic Operations
@defun asin arg
The value of @code{(asin @var{arg})} is a number between
-@ifinfo
+@ifnottex
@minus{}pi/2
-@end ifinfo
+@end ifnottex
@tex
-$-\pi/2$
+@math{-\pi/2}
@end tex
and
-@ifinfo
+@ifnottex
pi/2
-@end ifinfo
+@end ifnottex
@tex
-$\pi/2$
+@math{\pi/2}
@end tex
(inclusive) whose sine is @var{arg}; if, however, @var{arg}
is out of range (outside [-1, 1]), then the result is a NaN.
@defun acos arg
The value of @code{(acos @var{arg})} is a number between 0 and
-@ifinfo
+@ifnottex
pi
-@end ifinfo
+@end ifnottex
@tex
-$\pi$
+@math{\pi}
@end tex
(inclusive) whose cosine is @var{arg}; if, however, @var{arg}
is out of range (outside [-1, 1]), then the result is a NaN.
@defun atan arg
The value of @code{(atan @var{arg})} is a number between
-@ifinfo
+@ifnottex
@minus{}pi/2
-@end ifinfo
+@end ifnottex
@tex
-$-\pi/2$
+@math{-\pi/2}
@end tex
and
-@ifinfo
+@ifnottex
pi/2
-@end ifinfo
+@end ifnottex
@tex
-$\pi/2$
+@math{\pi/2}
@end tex
(exclusive) whose tangent is @var{arg}.
@end defun
@defun exp arg
This is the exponential function; it returns
@tex
-$e$
+@math{e}
@end tex
-@ifinfo
+@ifnottex
@i{e}
-@end ifinfo
+@end ifnottex
to the power @var{arg}.
@tex
-$e$
+@math{e}
@end tex
-@ifinfo
+@ifnottex
@i{e}
-@end ifinfo
+@end ifnottex
is a fundamental mathematical constant also called the base of natural
logarithms.
@end defun
This function returns the logarithm of @var{arg}, with base @var{base}.
If you don't specify @var{base}, the base
@tex
-$e$
+@math{e}
@end tex
-@ifinfo
+@ifnottex
@i{e}
-@end ifinfo
+@end ifnottex
is used. If @var{arg}
is negative, the result is a NaN.
@end defun
-1457731, and the second one always returns -7692030. This
repeatability is helpful for debugging.
-If you want truly unpredictable random numbers, execute @code{(random
-t)}. This chooses a new seed based on the current time of day and on
-Emacs's process @sc{id} number.
+If you want random numbers that don't always come out the same, execute
+@code{(random t)}. This chooses a new seed based on the current time of
+day and on Emacs's process @sc{id} number.
@defun random &optional limit
This function returns a pseudo-random integer. Repeated calls return a