@c -*-texinfo-*-
@c This is part of the GNU Emacs Lisp Reference Manual.
@c Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1998, 1999
-@c Free Software Foundation, Inc.
+@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
-@tex
+@end ifnottex
+@tex
@math{-2^{27}}
@end tex
-to
-@ifinfo
+to
+@ifnottex
2**27 - 1),
-@end ifinfo
-@tex
+@end ifnottex
+@tex
@math{2^{27}-1}),
@end tex
but some machines may provide a wider range. Many examples in this
-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,
+inclusively). 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.
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.
+@defvar most-positive-fixnum
+The value of this variable is the largest integer that Emacs Lisp
+can handle.
+@end defvar
+
+@defvar most-negative-fixnum
+The value of this variable is the smallest integer that Emacs Lisp can
+handle. It is negative.
+@end defvar
+
@node Float Basics
@section Floating Point Basics
@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
(lsh 3 2)
@result{} 12
;; @r{Decimal 3 becomes decimal 12.}
-00000011 @result{} 00001100
+00000011 @result{} 00001100
@end group
@end example
(lsh 6 -1)
@result{} 3
;; @r{Decimal 6 becomes decimal 3.}
-00000110 @result{} 00000011
+00000110 @result{} 00000011
@end group
@group
(lsh 5 -1)
@result{} 2
;; @r{Decimal 5 becomes decimal 2.}
-00000101 @result{} 00000010
+00000101 @result{} 00000010
@end group
@end example
@example
@group
;; @r{Decimal 134,217,727}
-0111 1111 1111 1111 1111 1111 1111
+0111 1111 1111 1111 1111 1111 1111
@end group
@end example
@example
@group
;; @r{Decimal @minus{}2}
-1111 1111 1111 1111 1111 1111 1110
+1111 1111 1111 1111 1111 1111 1110
@end group
@end example
@end defun
@example
@group
-(ash -6 -1) @result{} -3
+(ash -6 -1) @result{} -3
;; @r{Decimal @minus{}6 becomes decimal @minus{}3.}
1111 1111 1111 1111 1111 1111 1010
- @result{}
+ @result{}
1111 1111 1111 1111 1111 1111 1101
@end group
@end example
(lsh -6 -1) @result{} 134217725
;; @r{Decimal @minus{}6 becomes decimal 134,217,725.}
1111 1111 1111 1111 1111 1111 1010
- @result{}
+ @result{}
0111 1111 1111 1111 1111 1111 1101
@end group
@end example
@var{integer}, and vice-versa.
@example
-(lognot 5)
+(lognot 5)
@result{} -6
;; 5 = @r{0000 0000 0000 0000 0000 0000 0101}
;; @r{becomes}
@defun asin arg
The value of @code{(asin @var{arg})} is a number between
-@ifinfo
+@ifnottex
@minus{}pi/2
-@end ifinfo
+@end ifnottex
@tex
@math{-\pi/2}
@end tex
and
-@ifinfo
+@ifnottex
pi/2
-@end ifinfo
+@end ifnottex
@tex
@math{\pi/2}
@end tex
@defun acos arg
The value of @code{(acos @var{arg})} is a number between 0 and
-@ifinfo
+@ifnottex
pi
-@end ifinfo
+@end ifnottex
@tex
@math{\pi}
@end tex
is out of range (outside [-1, 1]), then the result is a NaN.
@end defun
-@defun atan arg
-The value of @code{(atan @var{arg})} is a number between
-@ifinfo
+@defun atan y &optional x
+The value of @code{(atan @var{y})} is a number between
+@ifnottex
@minus{}pi/2
-@end ifinfo
+@end ifnottex
@tex
@math{-\pi/2}
@end tex
and
-@ifinfo
+@ifnottex
pi/2
-@end ifinfo
+@end ifnottex
@tex
@math{\pi/2}
@end tex
-(exclusive) whose tangent is @var{arg}.
+(exclusive) whose tangent is @var{y}. If the optional second
+argument @var{x} is given, the value of @code{(atan y x)} is the
+angle in radians between the vector @code{[@var{x}, @var{y}]} and the
+@code{X} axis.
@end defun
@defun exp arg
@tex
@math{e}
@end tex
-@ifinfo
+@ifnottex
@i{e}
-@end ifinfo
+@end ifnottex
to the power @var{arg}.
@tex
@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
@tex
@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
of @code{random}. On other machines, the result can never be larger
than a certain maximum or less than a certain (negative) minimum.
@end defun
+
+@ignore
+ arch-tag: 574e8dd2-d513-4616-9844-c9a27869782e
+@end ignore