@c -*-texinfo-*-
@c This is part of the GNU Emacs Lisp Reference Manual.
-@c Copyright (C) 1990-1995, 1998-1999, 2001-2011
-@c Free Software Foundation, Inc.
+@c Copyright (C) 1990-1995, 1998-1999, 2001-2013 Free Software
+@c Foundation, Inc.
@c See the file elisp.texi for copying conditions.
-@setfilename ../../info/numbers
-@node Numbers, Strings and Characters, Lisp Data Types, Top
+@node Numbers
@chapter Numbers
@cindex integers
@cindex numbers
@end menu
@node Integer Basics
-@comment node-name, next, previous, up
@section Integer Basics
The range of values for an integer depends on the machine. The
@end tex
to
@ifnottex
-2**29 - 1),
+2**29 @minus{} 1),
@end ifnottex
@tex
@math{2^{29}-1}),
@end tex
-but some machines may provide a wider range. Many examples in this
-chapter assume an integer has 30 bits.
+but many machines provide a wider range. Many examples in this
+chapter assume the minimum integer width of 30 bits.
@cindex overflow
The Lisp reader reads an integer as a sequence of digits with optional
-initial sign and optional final period.
+initial sign and optional final period. An integer that is out of the
+Emacs range is treated as a floating-point number.
@example
1 ; @r{The integer 1.}
1. ; @r{The integer 1.}
+1 ; @r{Also the integer 1.}
-1 ; @r{The integer @minus{}1.}
- 1073741825 ; @r{Also the integer 1, due to overflow.}
+ 1073741825 ; @r{The floating point number 1073741825.0.}
0 ; @r{The integer 0.}
-0 ; @r{The integer 0.}
@end example
In 30-bit binary, the decimal integer 5 looks like this:
@example
-00 0000 0000 0000 0000 0000 0000 0101
+0000...000101 (30 bits total)
@end example
@noindent
-(We have inserted spaces between groups of 4 bits, and two spaces
-between groups of 8 bits, to make the binary integer easier to read.)
+(The @samp{...} stands for enough bits to fill out a 30-bit word; in
+this case, @samp{...} stands for twenty 0 bits. Later examples also
+use the @samp{...} notation to make binary integers easier to read.)
The integer @minus{}1 looks like this:
@example
-11 1111 1111 1111 1111 1111 1111 1111
+1111...111111 (30 bits total)
@end example
@noindent
@minus{}5 looks like this:
@example
-11 1111 1111 1111 1111 1111 1111 1011
+1111...111011 (30 bits total)
@end example
In this implementation, the largest 30-bit binary integer value is
536,870,911 in decimal. In binary, it looks like this:
@example
-01 1111 1111 1111 1111 1111 1111 1111
+0111...111111 (30 bits total)
@end example
Since the arithmetic functions do not check whether integers go
@example
(+ 1 536870911)
@result{} -536870912
- @result{} 10 0000 0000 0000 0000 0000 0000 0000
+ @result{} 1000...000000 (30 bits total)
@end example
Many of the functions described in this chapter accept markers for
give these arguments the name @var{number-or-marker}. When the argument
value is a marker, its position value is used and its buffer is ignored.
+@cindex largest Lisp integer number
+@cindex maximum Lisp integer number
@defvar most-positive-fixnum
The value of this variable is the largest integer that Emacs Lisp
can handle.
@end defvar
+@cindex smallest Lisp integer number
+@cindex minimum Lisp integer number
@defvar most-negative-fixnum
The value of this variable is the smallest integer that Emacs Lisp can
handle. It is negative.
@end defvar
- @xref{Character Codes, max-char}, for the maximum value of a valid
-character codepoint.
+ In Emacs Lisp, text characters are represented by integers. Any
+integer between zero and the value of @code{max-char}, inclusive, is
+considered to be valid as a character. @xref{String Basics}.
@node Float Basics
@section Floating Point Basics
+@cindex @acronym{IEEE} floating point
Floating point numbers are useful for representing numbers that are
not integral. The precise range of floating point numbers is
machine-specific; it is the same as the range of the C data type
-@code{double} on the machine you are using.
+@code{double} on the machine you are using. Emacs uses the
+@acronym{IEEE} floating point standard, which is supported by all
+modern computers.
- The read-syntax for floating point numbers requires either a decimal
+ The read syntax for floating point numbers requires either a decimal
point (with at least one digit following), an exponent, or both. For
example, @samp{1500.0}, @samp{15e2}, @samp{15.0e2}, @samp{1.5e3}, and
@samp{.15e4} are five ways of writing a floating point number whose
-value is 1500. They are all equivalent. You can also use a minus sign
-to write negative floating point numbers, as in @samp{-1.0}.
+value is 1500. They are all equivalent. You can also use a minus
+sign to write negative floating point numbers, as in @samp{-1.0}.
+
+ Emacs Lisp treats @code{-0.0} as equal to ordinary zero (with
+respect to @code{equal} and @code{=}), even though the two are
+distinguishable in the @acronym{IEEE} floating point standard.
-@cindex @acronym{IEEE} floating point
@cindex positive infinity
@cindex negative infinity
@cindex infinity
@cindex NaN
- Most modern computers support the @acronym{IEEE} floating point standard,
-which provides for positive infinity and negative infinity as floating point
-values. It also provides for a class of values called NaN or
-``not-a-number''; numerical functions return such values in cases where
-there is no correct answer. For example, @code{(/ 0.0 0.0)} returns a
-NaN. For practical purposes, there's no significant difference between
-different NaN values in Emacs Lisp, and there's no rule for precisely
-which NaN value should be used in a particular case, so Emacs Lisp
-doesn't try to distinguish them (but it does report the sign, if you
-print it). Here are the read syntaxes for these special floating
-point values:
+ The @acronym{IEEE} floating point standard supports positive
+infinity and negative infinity as floating point values. It also
+provides for a class of values called NaN or ``not-a-number'';
+numerical functions return such values in cases where there is no
+correct answer. For example, @code{(/ 0.0 0.0)} returns a NaN@. (NaN
+values can also carry a sign, but for practical purposes there's no
+significant difference between different NaN values in Emacs Lisp.)
+
+When a function is documented to return a NaN, it returns an
+implementation-defined value when Emacs is running on one of the
+now-rare platforms that do not use @acronym{IEEE} floating point. For
+example, @code{(log -1.0)} typically returns a NaN, but on
+non-@acronym{IEEE} platforms it returns an implementation-defined
+value.
+
+Here are the read syntaxes for these special floating point values:
@table @asis
@item positive infinity
@samp{1.0e+INF}
@item negative infinity
@samp{-1.0e+INF}
-@item Not-a-number
+@item Not-a-number
@samp{0.0e+NaN} or @samp{-0.0e+NaN}.
@end table
- To test whether a floating point value is a NaN, compare it with
-itself using @code{=}. That returns @code{nil} for a NaN, and
-@code{t} for any other floating point value.
+@defun isnan number
+This predicate tests whether its argument is NaN, and returns @code{t}
+if so, @code{nil} otherwise. The argument must be a number.
+@end defun
+
+ The following functions are specialized for handling floating point
+numbers:
+
+@defun frexp x
+This function returns a cons cell @code{(@var{sig} . @var{exp})},
+where @var{sig} and @var{exp} are respectively the significand and
+exponent of the floating point number @var{x}:
+
+@smallexample
+@var{x} = @var{sig} * 2^@var{exp}
+@end smallexample
+
+@var{sig} is a floating point number between 0.5 (inclusive) and 1.0
+(exclusive). If @var{x} is zero, the return value is @code{(0 . 0)}.
+@end defun
- The value @code{-0.0} is distinguishable from ordinary zero in
-@acronym{IEEE} floating point, but Emacs Lisp @code{equal} and
-@code{=} consider them equal values.
+@defun ldexp sig &optional exp
+This function returns a floating point number corresponding to the
+significand @var{sig} and exponent @var{exp}.
+@end defun
- You can use @code{logb} to extract the binary exponent of a floating
-point number (or estimate the logarithm of an integer):
+@defun copysign x1 x2
+This function copies the sign of @var{x2} to the value of @var{x1},
+and returns the result. @var{x1} and @var{x2} must be floating point
+numbers.
+@end defun
@defun logb number
This function returns the binary exponent of @var{number}. More
-precisely, the value is the logarithm of @var{number} base 2, rounded
+precisely, the value is the logarithm of |@var{number}| base 2, rounded
down to an integer.
@example
@end example
@end defun
-@defvar float-e
-The mathematical constant @math{e} (2.71828@dots{}).
-@end defvar
-
-@defvar float-pi
-The mathematical constant @math{pi} (3.14159@dots{}).
-@end defvar
-
@node Predicates on Numbers
@section Type Predicates for Numbers
@cindex predicates for numbers
@defun floatp object
This predicate tests whether its argument is a floating point
number and returns @code{t} if so, @code{nil} otherwise.
-
-@code{floatp} does not exist in Emacs versions 18 and earlier.
@end defun
@defun integerp object
floating point), and returns @code{t} if so, @code{nil} otherwise.
@end defun
-@defun wholenump object
+@defun natnump object
@cindex natural numbers
-The @code{wholenump} predicate (whose name comes from the phrase
-``whole-number-p'') tests to see whether its argument is a nonnegative
-integer, and returns @code{t} if so, @code{nil} otherwise. 0 is
-considered non-negative.
+This predicate (whose name comes from the phrase ``natural number'')
+tests to see whether its argument is a nonnegative integer, and
+returns @code{t} if so, @code{nil} otherwise. 0 is considered
+non-negative.
-@findex natnump
-@code{natnump} is an obsolete synonym for @code{wholenump}.
+@findex wholenump number
+This is a synonym for @code{natnump}.
@end defun
@defun zerop number
@emph{object}. By contrast, @code{=} compares only the numeric values
of the objects.
- At present, each integer value has a unique Lisp object in Emacs Lisp.
+ In Emacs Lisp, each integer value is a unique Lisp object.
Therefore, @code{eq} is equivalent to @code{=} where integers are
-concerned. It is sometimes convenient to use @code{eq} for comparing an
-unknown value with an integer, because @code{eq} does not report an
-error if the unknown value is not a number---it accepts arguments of any
-type. By contrast, @code{=} signals an error if the arguments are not
-numbers or markers. However, it is a good idea to use @code{=} if you
-can, even for comparing integers, just in case we change the
-representation of integers in a future Emacs version.
-
- Sometimes it is useful to compare numbers with @code{equal}; it
+concerned. It is sometimes convenient to use @code{eq} for comparing
+an unknown value with an integer, because @code{eq} does not report an
+error if the unknown value is not a number---it accepts arguments of
+any type. By contrast, @code{=} signals an error if the arguments are
+not numbers or markers. However, it is better programming practice to
+use @code{=} if you can, even for comparing integers.
+
+ Sometimes it is useful to compare numbers with @code{equal}, which
treats two numbers as equal if they have the same data type (both
integers, or both floating point) and the same value. By contrast,
@code{=} can treat an integer and a floating point number as equal.
it unchanged.
@end defun
-There are four functions to convert floating point numbers to integers;
-they differ in how they round. All accept an argument @var{number}
-and an optional argument @var{divisor}. Both arguments may be
-integers or floating point numbers. @var{divisor} may also be
+ There are four functions to convert floating point numbers to
+integers; they differ in how they round. All accept an argument
+@var{number} and an optional argument @var{divisor}. Both arguments
+may be integers or floating point numbers. @var{divisor} may also be
@code{nil}. If @var{divisor} is @code{nil} or omitted, these
functions convert @var{number} to an integer, or return it unchanged
if it already is an integer. If @var{divisor} is non-@code{nil}, they
divide @var{number} by @var{divisor} and convert the result to an
-integer. An @code{arith-error} results if @var{divisor} is 0.
+integer. integer. If @var{divisor} is zero (whether integer or
+floating-point), Emacs signals an @code{arith-error} error.
@defun truncate number &optional divisor
This returns @var{number}, converted to an integer by rounding towards
@section Arithmetic Operations
@cindex arithmetic operations
- Emacs Lisp provides the traditional four arithmetic operations:
-addition, subtraction, multiplication, and division. Remainder and modulus
-functions supplement the division functions. The functions to
-add or subtract 1 are provided because they are traditional in Lisp and
-commonly used.
-
- All of these functions except @code{%} return a floating point value
-if any argument is floating.
+ Emacs Lisp provides the traditional four arithmetic operations
+(addition, subtraction, multiplication, and division), as well as
+remainder and modulus functions, and functions to add or subtract 1.
+Except for @code{%}, each of these functions accepts both integer and
+floating point arguments, and returns a floating point number if any
+argument is a floating point number.
It is important to note that in Emacs Lisp, arithmetic functions
-do not check for overflow. Thus @code{(1+ 268435455)} may evaluate to
-@minus{}268435456, depending on your hardware.
+do not check for overflow. Thus @code{(1+ 536870911)} may evaluate to
+@minus{}536870912, depending on your hardware.
@defun 1+ number-or-marker
This function returns @var{number-or-marker} plus 1.
divides @var{dividend} by each divisor in turn. Each argument may be a
number or a marker.
-If all the arguments are integers, then the result is an integer too.
-This means the result has to be rounded. On most machines, the result
-is rounded towards zero after each division, but some machines may round
-differently with negative arguments. This is because the Lisp function
-@code{/} is implemented using the C division operator, which also
-permits machine-dependent rounding. As a practical matter, all known
-machines round in the standard fashion.
-
-@cindex @code{arith-error} in division
-If you divide an integer by 0, an @code{arith-error} error is signaled.
-(@xref{Errors}.) Floating point division by zero returns either
-infinity or a NaN if your machine supports @acronym{IEEE} floating point;
-otherwise, it signals an @code{arith-error} error.
+If all the arguments are integers, the result is an integer, obtained
+by rounding the quotient towards zero after each division.
+(Hypothetically, some machines may have different rounding behavior
+for negative arguments, because @code{/} is implemented using the C
+division operator, which permits machine-dependent rounding; but this
+does not happen in practice.)
@example
@group
(/ 6 2)
@result{} 3
@end group
+@group
(/ 5 2)
@result{} 2
+@end group
+@group
(/ 5.0 2)
@result{} 2.5
+@end group
+@group
(/ 5 2.0)
@result{} 2.5
+@end group
+@group
(/ 5.0 2.0)
@result{} 2.5
+@end group
+@group
(/ 25 3 2)
@result{} 4
+@end group
@group
(/ -17 6)
- @result{} -2 @r{(could in theory be @minus{}3 on some machines)}
+ @result{} -2
@end group
@end example
+
+@cindex @code{arith-error} in division
+If you divide an integer by the integer 0, Emacs signals an
+@code{arith-error} error (@pxref{Errors}). If you divide a floating
+point number by 0, or divide by the floating point number 0.0, the
+result is either positive or negative infinity (@pxref{Float Basics}).
@end defun
@defun % dividend divisor
This function returns the integer remainder after division of @var{dividend}
by @var{divisor}. The arguments must be integers or markers.
-For negative arguments, the remainder is in principle machine-dependent
-since the quotient is; but in practice, all known machines behave alike.
+For any two integers @var{dividend} and @var{divisor},
-An @code{arith-error} results if @var{divisor} is 0.
+@example
+@group
+(+ (% @var{dividend} @var{divisor})
+ (* (/ @var{dividend} @var{divisor}) @var{divisor}))
+@end group
+@end example
+
+@noindent
+always equals @var{dividend}. If @var{divisor} is zero, Emacs signals
+an @code{arith-error} error.
@example
(% 9 4)
(% -9 -4)
@result{} -1
@end example
-
-For any two integers @var{dividend} and @var{divisor},
-
-@example
-@group
-(+ (% @var{dividend} @var{divisor})
- (* (/ @var{dividend} @var{divisor}) @var{divisor}))
-@end group
-@end example
-
-@noindent
-always equals @var{dividend}.
@end defun
@defun mod dividend divisor
by @var{divisor}, but with the same sign as @var{divisor}.
The arguments must be numbers or markers.
-Unlike @code{%}, @code{mod} returns a well-defined result for negative
-arguments. It also permits floating point arguments; it rounds the
-quotient downward (towards minus infinity) to an integer, and uses that
-quotient to compute the remainder.
+Unlike @code{%}, @code{mod} permits floating point arguments; it
+rounds the quotient downward (towards minus infinity) to an integer,
+and uses that quotient to compute the remainder.
-An @code{arith-error} results if @var{divisor} is 0.
+If @var{divisor} is zero, @code{mod} signals an @code{arith-error}
+error if both arguments are integers, and returns a NaN otherwise.
@example
@group
sequence of @dfn{bits} (digits which are either zero or one). A bitwise
operation acts on the individual bits of such a sequence. For example,
@dfn{shifting} moves the whole sequence left or right one or more places,
-reproducing the same pattern ``moved over.''
+reproducing the same pattern ``moved over''.
The bitwise operations in Emacs Lisp apply only to integers.
The function @code{lsh}, like all Emacs Lisp arithmetic functions, does
not check for overflow, so shifting left can discard significant bits
and change the sign of the number. For example, left shifting
-536,870,911 produces @minus{}2 on a 30-bit machine:
+536,870,911 produces @minus{}2 in the 30-bit implementation:
@example
(lsh 536870911 1) ; @r{left shift}
@result{} -2
@end example
-In binary, in the 30-bit implementation, the argument looks like this:
+In binary, the argument looks like this:
@example
@group
;; @r{Decimal 536,870,911}
-01 1111 1111 1111 1111 1111 1111 1111
+0111...111111 (30 bits total)
@end group
@end example
@example
@group
;; @r{Decimal @minus{}2}
-11 1111 1111 1111 1111 1111 1111 1110
+1111...111110 (30 bits total)
@end group
@end example
@end defun
@group
(ash -6 -1) @result{} -3
;; @r{Decimal @minus{}6 becomes decimal @minus{}3.}
-11 1111 1111 1111 1111 1111 1111 1010
+1111...111010 (30 bits total)
@result{}
-11 1111 1111 1111 1111 1111 1111 1101
+1111...111101 (30 bits total)
@end group
@end example
@group
(lsh -6 -1) @result{} 536870909
;; @r{Decimal @minus{}6 becomes decimal 536,870,909.}
-11 1111 1111 1111 1111 1111 1111 1010
+1111...111010 (30 bits total)
@result{}
-01 1111 1111 1111 1111 1111 1111 1101
+0111...111101 (30 bits total)
@end group
@end example
@c with smallbook but not with regular book! --rjc 16mar92
@smallexample
@group
- ; @r{ 30-bit binary values}
+ ; @r{ 30-bit binary values}
-(lsh 5 2) ; 5 = @r{00 0000 0000 0000 0000 0000 0000 0101}
- @result{} 20 ; = @r{00 0000 0000 0000 0000 0000 0001 0100}
+(lsh 5 2) ; 5 = @r{0000...000101}
+ @result{} 20 ; = @r{0000...010100}
@end group
@group
(ash 5 2)
@result{} 20
-(lsh -5 2) ; -5 = @r{11 1111 1111 1111 1111 1111 1111 1011}
- @result{} -20 ; = @r{11 1111 1111 1111 1111 1111 1110 1100}
+(lsh -5 2) ; -5 = @r{1111...111011}
+ @result{} -20 ; = @r{1111...101100}
(ash -5 2)
@result{} -20
@end group
@group
-(lsh 5 -2) ; 5 = @r{00 0000 0000 0000 0000 0000 0000 0101}
- @result{} 1 ; = @r{00 0000 0000 0000 0000 0000 0000 0001}
+(lsh 5 -2) ; 5 = @r{0000...000101}
+ @result{} 1 ; = @r{0000...000001}
@end group
@group
(ash 5 -2)
@result{} 1
@end group
@group
-(lsh -5 -2) ; -5 = @r{11 1111 1111 1111 1111 1111 1111 1011}
- @result{} 268435454 ; = @r{00 0111 1111 1111 1111 1111 1111 1110}
+(lsh -5 -2) ; -5 = @r{1111...111011}
+ @result{} 268435454
+ ; = @r{0011...111110}
@end group
@group
-(ash -5 -2) ; -5 = @r{11 1111 1111 1111 1111 1111 1111 1011}
- @result{} -2 ; = @r{11 1111 1111 1111 1111 1111 1111 1110}
+(ash -5 -2) ; -5 = @r{1111...111011}
+ @result{} -2 ; = @r{1111...111110}
@end group
@end smallexample
@end defun
@smallexample
@group
- ; @r{ 30-bit binary values}
+ ; @r{ 30-bit binary values}
-(logand 14 13) ; 14 = @r{00 0000 0000 0000 0000 0000 0000 1110}
- ; 13 = @r{00 0000 0000 0000 0000 0000 0000 1101}
- @result{} 12 ; 12 = @r{00 0000 0000 0000 0000 0000 0000 1100}
+(logand 14 13) ; 14 = @r{0000...001110}
+ ; 13 = @r{0000...001101}
+ @result{} 12 ; 12 = @r{0000...001100}
@end group
@group
-(logand 14 13 4) ; 14 = @r{00 0000 0000 0000 0000 0000 0000 1110}
- ; 13 = @r{00 0000 0000 0000 0000 0000 0000 1101}
- ; 4 = @r{00 0000 0000 0000 0000 0000 0000 0100}
- @result{} 4 ; 4 = @r{00 0000 0000 0000 0000 0000 0000 0100}
+(logand 14 13 4) ; 14 = @r{0000...001110}
+ ; 13 = @r{0000...001101}
+ ; 4 = @r{0000...000100}
+ @result{} 4 ; 4 = @r{0000...000100}
@end group
@group
(logand)
- @result{} -1 ; -1 = @r{11 1111 1111 1111 1111 1111 1111 1111}
+ @result{} -1 ; -1 = @r{1111...111111}
@end group
@end smallexample
@end defun
@smallexample
@group
- ; @r{ 30-bit binary values}
+ ; @r{ 30-bit binary values}
-(logior 12 5) ; 12 = @r{00 0000 0000 0000 0000 0000 0000 1100}
- ; 5 = @r{00 0000 0000 0000 0000 0000 0000 0101}
- @result{} 13 ; 13 = @r{00 0000 0000 0000 0000 0000 0000 1101}
+(logior 12 5) ; 12 = @r{0000...001100}
+ ; 5 = @r{0000...000101}
+ @result{} 13 ; 13 = @r{0000...001101}
@end group
@group
-(logior 12 5 7) ; 12 = @r{00 0000 0000 0000 0000 0000 0000 1100}
- ; 5 = @r{00 0000 0000 0000 0000 0000 0000 0101}
- ; 7 = @r{00 0000 0000 0000 0000 0000 0000 0111}
- @result{} 15 ; 15 = @r{00 0000 0000 0000 0000 0000 0000 1111}
+(logior 12 5 7) ; 12 = @r{0000...001100}
+ ; 5 = @r{0000...000101}
+ ; 7 = @r{0000...000111}
+ @result{} 15 ; 15 = @r{0000...001111}
@end group
@end smallexample
@end defun
@smallexample
@group
- ; @r{ 30-bit binary values}
+ ; @r{ 30-bit binary values}
-(logxor 12 5) ; 12 = @r{00 0000 0000 0000 0000 0000 0000 1100}
- ; 5 = @r{00 0000 0000 0000 0000 0000 0000 0101}
- @result{} 9 ; 9 = @r{00 0000 0000 0000 0000 0000 0000 1001}
+(logxor 12 5) ; 12 = @r{0000...001100}
+ ; 5 = @r{0000...000101}
+ @result{} 9 ; 9 = @r{0000...001001}
@end group
@group
-(logxor 12 5 7) ; 12 = @r{00 0000 0000 0000 0000 0000 0000 1100}
- ; 5 = @r{00 0000 0000 0000 0000 0000 0000 0101}
- ; 7 = @r{00 0000 0000 0000 0000 0000 0000 0111}
- @result{} 14 ; 14 = @r{00 0000 0000 0000 0000 0000 0000 1110}
+(logxor 12 5 7) ; 12 = @r{0000...001100}
+ ; 5 = @r{0000...000101}
+ ; 7 = @r{0000...000111}
+ @result{} 14 ; 14 = @r{0000...001110}
@end group
@end smallexample
@end defun
@example
(lognot 5)
@result{} -6
-;; 5 = @r{00 0000 0000 0000 0000 0000 0000 0101}
+;; 5 = @r{0000...000101} (30 bits total)
;; @r{becomes}
-;; -6 = @r{11 1111 1111 1111 1111 1111 1111 1010}
+;; -6 = @r{1111...111010} (30 bits total)
@end example
@end defun
@defun sin arg
@defunx cos arg
@defunx tan arg
-These are the ordinary trigonometric functions, with argument measured
-in radians.
+These are the basic trigonometric functions, with argument @var{arg}
+measured in radians.
@end defun
@defun asin arg
@tex
@math{\pi/2}
@end tex
-(inclusive) whose sine is @var{arg}; if, however, @var{arg} is out of
-range (outside [@minus{}1, 1]), it signals a @code{domain-error} error.
+(inclusive) whose sine is @var{arg}. If @var{arg} is out of range
+(outside [@minus{}1, 1]), @code{asin} returns a NaN.
@end defun
@defun acos arg
@tex
@math{\pi}
@end tex
-(inclusive) whose cosine is @var{arg}; if, however, @var{arg} is out
-of range (outside [@minus{}1, 1]), it signals a @code{domain-error} error.
+(inclusive) whose cosine is @var{arg}. If @var{arg} is out of range
+(outside [@minus{}1, 1]), @code{acos} returns a NaN.
@end defun
@defun atan y &optional x
@end defun
@defun exp arg
-This is the exponential function; it returns
-@tex
-@math{e}
-@end tex
-@ifnottex
-@i{e}
-@end ifnottex
-to the power @var{arg}.
-@tex
-@math{e}
-@end tex
-@ifnottex
-@i{e}
-@end ifnottex
-is a fundamental mathematical constant also called the base of natural
-logarithms.
+This is the exponential function; it returns @math{e} to the power
+@var{arg}.
@end defun
@defun log arg &optional base
-This function returns the logarithm of @var{arg}, with base @var{base}.
-If you don't specify @var{base}, the base
-@tex
-@math{e}
-@end tex
-@ifnottex
-@i{e}
-@end ifnottex
-is used. If @var{arg} is negative, it signals a @code{domain-error}
-error.
-@end defun
-
-@ignore
-@defun expm1 arg
-This function returns @code{(1- (exp @var{arg}))}, but it is more
-accurate than that when @var{arg} is negative and @code{(exp @var{arg})}
-is close to 1.
-@end defun
-
-@defun log1p arg
-This function returns @code{(log (1+ @var{arg}))}, but it is more
-accurate than that when @var{arg} is so small that adding 1 to it would
-lose accuracy.
+This function returns the logarithm of @var{arg}, with base
+@var{base}. If you don't specify @var{base}, the natural base
+@math{e} is used. If @var{arg} or @var{base} is negative, @code{log}
+returns a NaN.
@end defun
-@end ignore
@defun log10 arg
-This function returns the logarithm of @var{arg}, with base 10. If
-@var{arg} is negative, it signals a @code{domain-error} error.
-@code{(log10 @var{x})} @equiv{} @code{(log @var{x} 10)}, at least
-approximately.
+This function returns the logarithm of @var{arg}, with base 10:
+@code{(log10 @var{x})} @equiv{} @code{(log @var{x} 10)}.
@end defun
@defun expt x y
This function returns @var{x} raised to power @var{y}. If both
arguments are integers and @var{y} is positive, the result is an
integer; in this case, overflow causes truncation, so watch out.
+If @var{x} is a finite negative number and @var{y} is a finite
+non-integer, @code{expt} returns a NaN.
@end defun
@defun sqrt arg
This returns the square root of @var{arg}. If @var{arg} is negative,
-it signals a @code{domain-error} error.
+@code{sqrt} returns a NaN.
@end defun
+In addition, Emacs defines the following common mathematical
+constants:
+
+@defvar float-e
+The mathematical constant @math{e} (2.71828@dots{}).
+@end defvar
+
+@defvar float-pi
+The mathematical constant @math{pi} (3.14159@dots{}).
+@end defvar
+
@node Random Numbers
@section Random Numbers
@cindex random numbers
-A deterministic computer program cannot generate true random numbers.
-For most purposes, @dfn{pseudo-random numbers} suffice. A series of
-pseudo-random numbers is generated in a deterministic fashion. The
-numbers are not truly random, but they have certain properties that
-mimic a random series. For example, all possible values occur equally
-often in a pseudo-random series.
-
-In Emacs, pseudo-random numbers are generated from a ``seed'' number.
-Starting from any given seed, the @code{random} function always
-generates the same sequence of numbers. Emacs always starts with the
-same seed value, so the sequence of values of @code{random} is actually
-the same in each Emacs run! For example, in one operating system, the
-first call to @code{(random)} after you start Emacs always returns
-@minus{}1457731, and the second one always returns @minus{}7692030. This
-repeatability is helpful for debugging.
-
-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 @acronym{ID} number.
+ A deterministic computer program cannot generate true random
+numbers. For most purposes, @dfn{pseudo-random numbers} suffice. A
+series of pseudo-random numbers is generated in a deterministic
+fashion. The numbers are not truly random, but they have certain
+properties that mimic a random series. For example, all possible
+values occur equally often in a pseudo-random series.
+
+ Pseudo-random numbers are generated from a ``seed''. Starting from
+any given seed, the @code{random} function always generates the same
+sequence of numbers. By default, Emacs initializes the random seed at
+startup, in such a way that the sequence of values of @code{random}
+(with overwhelming likelihood) differs in each Emacs run.
+
+ Sometimes you want the random number sequence to be repeatable. For
+example, when debugging a program whose behavior depends on the random
+number sequence, it is helpful to get the same behavior in each
+program run. To make the sequence repeat, execute @code{(random "")}.
+This sets the seed to a constant value for your particular Emacs
+executable (though it may differ for other Emacs builds). You can use
+other strings to choose various seed values.
@defun random &optional limit
This function returns a pseudo-random integer. Repeated calls return a
series of pseudo-random integers.
If @var{limit} is a positive integer, the value is chosen to be
-nonnegative and less than @var{limit}.
+nonnegative and less than @var{limit}. Otherwise, the value might be
+any integer representable in Lisp, i.e., an integer between
+@code{most-negative-fixnum} and @code{most-positive-fixnum}
+(@pxref{Integer Basics}).
If @var{limit} is @code{t}, it means to choose a new seed based on the
current time of day and on Emacs's process @acronym{ID} number.
-@c "Emacs'" is incorrect usage!
-On some machines, any integer representable in Lisp may be the result
-of @code{random}. On other machines, the result can never be larger
-than a certain maximum or less than a certain (negative) minimum.
+If @var{limit} is a string, it means to choose a new seed based on the
+string's contents.
+
@end defun