(xmenu_show) [USE_X_TOOLKIT]: Keyboard input exits the menu.
ButtonRelease does so if within Vdouble_click_time.
Ignore mouse motion if button was already released.
(menu_item_selection): Declare volatile, if __STDC__.
@c -*-texinfo-*-@c This is part of the GNU Emacs Lisp Reference Manual.@c Copyright (C) 1990, 1991, 1992, 1993, 1994 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@chapter Numbers@cindex integers@cindex numbers GNU Emacs supports two numeric data types: @dfn{integers} and@dfn{floating point numbers}. Integers are whole numbers such as@minus{}3, 0, 7, 13, and 511. Their values are exact. Floating pointnumbers are numbers with fractional parts, such as @minus{}4.5, 0.0, or2.71828. They can also be expressed in exponential notation:1.5e2 equals 150; in this example, @samp{e2} stands for ten to thesecond power, and is multiplied by 1.5. Floating point values are notexact; they have a fixed, limited amount of precision. Support for floating point numbers is a new feature in Emacs 19, and itis controlled by a separate compilation option, so you may encounter a sitewhere Emacs does not support them.@menu* Integer Basics:: Representation and range of integers.* Float Basics:: Representation and range of floating point.* Predicates on Numbers:: Testing for numbers.* Comparison of Numbers:: Equality and inequality predicates.* Numeric Conversions:: Converting float to integer and vice versa.* Arithmetic Operations:: How to add, subtract, multiply and divide.* Rounding Operations:: Explicitly rounding floating point numbers.* Bitwise Operations:: Logical and, or, not, shifting.* Transcendental Functions:: Trig, exponential and logarithmic functions.* Random Numbers:: Obtaining random integers, predictable or not.@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. Therange is @minus{}8388608 to 8388607 (24 bits; i.e.,@ifinfo -2**23@end ifinfo@tex $-2^{23}$ @end texto @ifinfo 2**23 - 1)@end ifinfo@tex $2^{23}-1$)@end texon most machines, but on others it is @minus{}16777216 to 16777215 (25bits), or @minus{}33554432 to 33554431 (26 bits). Many examples in thischapter assume an integer has 24 bits.@cindex overflow The Lisp reader reads an integer as a sequence of digits with optionalinitial sign and optional final period.@example 1 ; @r{The integer 1.} 1. ; @r{The integer 1.}+1 ; @r{Also the integer 1.}-1 ; @r{The integer @minus{}1.} 16777217 ; @r{Also the integer 1, due to overflow.} 0 ; @r{The integer 0.}-0 ; @r{The integer 0.}@end example To understand how various functions work on integers, especially thebitwise operators (@pxref{Bitwise Operations}), it is often helpful toview the numbers in their binary form. In 24-bit binary, the decimal integer 5 looks like this:@example0000 0000 0000 0000 0000 0101@end example@noindent(We have inserted spaces between groups of 4 bits, and two spacesbetween groups of 8 bits, to make the binary integer easier to read.) The integer @minus{}1 looks like this:@example1111 1111 1111 1111 1111 1111@end example@noindent@cindex two's complement@minus{}1 is represented as 24 ones. (This is called @dfn{two'scomplement} notation.) The negative integer, @minus{}5, is creating by subtracting 4 from@minus{}1. In binary, the decimal integer 4 is 100. Consequently,@minus{}5 looks like this:@example1111 1111 1111 1111 1111 1011@end example In this implementation, the largest 24-bit binary integer is thedecimal integer 8,388,607. In binary, it looks like this:@example0111 1111 1111 1111 1111 1111@end example Since the arithmetic functions do not check whether integers gooutside their range, when you add 1 to 8,388,607, the value is thenegative integer @minus{}8,388,608:@example(+ 1 8388607) @result{} -8388608 @result{} 1000 0000 0000 0000 0000 0000@end example Many of the following functions accept markers for arguments as wellas integers. (@xref{Markers}.) More precisely, the actual arguments tosuch functions may be either integers or markers, which is why we oftengive these arguments the name @var{int-or-marker}. When the argumentvalue is a marker, its position value is used and its buffer is ignored.@ignore In version 19, except where @emph{integer} is specified as anargument, all of the functions for markers and integers also work forfloating point numbers.@end ignore@node Float Basics@section Floating Point Basics@cindex @code{LISP_FLOAT_TYPE} configuration macro Emacs version 19 supports floating point numbers, if compiled with themacro @code{LISP_FLOAT_TYPE} defined. The precise range of floatingpoint numbers is machine-specific; it is the same as the range of the Cdata type @code{double} on the machine in question. The printed representation for floating point numbers requires eithera decimal point (with at least one digit following), an exponent, orboth. For example, @samp{1500.0}, @samp{15e2}, @samp{15.0e2},@samp{1.5e3}, and @samp{.15e4} are five ways of writing a floating pointnumber whose value is 1500. They are all equivalent. You can also usea minus sign to write negative floating point numbers, as in@samp{-1.0}.@cindex IEEE floating point@cindex positive infinity@cindex negative infinity@cindex infinity@cindex NaN Most modern computers support the IEEE floating point standard, whichprovides for positive infinity and negative infinity as floating pointvalues. It also provides for a class of values called NaN or``not-a-number''; numerical functions return such values in cases wherethere is no correct answer. For example, @code{(sqrt -1.0)} returns aNaN. For practical purposes, there's no significant difference betweendifferent NaN values in Emacs Lisp, and there's no rule for preciselywhich NaN value should be used in a particular case, so this manualdoesn't try to distinguish them. Emacs Lisp has no read syntax for NaNsor infinities; perhaps we should create a syntax in the future. You can use @code{logb} to extract the binary exponent of a floatingpoint number (or estimate the logarithm of an integer):@defun logb numberThis function returns the binary exponent of @var{number}. Moreprecisely, the value is the logarithm of @var{number} base 2, roundeddown to an integer.@end defun@node Predicates on Numbers@section Type Predicates for Numbers The functions in this section test whether the argument is a number orwhether it is a certain sort of number. The functions @code{integerp}and @code{floatp} can take any type of Lisp object as argument (thepredicates would not be of much use otherwise); but the @code{zerop}predicate requires a number as its argument. See also@code{integer-or-marker-p} and @code{number-or-marker-p}, in@ref{Predicates on Markers}.@defun floatp objectThis predicate tests whether its argument is a floating pointnumber and returns @code{t} if so, @code{nil} otherwise.@code{floatp} does not exist in Emacs versions 18 and earlier.@end defun@defun integerp objectThis predicate tests whether its argument is an integer, and returns@code{t} if so, @code{nil} otherwise.@end defun@defun numberp objectThis predicate tests whether its argument is a number (either integer orfloating point), and returns @code{t} if so, @code{nil} otherwise.@end defun@defun wholenump object@cindex natural numbersThe @code{wholenump} predicate (whose name comes from the phrase``whole-number-p'') tests to see whether its argument is a nonnegativeinteger, and returns @code{t} if so, @code{nil} otherwise. 0 isconsidered non-negative.@findex natnump@code{natnump} is an obsolete synonym for @code{wholenump}.@end defun@defun zerop numberThis predicate tests whether its argument is zero, and returns @code{t}if so, @code{nil} otherwise. The argument must be a number.These two forms are equivalent: @code{(zerop x)} @equiv{} @code{(= x 0)}.@end defun@node Comparison of Numbers@section Comparison of Numbers@cindex number equality To test numbers for numerical equality, you should normally use@code{=}, not @code{eq}. There can be many distinct floating pointnumber objects with the same numeric value. If you use @code{eq} tocompare them, then you test whether two values are the same@emph{object}. By contrast, @code{=} compares only the numeric valuesof the objects. At present, each integer value has a unique Lisp object in Emacs Lisp.Therefore, @code{eq} is equivalent @code{=} where integers areconcerned. It is sometimes convenient to use @code{eq} for comparing anunknown value with an integer, because @code{eq} does not report anerror if the unknown value is not a number---it accepts arguments of anytype. By contrast, @code{=} signals an error if the arguments are notnumbers or markers. However, it is a good idea to use @code{=} if youcan, even for comparing integers, just in case we change therepresentation of integers in a future Emacs version. There is another wrinkle: because floating point arithmetic is notexact, it is often a bad idea to check for equality of two floatingpoint values. Usually it is better to test for approximate equality.Here's a function to do this:@example(defvar fuzz-factor 1.0e-6)(defun approx-equal (x y) (< (/ (abs (- x y)) (max (abs x) (abs y))) fuzz-factor))@end example@cindex CL note---integers vrs @code{eq}@quotation@b{Common Lisp note:} Comparing numbers in Common Lisp always requires@code{=} because Common Lisp implements multi-word integers, and twodistinct integer objects can have the same numeric value. Emacs Lispcan have just one integer object for any given value because it has alimited range of integer values.@end quotation@defun = number-or-marker1 number-or-marker2This function tests whether its arguments are numerically equal, andreturns @code{t} if so, @code{nil} otherwise.@end defun@defun /= number-or-marker1 number-or-marker2This function tests whether its arguments are numerically equal, andreturns @code{t} if they are not, and @code{nil} if they are.@end defun@defun < number-or-marker1 number-or-marker2This function tests whether its first argument is strictly less thanits second argument. It returns @code{t} if so, @code{nil} otherwise.@end defun@defun <= number-or-marker1 number-or-marker2This function tests whether its first argument is less than or equalto its second argument. It returns @code{t} if so, @code{nil}otherwise.@end defun@defun > number-or-marker1 number-or-marker2This function tests whether its first argument is strictly greaterthan its second argument. It returns @code{t} if so, @code{nil}otherwise.@end defun@defun >= number-or-marker1 number-or-marker2This function tests whether its first argument is greater than orequal to its second argument. It returns @code{t} if so, @code{nil}otherwise.@end defun@defun max number-or-marker &rest numbers-or-markersThis function returns the largest of its arguments.@example(max 20) @result{} 20(max 1 2.5) @result{} 2.5(max 1 3 2.5) @result{} 3@end example@end defun@defun min number-or-marker &rest numbers-or-markersThis function returns the smallest of its arguments.@example(min -4 1) @result{} -4@end example@end defun@node Numeric Conversions@section Numeric Conversions@cindex rounding in conversionsTo convert an integer to floating point, use the function @code{float}.@defun float numberThis returns @var{number} converted to floating point.If @var{number} is already a floating point number, @code{float} returnsit unchanged.@end defunThere are four functions to convert floating point numbers to integers;they differ in how they round. These functions accept integer argumentsalso, and return such arguments unchanged.@defun truncate numberThis returns @var{number}, converted to an integer by rounding towardszero.@end defun@defun floor number &optional divisorThis 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 is the division operation thatcorresponds to @code{mod}. An @code{arith-error} results if@var{divisor} is 0.@end defun@defun ceiling numberThis returns @var{number}, converted to an integer by rounding upward(towards positive infinity).@end defun@defun round numberThis returns @var{number}, converted to an integer by rounding towards thenearest integer.@end defun@node Arithmetic Operations@section Arithmetic Operations Emacs Lisp provides the traditional four arithmetic operations:addition, subtraction, multiplication, and division. Remainder and modulusfunctions supplement the division functions. The functions toadd or subtract 1 are provided because they are traditional in Lisp andcommonly used. All of these functions except @code{%} return a floating point valueif any argument is floating. It is important to note that in GNU Emacs Lisp, arithmetic functionsdo not check for overflow. Thus @code{(1+ 8388607)} may evaluate to@minus{}8388608, depending on your hardware.@defun 1+ number-or-markerThis function returns @var{number-or-marker} plus 1.For example,@example(setq foo 4) @result{} 4(1+ foo) @result{} 5@end exampleThis function is not analogous to the C operator @code{++}---it doesnot increment a variable. It just computes a sum. Thus,@examplefoo @result{} 4@end exampleIf you want to increment the variable, you must use @code{setq},like this:@example(setq foo (1+ foo)) @result{} 5@end example@end defun@defun 1- number-or-markerThis function returns @var{number-or-marker} minus 1.@end defun@defun abs numberThis returns the absolute value of @var{number}.@end defun@defun + &rest numbers-or-markersThis function adds its arguments together. When given no arguments,@code{+} returns 0. It does not check for overflow.@example(+) @result{} 0(+ 1) @result{} 1(+ 1 2 3 4) @result{} 10@end example@end defun@defun - &optional number-or-marker &rest other-numbers-or-markersThe @code{-} function serves two purposes: negation and subtraction.When @code{-} has a single argument, the value is the negative of theargument. When there are multiple arguments, @code{-} subtracts each ofthe @var{other-numbers-or-markers} from @var{number-or-marker},cumulatively. If there are no arguments, the result is 0. Thisfunction does not check for overflow.@example(- 10 1 2 3 4) @result{} 0(- 10) @result{} -10(-) @result{} 0@end example@end defun@defun * &rest numbers-or-markersThis function multiplies its arguments together, and returns theproduct. When given no arguments, @code{*} returns 1. It doesnot check for overflow.@example(*) @result{} 1(* 1) @result{} 1(* 1 2 3 4) @result{} 24@end example@end defun@defun / dividend divisor &rest divisorsThis function divides @var{dividend} by @var{divisor} and returns thequotient. If there are additional arguments @var{divisors}, then itdivides @var{dividend} by each divisor in turn. Each argument may be anumber 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 resultis rounded towards zero after each division, but some machines may rounddifferently with negative arguments. This is because the Lisp function@code{/} is implemented using the C division operator, which alsopermits machine-dependent rounding. As a practical matter, all knownmachines round in the standard fashion.@cindex @code{arith-error} in divisionIf you divide by 0, an @code{arith-error} error is signaled.(@xref{Errors}.)@example(/ 6 2) @result{} 3(/ 5 2) @result{} 2(/ 25 3 2) @result{} 4(/ -17 6) @result{} -2@end exampleThe result of @code{(/ -17 6)} could in principle be -3 on somemachines.@end defun@defun % dividend divisor@cindex remainderThis 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-dependentsince the quotient is; but in practice, all known machines behave alike.An @code{arith-error} results if @var{divisor} is 0.@example(% 9 4) @result{} 1(% -9 4) @result{} -1(% 9 -4) @result{} 1(% -9 -4) @result{} -1@end exampleFor any two integers @var{dividend} and @var{divisor},@example@group(+ (% @var{dividend} @var{divisor}) (* (/ @var{dividend} @var{divisor}) @var{divisor}))@end group@end example@noindentalways equals @var{dividend}.@end defun@defun mod dividend divisor@cindex modulusThis function returns the value of @var{dividend} modulo @var{divisor};in other words, the remainder after division of @var{dividend}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 negativearguments. It also permits floating point arguments; it rounds thequotient downward (towards minus infinity) to an integer, and uses thatquotient to compute the remainder.An @code{arith-error} results if @var{divisor} is 0.@example(mod 9 4) @result{} 1(mod -9 4) @result{} 3(mod 9 -4) @result{} -3(mod -9 -4) @result{} -1(mod 5.5 2.5) @result{} .5@end exampleFor any two numbers @var{dividend} and @var{divisor},@example@group(+ (mod @var{dividend} @var{divisor}) (* (floor @var{dividend} @var{divisor}) @var{divisor}))@end group@end example@noindentalways equals @var{dividend}, subject to rounding error ifeither argument is floating point.@end defun@node Rounding Operations@section Rounding Operations@cindex rounding without conversionThe functions @code{ffloor}, @code{fceiling}, @code{fround} and@code{ftruncate} take a floating point argument and return a floatingpoint result whose value is a nearby integer. @code{ffloor} returns thenearest integer below; @code{fceiling}, the nearest integer above;@code{ftruncate}, the nearest integer in the direction towards zero;@code{fround}, the nearest integer.@defun ffloor floatThis function rounds @var{float} to the next lower integral value, andreturns that value as a floating point number.@end defun@defun fceiling floatThis function rounds @var{float} to the next higher integral value, andreturns that value as a floating point number.@end defun@defun ftruncate floatThis function rounds @var{float} towards zero to an integral value, andreturns that value as a floating point number.@end defun@defun fround floatThis function rounds @var{float} to the nearest integral value,and returns that value as a floating point number.@end defun@node Bitwise Operations@section Bitwise Operations on Integers In a computer, an integer is represented as a binary number, asequence of @dfn{bits} (digits which are either zero or one). A bitwiseoperation 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''. The bitwise operations in Emacs Lisp apply only to integers.@defun lsh integer1 count@cindex logical shift@code{lsh}, which is an abbreviation for @dfn{logical shift}, shifts thebits in @var{integer1} to the left @var{count} places, or to the rightif @var{count} is negative, bringing zeros into the vacated bits. If@var{count} is negative, @code{lsh} shifts zeros into the leftmost(most-significant) bit, producing a positive result even if@var{integer1} is negative. Contrast this with @code{ash}, below.Here are two examples of @code{lsh}, shifting a pattern of bits oneplace to the left. We show only the low-order eight bits of the binarypattern; the rest are all zero.@example@group(lsh 5 1) @result{} 10;; @r{Decimal 5 becomes decimal 10.}00000101 @result{} 00001010(lsh 7 1) @result{} 14;; @r{Decimal 7 becomes decimal 14.}00000111 @result{} 00001110@end group@end example@noindentAs the examples illustrate, shifting the pattern of bits one place tothe left produces a number that is twice the value of the previousnumber.The function @code{lsh}, like all Emacs Lisp arithmetic functions, doesnot check for overflow, so shifting left can discard significant bitsand change the sign of the number. For example, left shifting 8,388,607produces @minus{}2 on a 24-bit machine:@example(lsh 8388607 1) ; @r{left shift} @result{} -2@end exampleIn binary, in the 24-bit implementation, the argument looks like this:@example@group;; @r{Decimal 8,388,607}0111 1111 1111 1111 1111 1111 @end group@end example@noindentwhich becomes the following when left shifted:@example@group;; @r{Decimal @minus{}2}1111 1111 1111 1111 1111 1110 @end group@end exampleShifting the pattern of bits two places to the left produces resultslike this (with 8-bit binary numbers):@example@group(lsh 3 2) @result{} 12;; @r{Decimal 3 becomes decimal 12.}00000011 @result{} 00001100 @end group@end exampleOn the other hand, shifting the pattern of bits one place to the rightlooks like this:@example@group(lsh 6 -1) @result{} 3;; @r{Decimal 6 becomes decimal 3.}00000110 @result{} 00000011 @end group@group(lsh 5 -1) @result{} 2;; @r{Decimal 5 becomes decimal 2.}00000101 @result{} 00000010 @end group@end example@noindentAs the example illustrates, shifting the pattern of bits one place tothe right divides the value of the binary number by two, rounding downward.@end defun@defun ash integer1 count@cindex arithmetic shift@code{ash} (@dfn{arithmetic shift}) shifts the bits in @var{integer1}to the left @var{count} places, or to the right if @var{count}is negative.@code{ash} gives the same results as @code{lsh} except when@var{integer1} and @var{count} are both negative. In that case,@code{ash} puts a one in the leftmost position, while @code{lsh} putsa zero in the leftmost position.Thus, with @code{ash}, shifting the pattern of bits one place to the rightlooks like this:@example@group(ash -6 -1) @result{} -3 ;; @r{Decimal @minus{}6 becomes decimal @minus{}3.}1111 1111 1111 1111 1111 1010 @result{} 1111 1111 1111 1111 1111 1101@end group@end exampleIn contrast, shifting the pattern of bits one place to the right with@code{lsh} looks like this:@example@group(lsh -6 -1) @result{} 8388605 ;; @r{Decimal @minus{}6 becomes decimal 8,388,605.}1111 1111 1111 1111 1111 1010 @result{} 0111 1111 1111 1111 1111 1101@end group@end exampleHere are other examples:@c !!! Check if lined up in smallbook format! XDVI shows problem@c with smallbook but not with regular book! --rjc 16mar92@smallexample@group ; @r{ 24-bit binary values}(lsh 5 2) ; 5 = @r{0000 0000 0000 0000 0000 0101} @result{} 20 ; = @r{0000 0000 0000 0000 0001 0100}@end group@group(ash 5 2) @result{} 20(lsh -5 2) ; -5 = @r{1111 1111 1111 1111 1111 1011} @result{} -20 ; = @r{1111 1111 1111 1111 1110 1100}(ash -5 2) @result{} -20@end group@group(lsh 5 -2) ; 5 = @r{0000 0000 0000 0000 0000 0101} @result{} 1 ; = @r{0000 0000 0000 0000 0000 0001}@end group@group(ash 5 -2) @result{} 1@end group@group(lsh -5 -2) ; -5 = @r{1111 1111 1111 1111 1111 1011} @result{} 4194302 ; = @r{0011 1111 1111 1111 1111 1110}@end group@group(ash -5 -2) ; -5 = @r{1111 1111 1111 1111 1111 1011} @result{} -2 ; = @r{1111 1111 1111 1111 1111 1110}@end group@end smallexample@end defun@defun logand &rest ints-or-markers@cindex logical and@cindex bitwise andThis function returns the ``logical and'' of the arguments: the@var{n}th bit is set in the result if, and only if, the @var{n}th bit isset in all the arguments. (``Set'' means that the value of the bit is 1rather than 0.)For example, using 4-bit binary numbers, the ``logical and'' of 13 and12 is 12: 1101 combined with 1100 produces 1100.In both the binary numbers, the leftmost two bits are set (i.e., theyare 1's), so the leftmost two bits of the returned value are set.However, for the rightmost two bits, each is zero in at least one ofthe arguments, so the rightmost two bits of the returned value are 0's.@noindentTherefore,@example@group(logand 13 12) @result{} 12@end group@end exampleIf @code{logand} is not passed any argument, it returns a value of@minus{}1. This number is an identity element for @code{logand}because its binary representation consists entirely of ones. If@code{logand} is passed just one argument, it returns that argument.@smallexample@group ; @r{ 24-bit binary values}(logand 14 13) ; 14 = @r{0000 0000 0000 0000 0000 1110} ; 13 = @r{0000 0000 0000 0000 0000 1101} @result{} 12 ; 12 = @r{0000 0000 0000 0000 0000 1100}@end group@group(logand 14 13 4) ; 14 = @r{0000 0000 0000 0000 0000 1110} ; 13 = @r{0000 0000 0000 0000 0000 1101} ; 4 = @r{0000 0000 0000 0000 0000 0100} @result{} 4 ; 4 = @r{0000 0000 0000 0000 0000 0100}@end group@group(logand) @result{} -1 ; -1 = @r{1111 1111 1111 1111 1111 1111}@end group@end smallexample@end defun@defun logior &rest ints-or-markers@cindex logical inclusive or@cindex bitwise orThis function returns the ``inclusive or'' of its arguments: the @var{n}th bitis set in the result if, and only if, the @var{n}th bit is set in at leastone of the arguments. If there are no arguments, the result is zero,which is an identity element for this operation. If @code{logior} ispassed just one argument, it returns that argument.@smallexample@group ; @r{ 24-bit binary values}(logior 12 5) ; 12 = @r{0000 0000 0000 0000 0000 1100} ; 5 = @r{0000 0000 0000 0000 0000 0101} @result{} 13 ; 13 = @r{0000 0000 0000 0000 0000 1101}@end group@group(logior 12 5 7) ; 12 = @r{0000 0000 0000 0000 0000 1100} ; 5 = @r{0000 0000 0000 0000 0000 0101} ; 7 = @r{0000 0000 0000 0000 0000 0111} @result{} 15 ; 15 = @r{0000 0000 0000 0000 0000 1111}@end group@end smallexample@end defun@defun logxor &rest ints-or-markers@cindex bitwise exclusive or@cindex logical exclusive orThis function returns the ``exclusive or'' of its arguments: the@var{n}th bit is set in the result if, and only if, the @var{n}th bit isset in an odd number of the arguments. If there are no arguments, theresult is 0, which is an identity element for this operation. If@code{logxor} is passed just one argument, it returns that argument.@smallexample@group ; @r{ 24-bit binary values}(logxor 12 5) ; 12 = @r{0000 0000 0000 0000 0000 1100} ; 5 = @r{0000 0000 0000 0000 0000 0101} @result{} 9 ; 9 = @r{0000 0000 0000 0000 0000 1001}@end group@group(logxor 12 5 7) ; 12 = @r{0000 0000 0000 0000 0000 1100} ; 5 = @r{0000 0000 0000 0000 0000 0101} ; 7 = @r{0000 0000 0000 0000 0000 0111} @result{} 14 ; 14 = @r{0000 0000 0000 0000 0000 1110}@end group@end smallexample@end defun@defun lognot integer@cindex logical not@cindex bitwise notThis function returns the logical complement of its argument: the @var{n}thbit is one in the result if, and only if, the @var{n}th bit is zero in@var{integer}, and vice-versa.@example(lognot 5) @result{} -6;; 5 = @r{0000 0000 0000 0000 0000 0101};; @r{becomes};; -6 = @r{1111 1111 1111 1111 1111 1010}@end example@end defun@node Transcendental Functions@section Transcendental Functions@cindex transcendental functions@cindex mathematical functionsThese mathematical functions are available if floating point issupported. They allow integers as well as floating point numbersas arguments.@defun sin arg@defunx cos arg@defunx tan argThese are the ordinary trigonometric functions, with argument measuredin radians.@end defun@defun asin argThe value of @code{(asin @var{arg})} is a number between @minus{}pi/2and pi/2 (inclusive) whose sine is @var{arg}; if, however, @var{arg}is out of range (outside [-1, 1]), then the result is a NaN.@end defun@defun acos argThe value of @code{(acos @var{arg})} is a number between 0 and pi(inclusive) whose cosine is @var{arg}; if, however, @var{arg}is out of range (outside [-1, 1]), then the result is a NaN.@end defun@defun atan argThe value of @code{(atan @var{arg})} is a number between @minus{}pi/2and pi/2 (exclusive) whose tangent is @var{arg}.@end defun@defun exp argThis is the exponential function; it returns @i{e} to the power@var{arg}. @i{e} is a fundamental mathematical constant also called thebase of natural logarithms.@end defun@defun log arg &optional baseThis function returns the logarithm of @var{arg}, with base @var{base}.If you don't specify @var{base}, the base @var{e} is used. If @var{arg}is negative, the result is a NaN.@end defun@ignore@defun expm1 argThis function returns @code{(1- (exp @var{arg}))}, but it is moreaccurate than that when @var{arg} is negative and @code{(exp @var{arg})}is close to 1.@end defun@defun log1p argThis function returns @code{(log (1+ @var{arg}))}, but it is moreaccurate than that when @var{arg} is so small that adding 1 to it wouldlose accuracy.@end defun@end ignore@defun log10 argThis function returns the logarithm of @var{arg}, with base 10. If@var{arg} is negative, the result is a NaN. @code{(log10 @var{x})}@equiv{} @code{(log @var{x} 10)}, at least approximately.@end defun@defun expt x yThis function returns @var{x} raised to power @var{y}.@end defun@defun sqrt argThis returns the square root of @var{arg}. If @var{arg} is negative,the value is a NaN.@end defun@node Random Numbers@section Random Numbers@cindex random numbersA deterministic computer program cannot generate true random numbers.For most purposes, @dfn{pseudo-random numbers} suffice. A series ofpseudo-random numbers is generated in a deterministic fashion. Thenumbers are not truly random, but they have certain properties thatmimic a random series. For example, all possible values occur equallyoften 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 alwaysgenerates the same sequence of numbers. Emacs always starts with thesame seed value, so the sequence of values of @code{random} is actuallythe same in each Emacs run! For example, in one operating system, thefirst call to @code{(random)} after you start Emacs always returns-1457731, and the second one always returns -7692030. Thisrepeatability is helpful for debugging.If you want truly unpredictable random numbers, execute @code{(randomt)}. This chooses a new seed based on the current time of day and onEmacs's process @sc{id} number.@defun random &optional limitThis function returns a pseudo-random integer. Repeated calls return aseries of pseudo-random integers.If @var{limit} is @code{nil}, then the value may in principle be anyinteger. If @var{limit} is a positive integer, the value is chosen tobe nonnegative and less than @var{limit} (only in Emacs 19).If @var{limit} is @code{t}, it means to choose a new seed based on thecurrent time of day and on Emacs's process @sc{id} number.@c "Emacs'" is incorrect usage!On some machines, any integer representable in Lisp may be the resultof @code{random}. On other machines, the result can never be largerthan a certain maximum or less than a certain (negative) minimum.@end defun