comparison man/lispref/numbers.texi @ 5791:9fae6227ede5

Silence texinfo 5.2 warnings, primarily by adding next, prev, and up pointers to all nodes. See xemacs-patches message with ID <5315f7bf.sHpFD7lXYR05GH6E%james@xemacs.org>.
author Jerry James <james@xemacs.org>
date Thu, 27 Mar 2014 08:59:03 -0600
parents a2912073be85
children 6174848f3e6c
comparison
equal deleted inserted replaced
5790:dcf9067f26bb 5791:9fae6227ede5
75 * Bitwise Operations:: Logical and, or, not, shifting. 75 * Bitwise Operations:: Logical and, or, not, shifting.
76 * Math Functions:: Trig, exponential and logarithmic functions. 76 * Math Functions:: Trig, exponential and logarithmic functions.
77 * Random Numbers:: Obtaining random integers, predictable or not. 77 * Random Numbers:: Obtaining random integers, predictable or not.
78 @end menu 78 @end menu
79 79
80 @node Integer Basics 80 @node Integer Basics, Rational Basics, Numbers, Numbers
81 @section Integer Basics 81 @section Integer Basics
82 82
83 The range of values for an integer depends on the machine. If a 83 The range of values for an integer depends on the machine. If a
84 multiple-precision arithmetic library is available on your platform, 84 multiple-precision arithmetic library is available on your platform,
85 support for bignums, that is, integers with arbitrary precision, may be 85 support for bignums, that is, integers with arbitrary precision, may be
199 argument, all of the functions for markers and integers also work for 199 argument, all of the functions for markers and integers also work for
200 floating point numbers. 200 floating point numbers.
201 @end ignore 201 @end ignore
202 202
203 203
204 @node Rational Basics 204 @node Rational Basics, Float Basics, Integer Basics, Numbers
205 @section Rational Basics 205 @section Rational Basics
206 206
207 Ratios (built-in rational numbers) are available only when the bignum 207 Ratios (built-in rational numbers) are available only when the bignum
208 extension is built into your XEmacs. This facility is new and 208 extension is built into your XEmacs. This facility is new and
209 experimental. It is discussed in a separate section for convenience of 209 experimental. It is discussed in a separate section for convenience of
223 If @var{rational} is an integer, 1 is returned. @var{rational} must be 223 If @var{rational} is an integer, 1 is returned. @var{rational} must be
224 an integer or a ratio. 224 an integer or a ratio.
225 @end defun 225 @end defun
226 226
227 227
228 @node Float Basics 228 @node Float Basics, The Bignum Extension, Rational Basics, Numbers
229 @section Floating Point Basics 229 @section Floating Point Basics
230 230
231 XEmacs supports floating point numbers. The precise range of floating 231 XEmacs supports floating point numbers. The precise range of floating
232 point numbers is machine-specific; it is the same as the range of the C 232 point numbers is machine-specific; it is the same as the range of the C
233 data type @code{double} on the machine in question. If a 233 data type @code{double} on the machine in question. If a
308 floating point number, so Lisp programs can detect loss of precision due 308 floating point number, so Lisp programs can detect loss of precision due
309 to unnormalized floats by checking whether the number is between 309 to unnormalized floats by checking whether the number is between
310 @code{least-positive-float} and @code{least-positive-normalized-float}. 310 @code{least-positive-float} and @code{least-positive-normalized-float}.
311 311
312 312
313 @node The Bignum Extension 313 @node The Bignum Extension, Predicates on Numbers, Float Basics, Numbers
314 @section The Bignum Extension 314 @section The Bignum Extension
315 315
316 In XEmacs 21.5.18, an extension was added by @email{james@@xemacs.org, 316 In XEmacs 21.5.18, an extension was added by @email{james@@xemacs.org,
317 Jerry James} to allow linking with arbitrary-precision arithmetic 317 Jerry James} to allow linking with arbitrary-precision arithmetic
318 libraries if they are available on your platform. ``Arbitrary'' 318 libraries if they are available on your platform. ``Arbitrary''
371 * Canonicalization and Contagion:: Automatic coercion to other types. 371 * Canonicalization and Contagion:: Automatic coercion to other types.
372 * Compatibility Issues:: Changes in fixed-precision arithmetic. 372 * Compatibility Issues:: Changes in fixed-precision arithmetic.
373 @end menu 373 @end menu
374 374
375 375
376 @node Bignum Basics 376 @node Bignum Basics, Ratio Basics, The Bignum Extension, The Bignum Extension
377 @subsection Bignum Basics 377 @subsection Bignum Basics
378 378
379 In most cases, bignum support should be transparent to users and Lisp 379 In most cases, bignum support should be transparent to users and Lisp
380 programmers. A bignum-enabled XEmacs will automatically convert from 380 programmers. A bignum-enabled XEmacs will automatically convert from
381 fixnums to bignums and back in pure integer arithmetic, and for GMP and 381 fixnums to bignums and back in pure integer arithmetic, and for GMP and
385 bignums, as have the mathematical functions. Rationals (fixnums, 385 bignums, as have the mathematical functions. Rationals (fixnums,
386 bignums, and ratios) are printed using the @samp{%d}, @samp{%o}, 386 bignums, and ratios) are printed using the @samp{%d}, @samp{%o},
387 @samp{%x}, and @samp{%u} format conversions. 387 @samp{%x}, and @samp{%u} format conversions.
388 388
389 389
390 @node Ratio Basics 390 @node Ratio Basics, Bigfloat Basics, Bignum Basics, The Bignum Extension
391 @subsection Ratio Basics 391 @subsection Ratio Basics
392 392
393 Ratios, when available, have the read syntax and print representation 393 Ratios, when available, have the read syntax and print representation
394 @samp{3/5}. Like other rationals (fixnums and bignums), they are 394 @samp{3/5}. Like other rationals (fixnums and bignums), they are
395 printed using the @samp{%d}, @samp{%o}, @samp{%x}, and @samp{%u} format 395 printed using the @samp{%d}, @samp{%o}, @samp{%x}, and @samp{%u} format
396 conversions. 396 conversions.
397 397
398 398
399 @node Bigfloat Basics 399 @node Bigfloat Basics, Canonicalization and Contagion, Ratio Basics, The Bignum Extension
400 @subsection Bigfloat Basics 400 @subsection Bigfloat Basics
401 401
402 Bigfloats, when available, have the same read syntax and print 402 Bigfloats, when available, have the same read syntax and print
403 representations as fixed-precision floats. 403 representations as fixed-precision floats.
404 404
435 @example 435 @example
436 (coerce 999999999999999 'bigfloat) 436 (coerce 999999999999999 'bigfloat)
437 @result{} 9.99999999999999E14 437 @result{} 9.99999999999999E14
438 @end example 438 @end example
439 439
440 @node Canonicalization and Contagion 440 @node Canonicalization and Contagion, Compatibility Issues, Bigfloat Basics, The Bignum Extension
441 @subsection Canonicalization and Contagion 441 @subsection Canonicalization and Contagion
442 442
443 @dfn{Canonicalization} is a rule intended to enhance the time and space 443 @dfn{Canonicalization} is a rule intended to enhance the time and space
444 efficiency of exact arithmetic. Because bignums and ratios are 444 efficiency of exact arithmetic. Because bignums and ratios are
445 implemented as record objects, they take up much more space than 445 implemented as record objects, they take up much more space than
526 However, if we've done our job properly, this is always a no-op. That 526 However, if we've done our job properly, this is always a no-op. That
527 is, if you find a number in un-canonicalized form, please report it as a 527 is, if you find a number in un-canonicalized form, please report it as a
528 bug. 528 bug.
529 529
530 530
531 @node Compatibility Issues 531 @node Compatibility Issues, , Canonicalization and Contagion, The Bignum Extension
532 @subsection Compatibility Issues 532 @subsection Compatibility Issues
533 533
534 @emph{Surgeon General's Warning}: The automatic conversions cannot be 534 @emph{Surgeon General's Warning}: The automatic conversions cannot be
535 disabled at runtime. Old functions will not produce ratios unless there 535 disabled at runtime. Old functions will not produce ratios unless there
536 is a ratio operand, so there should be few surprises with type 536 is a ratio operand, so there should be few surprises with type
590 same type which have equal values compare equal, or @code{=}, which does 590 same type which have equal values compare equal, or @code{=}, which does
591 any necessary type coercions before comparing for equality 591 any necessary type coercions before comparing for equality
592 @ref{Comparison of Numbers}. 592 @ref{Comparison of Numbers}.
593 593
594 594
595 @node Predicates on Numbers 595 @node Predicates on Numbers, Comparison of Numbers, The Bignum Extension, Numbers
596 @section Type Predicates for Numbers 596 @section Type Predicates for Numbers
597 597
598 The functions in this section test whether the argument is a number or 598 The functions in this section test whether the argument is a number or
599 whether it is a certain sort of number. The functions which test for 599 whether it is a certain sort of number. The functions which test for
600 type can take any type of Lisp object as argument (the more general 600 type can take any type of Lisp object as argument (the more general
700 floating point number represented as a bigfloat, and returns @code{t} if 700 floating point number represented as a bigfloat, and returns @code{t} if
701 so, @code{nil} otherwise. 701 so, @code{nil} otherwise.
702 @end defun 702 @end defun
703 703
704 704
705 @node Comparison of Numbers 705 @node Comparison of Numbers, Numeric Conversions, Predicates on Numbers, Numbers
706 @section Comparison of Numbers 706 @section Comparison of Numbers
707 @cindex number equality 707 @cindex number equality
708 708
709 To test numbers for numerical equality, you should normally use 709 To test numbers for numerical equality, you should normally use
710 @code{=}, not @code{eq}. There can be many distinct floating point, 710 @code{=}, not @code{eq}. There can be many distinct floating point,
874 (min -4 1) 874 (min -4 1)
875 @result{} -4 875 @result{} -4
876 @end example 876 @end example
877 @end defun 877 @end defun
878 878
879 @node Numeric Conversions 879 @node Numeric Conversions, Arithmetic Operations, Comparison of Numbers, Numbers
880 @section Numeric Conversions 880 @section Numeric Conversions
881 @cindex rounding in conversions 881 @cindex rounding in conversions
882 882
883 To convert an integer to floating point, use the function @code{float}. 883 To convert an integer to floating point, use the function @code{float}.
884 884
921 integer. GNU Emacs and older XEmacs did not guarantee this, and the 921 integer. GNU Emacs and older XEmacs did not guarantee this, and the
922 direction of rounding depended on the underlying machine and the C 922 direction of rounding depended on the underlying machine and the C
923 implementation. 923 implementation.
924 @end defun 924 @end defun
925 925
926 @node Arithmetic Operations 926 @node Arithmetic Operations, Rounding Operations, Numeric Conversions, Numbers
927 @section Arithmetic Operations 927 @section Arithmetic Operations
928 928
929 XEmacs Lisp provides the traditional four arithmetic operations: 929 XEmacs Lisp provides the traditional four arithmetic operations:
930 addition, subtraction, multiplication, and division. Remainder and modulus 930 addition, subtraction, multiplication, and division. Remainder and modulus
931 functions supplement the division functions. The functions to 931 functions supplement the division functions. The functions to
1164 always equals @var{dividend}, subject to rounding error if either 1164 always equals @var{dividend}, subject to rounding error if either
1165 argument is floating point. For @code{floor}, see @ref{Numeric 1165 argument is floating point. For @code{floor}, see @ref{Numeric
1166 Conversions}. 1166 Conversions}.
1167 @end defun 1167 @end defun
1168 1168
1169 @node Rounding Operations 1169 @node Rounding Operations, Bitwise Operations, Arithmetic Operations, Numbers
1170 @section Rounding Operations 1170 @section Rounding Operations
1171 @cindex rounding without conversion 1171 @cindex rounding without conversion
1172 1172
1173 The functions @code{ffloor}, @code{fceiling}, @code{fround} and 1173 The functions @code{ffloor}, @code{fceiling}, @code{fround} and
1174 @code{ftruncate} take a floating point argument and return a floating 1174 @code{ftruncate} take a floating point argument and return a floating
1206 even value. While this is specified by Common Lisp, GNU Emacs and older 1206 even value. While this is specified by Common Lisp, GNU Emacs and older
1207 XEmacs did not make this guarantee, and the direction of rounding 1207 XEmacs did not make this guarantee, and the direction of rounding
1208 depended on the underlying machine and the C implementation. 1208 depended on the underlying machine and the C implementation.
1209 @end defun 1209 @end defun
1210 1210
1211 @node Bitwise Operations 1211 @node Bitwise Operations, Math Functions, Rounding Operations, Numbers
1212 @section Bitwise Operations on Integers 1212 @section Bitwise Operations on Integers
1213 1213
1214 In a computer, an integer is represented as a binary number, a 1214 In a computer, an integer is represented as a binary number, a
1215 sequence of @dfn{bits} (digits which are either zero or one). A bitwise 1215 sequence of @dfn{bits} (digits which are either zero or one). A bitwise
1216 operation acts on the individual bits of such a sequence. For example, 1216 operation acts on the individual bits of such a sequence. For example,
1511 ;; @r{becomes} 1511 ;; @r{becomes}
1512 ;; -6 = @r{1111 1111 1111 1111 1111 1111 1010} 1512 ;; -6 = @r{1111 1111 1111 1111 1111 1111 1010}
1513 @end example 1513 @end example
1514 @end defun 1514 @end defun
1515 1515
1516 @node Math Functions 1516 @node Math Functions, Random Numbers, Bitwise Operations, Numbers
1517 @section Standard Mathematical Functions 1517 @section Standard Mathematical Functions
1518 @cindex transcendental functions 1518 @cindex transcendental functions
1519 @cindex mathematical functions 1519 @cindex mathematical functions
1520 1520
1521 These mathematical functions are available if floating point is 1521 These mathematical functions are available if floating point is
1593 1593
1594 @defun cube-root number 1594 @defun cube-root number
1595 This returns the cube root of @var{number}. 1595 This returns the cube root of @var{number}.
1596 @end defun 1596 @end defun
1597 1597
1598 @node Random Numbers 1598 @node Random Numbers, , Math Functions, Numbers
1599 @section Random Numbers 1599 @section Random Numbers
1600 @cindex random numbers 1600 @cindex random numbers
1601 1601
1602 A deterministic computer program cannot generate true random numbers. 1602 A deterministic computer program cannot generate true random numbers.
1603 For most purposes, @dfn{pseudo-random numbers} suffice. A series of 1603 For most purposes, @dfn{pseudo-random numbers} suffice. A series of