]> code.delx.au - gnu-emacs/blobdiff - lispref/numbers.texi
(Defining Abbrevs): Index no-self-insert.
[gnu-emacs] / lispref / numbers.texi
index a3a5767173958467d94c7ae7c3c61741e95f2fc3..e2cfc937c4d1a18d2ddb3a4600cd3d22ef30f084 100644 (file)
@@ -1,7 +1,7 @@
 @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
@@ -37,17 +37,17 @@ exact; they have a fixed, limited amount of precision.
 
   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
@@ -67,6 +67,18 @@ initial sign and optional final period.
 -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.
@@ -123,6 +135,16 @@ arguments to such functions may be either numbers or markers, we often
 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
 
@@ -360,21 +382,56 @@ also, and return such arguments unchanged.
 @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
@@ -382,6 +439,17 @@ This returns @var{number}, converted to an integer by rounding towards the
 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
@@ -688,7 +756,7 @@ like this (with 8-bit binary numbers):
 (lsh 3 2)
      @result{} 12
 ;; @r{Decimal 3 becomes decimal 12.}
-00000011 @result{} 00001100       
+00000011 @result{} 00001100
 @end group
 @end example
 
@@ -699,14 +767,14 @@ On the other hand, shifting one place to the right looks like this:
 (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
 
@@ -729,7 +797,7 @@ In binary, in the 28-bit implementation, the argument looks like this:
 @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
 
@@ -739,7 +807,7 @@ which becomes the following when left shifted:
 @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
@@ -760,10 +828,10 @@ looks like this:
 
 @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
@@ -776,7 +844,7 @@ In contrast, shifting the pattern of bits one place to the right with
 (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
@@ -934,7 +1002,7 @@ bit 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)             
+(lognot 5)
      @result{} -6
 ;;  5  =  @r{0000  0000 0000  0000 0000  0000 0101}
 ;; @r{becomes}
@@ -959,16 +1027,16 @@ in radians.
 
 @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
@@ -978,9 +1046,9 @@ 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
 @math{\pi}
 @end tex
@@ -988,22 +1056,25 @@ pi
 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
@@ -1011,16 +1082,16 @@ This is the exponential function; it returns
 @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
@@ -1031,9 +1102,9 @@ If you don't specify @var{base}, the base
 @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
@@ -1109,3 +1180,7 @@ 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.
 @end defun
+
+@ignore
+   arch-tag: 574e8dd2-d513-4616-9844-c9a27869782e
+@end ignore