comparison man/internals/internals.texi @ 5739:a2912073be85

Support bignums with MPIR. Add documentation on the bignum, ratio, and bigfloat implementations. See xemacs-patches message with ID <CAHCOHQkytZao7Uk9ggeo1HKKJtN1bqO054X2mPsGYyQFjbHrZA@mail.gmail.com> and following messages.
author Jerry James <james@xemacs.org>
date Wed, 19 Jun 2013 09:30:30 -0600
parents 9c9b07d40f20
children 9fae6227ede5
comparison
equal deleted inserted replaced
5738:f6af091ac654 5739:a2912073be85
1 \input texinfo @c -*-texinfo-*- 1 \input texinfo @c -*-texinfo-*-
2 @c %**start of header 2 @c %**start of header
3 @setfilename ../../info/internals.info 3 @setfilename ../../info/internals.info
4 @settitle XEmacs Internals Manual 4 @settitle XEmacs Internals Manual
5 @c %**end of header 5 @c %**end of header
6 6
86 @author Martin Buchholz 86 @author Martin Buchholz
87 @author Hrvoje Niksic 87 @author Hrvoje Niksic
88 @author Matthias Neubauer 88 @author Matthias Neubauer
89 @author Olivier Galibert 89 @author Olivier Galibert
90 @author Andy Piper 90 @author Andy Piper
91 @author Jerry James
91 92
92 93
93 @page 94 @page
94 @vskip 0pt plus 1fill 95 @vskip 0pt plus 1fill
95 96
351 * Regression Testing XEmacs:: 352 * Regression Testing XEmacs::
352 * Mercurial Techniques:: 353 * Mercurial Techniques::
353 * CVS Techniques:: 354 * CVS Techniques::
354 * XEmacs from the Inside:: 355 * XEmacs from the Inside::
355 * Basic Types:: 356 * Basic Types::
357 * Numeric Types::
356 * Low-Level Allocation:: 358 * Low-Level Allocation::
357 * The XEmacs Object System (Abstractly Speaking):: 359 * The XEmacs Object System (Abstractly Speaking)::
358 * How Lisp Objects Are Represented in C:: 360 * How Lisp Objects Are Represented in C::
359 * Allocation of Objects in XEmacs Lisp:: 361 * Allocation of Objects in XEmacs Lisp::
360 * The Lisp Reader and Compiler:: 362 * The Lisp Reader and Compiler::
3141 @item @file{native-gtk-toolbar.c} @tab 3143 @item @file{native-gtk-toolbar.c} @tab
3142 @item @file{ndir.h} @tab @ref{Modules for Interfacing with the File System}. 3144 @item @file{ndir.h} @tab @ref{Modules for Interfacing with the File System}.
3143 @item @file{nt.c} @tab 3145 @item @file{nt.c} @tab
3144 @item @file{ntheap.c} @tab 3146 @item @file{ntheap.c} @tab
3145 @item @file{ntplay.c} @tab 3147 @item @file{ntplay.c} @tab
3146 @item @file{number-gmp.c} @tab 3148 @item @file{number-gmp.c} @tab @ref{GMP and MPIR driver}
3147 @item @file{number-gmp.h} @tab 3149 @item @file{number-gmp.h} @tab @ref{GMP and MPIR driver}
3148 @item @file{number-mp.c} @tab 3150 @item @file{number-mp.c} @tab @ref{BSD MP driver}
3149 @item @file{number-mp.h} @tab 3151 @item @file{number-mp.h} @tab @ref{BSD MP driver}
3150 @item @file{number.c} @tab 3152 @item @file{number-mpir.c} @tab @ref{GMP and MPIR driver}
3151 @item @file{number.h} @tab 3153 @item @file{number-mpir.h} @tab @ref{GMP and MPIR driver}
3154 @item @file{number.c} @tab @ref{Abstract Numeric Interface}
3155 @item @file{number.h} @tab @ref{Abstract Numeric Interface}
3152 @item @file{fontcolor-gtk-impl.h} @tab 3156 @item @file{fontcolor-gtk-impl.h} @tab
3153 @item @file{fontcolor-gtk.c} @tab 3157 @item @file{fontcolor-gtk.c} @tab
3154 @item @file{fontcolor-gtk.h} @tab 3158 @item @file{fontcolor-gtk.h} @tab
3155 @item @file{fontcolor-impl.h} @tab 3159 @item @file{fontcolor-impl.h} @tab
3156 @item @file{fontcolor-msw-impl.h} @tab 3160 @item @file{fontcolor-msw-impl.h} @tab
7228 makes it much easier for people who are not XEmacs developers to 7232 makes it much easier for people who are not XEmacs developers to
7229 customize XEmacs, because they can make a change with much less chance 7233 customize XEmacs, because they can make a change with much less chance
7230 of obscure and unwanted interactions occurring than if they were to 7234 of obscure and unwanted interactions occurring than if they were to
7231 change the C code. 7235 change the C code.
7232 7236
7233 @node Basic Types, Low-Level Allocation, XEmacs from the Inside, Top 7237 @node Basic Types, Numeric Types, XEmacs from the Inside, Top
7234 @chapter Basic Types 7238 @chapter Basic Types
7235 @cindex basic types 7239 @cindex basic types
7236 @cindex types, basic 7240 @cindex types, basic
7237 7241
7238 Not yet documented. 7242 Not yet documented.
7239 7243
7240 @node Low-Level Allocation, The XEmacs Object System (Abstractly Speaking), Basic Types, Top 7244 @node Numeric Types, Low-Level Allocation, Basic Types, Top
7245 @chapter Numeric Types
7246 @cindex numeric types
7247 @cindex types, numeric
7248
7249 @menu
7250 * Abstract Numeric Interface::
7251 * GMP and MPIR driver::
7252 * BSD MP driver::
7253 * Numeric driver interface::
7254 @end menu
7255
7256 @node Abstract Numeric Interface, GMP and MPIR driver, Numeric Types, Numeric Types
7257 @section Abstract Interface
7258 @cindex abstract numeric interface
7259
7260 The following types are always defined in the same manner:
7261 @itemize
7262 @item fixnum
7263 Whatever fits in the @code{Lisp_Object} type.
7264 @item integer
7265 The union of the @code{fixnum} and @code{bignum} types.
7266 @item rational
7267 The union of the @code{integer} and @code{ratio} types.
7268 @item float
7269 The equivalent of a C @code{double}.
7270 @item floating
7271 The union of the @code{float} and @code{bigfloat} types.
7272 @item real
7273 The union of the @code{rational} and @code{floating} types.
7274 @item number
7275 The union of the @code{real} and @code{complex} types. Since there is
7276 no @code{complex} type, this is currently equivalent to the @code{real}
7277 type.
7278 @end itemize
7279
7280 The remaining types (@code{bignum}, @code{ratio}, and @code{bigfloat})
7281 are defined by library-specific drivers, as detailed in the remaining
7282 sections of this chapter. A given driver may define one or more of
7283 these types to be empty. In fact, the default configuration makes all
7284 three types empty, so that @code{integer} and @code{rational} are the
7285 same types as @code{fixnum}, etc. The configure script sets zero or
7286 more of the symbols @code{HAVE_BIGNUM}, @code{HAVE_RATIO}, and
7287 @code{HAVE_BIGFLOAT} to indicate which types are nonempty. These are
7288 the consequences of an empty type:
7289 @itemize
7290 @item bignum
7291 Then @code{bignump(x)} is false for all x. Any attempt to create a
7292 bignum causes an error to be raised.
7293 @item ratio
7294 Then @code{ratiop(x)} is false for all x. Any attempt to create a ratio
7295 causes an error to be raised.
7296 @item bigfloat
7297 Then @code{bigfloat(x)} is false for all x. Any attempt to create a
7298 bigfloat causes an error to be raised.
7299 @end itemize
7300
7301 We @code{(provide)} the following symbols, so that Lisp code can
7302 determine when the various numeric types are available for use:
7303 @itemize @bullet
7304 @item
7305 @code{(provide 'bignum)} if @code{HAVE_BIGNUM} is set
7306 @item
7307 @code{(provde 'ratio)} if @code{HAVE_RATIO} is set
7308 @item
7309 @code{(provide 'bigfloat)} if @code{HAVE_BIGFLOAT} is set
7310 @end itemize
7311
7312 C code should use one of the following macros to create a Lisp integer,
7313 depending on the type of the C integer to be converted.
7314 @itemize @bullet
7315 @item
7316 @code{make_fixnum(x)} if x is guaranteed to fit into a Lisp fixnum.
7317 @item
7318 @code{make_integer(x)} if x is a signed C integer of any type.
7319 @item
7320 @code{make_unsigned_integer(x)} if x is an unsigned C integer of any type.
7321 @end itemize
7322
7323 The @code{make_integer(x)} and @code{make_unsigned_integer(x)} macros
7324 both create a fixnum if possible, and a bignum otherwise. The value
7325 @code{x} can be a C integer of any size up to and including the size
7326 of a C @code{long long int}. The @code{make_fixnum(x)} macro is
7327 intended to signal the programmer's intent that only fixnum-sized
7328 integers will be used. In some cases, if the compiler cannot prove
7329 that the parameter is always in the fixnum range, this macro is also a
7330 code optimization.
7331
7332 @node GMP and MPIR driver, BSD MP driver, Abstract Numeric Interface, Numeric Types
7333 @section GMP driver
7334 @cindex gmp
7335 @cindex mpir
7336
7337 The GNU Multiple Precision library (@uref{http://gmplib.org/}) and its
7338 fork, the Multiple Precision Integers and Rationals library
7339 (@uref{http://www.mpir.org/}), provide large integers, ratios, and
7340 floating point numbers. The same driver supports both GMP and MPIR, and
7341 provides all 3 of the optional types: bignums, ratios, and bigfloats,
7342 implemented with the types @code{mpz_t}, @code{mpq_t}, and @code{mpf_t},
7343 respectively. Most of the abstract numeric interface is defined in
7344 terms of macros that expand directly into GMP or MPIR API calls, since
7345 GMP and MPIR provide a rich interface.
7346
7347 @node BSD MP driver, Numeric driver interface, GMP and MPIR driver, Numeric Types
7348 @section BSD MP driver
7349 @cindex BSD mp
7350
7351 The BSD MP interface is less rich than its GMP and MPIR counterparts.
7352 It provides only large integers, implemented as type @code{MINT *};
7353 ratios and bigfloats are not available. BSD MP libraries are supplied
7354 by multiple vendors, with some small variations. This driver is
7355 intended to work with any variation.
7356
7357 Some BSD MP libraries use function names that are likely cause name
7358 collisions, such as @code{gcd}, @code{mult}, and @code{pow}. Others
7359 follow the Single Unix Specification recommendation (see
7360 @uref{http://www.unix.com/man-page/all/3mp/mp_mcmp/}) and prefix all of
7361 the function names with ``mp_'': @code{mp_gcd}, @code{mp_mult},
7362 @code{mp_pow}, etc. The XEmacs configure script detects which of the
7363 two interfaces is in use, and defines @code{MP_PREFIX} for the latter
7364 case. We use macros (@code{MP_MULT}, etc.) to hide this difference.
7365
7366 Another variation is that some, but not all, BSD MP libraries supply a
7367 function named @code{move} or @code{mp_move} that copies its first
7368 argument into its second argument. We define the move operation as
7369 setting the destination number to the source number plus zero for those
7370 libraries that do not supply this function.
7371
7372 The BSD MP interface does not directly support many of the operations
7373 that we need, so the implementations sometimes consist of complex
7374 functions. See the implementation of @code{bignum_random}, for
7375 example.
7376
7377 @node Numeric driver interface, , BSD MP driver, Numeric Types
7378 @section Numeric driver interface
7379 @cindex numeric driver interface
7380
7381 @menu
7382 * Bignum interface::
7383 * Ratio interface::
7384 * Bigfloat interface::
7385 @end menu
7386
7387 @node Bignum interface, Ratio interface, Numeric driver interface, Numeric driver interface
7388 @subsection Bignum interface
7389 @cindex bignum interface
7390
7391 Each bignum implementation defines @code{HAVE_BIGNUM} and an appropriate
7392 bignum type. For example, the GMP driver uses this definition:
7393
7394 @example
7395 typedef mpz_t bignum;
7396 @end example
7397
7398 The following names are defined for each driver, either as real C
7399 functions or as C preprocessor macros.
7400 @itemize
7401 @item void bignum_init(bignum b)
7402 Does any necessary initialization before the bignum @code{b} can be
7403 used. This function typically allocates memory for the bignum.
7404 @item void bignum_fini(bignum b)
7405 Cleans up any resources held by the bignum @code{b}, typically
7406 deallocating the memory dedicated to that bignum. The object referred
7407 to by @code{b} must not be accessed after this call returns.
7408 @item unsigned int bignum_hashcode(bignum b)
7409 Returns a hash code for the bignum, suitable for use in XEmacs hash
7410 tables.
7411 @item int bignum_sign(bignum b)
7412 Returns a positive value, zero, or a negative value to indicate that
7413 @code{b} is positive, zero, or negative, respectively.
7414 @item int bignum_evenp(bignum b)
7415 Returns a nonzero value if @code{b} is an even number, zero if it is odd.
7416 @item int bignum_oddp(bignum b)
7417 Returns a nonzero value if @code{b} is an odd number, zero if it is even.
7418 @item int bignum_fits_int_p(bignum b)
7419 Returns a nonzero value if @code{b} can be represented in a C
7420 @code{int}, zero otherwise.
7421 @item int bignum_fits_uint_p(bignum b)
7422 Returns a nonzero value if @code{b} can be represented in a C
7423 @code{unsigned int}, zero otherwise.
7424 @item int bignum_fits_long_p(bignum b)
7425 Returns a nonzero value if @code{b} can be represented in a C
7426 @code{long int}, zero otherwise.
7427 @item int bignum_fits_ulong_p(bignum b)
7428 Returns a nonzero value if @code{b} can be represented in a C
7429 @code{unsigned long int}, zero otherwise.
7430 @item int bignum_fits_llong_p(bignum b)
7431 Returns a nonzero value if @code{b} can be represented in a C
7432 @code{long long int}, zero otherwise.
7433 @item int bignum_fits_ullong_p(bignum b)
7434 Returns a nonzero value if @code{b} can be represented in a C
7435 @code{unsigned long long int}, zero otherwise.
7436 @item void bignum_to_string(bignum b, int base)
7437 Converts @code{b} into a string representation using the given base,
7438 which is an integer between 2 and 36, inclusive.
7439 @item int bignum_to_int(bignum b)
7440 Converts @code{b} into a C @code{int}. If @code{b} does not fit into a
7441 C @code{int}, the results are undefined.
7442 @item unsigned int bignum_to_uint(bignum b)
7443 Converts @code{b} into a C @code{unsigned int}. If @code{b} does not
7444 fit into a C @code{unsigned int}, the results are undefined.
7445 @item long bignum_to_long(bignum b)
7446 Converts @code{b} into a C @code{long int}. If @code{b} does not fit
7447 into a C @code{long int}, the results are undefined.
7448 @item unsigned long bignum_to_ulong(bignum b)
7449 Converts @code{b} into a C @code{unsigned long int}. If @code{b} does
7450 not fit into a C @code{unsigned long int}, the results are undefined.
7451 @item long long bignum_to_llong(bignum b)
7452 Converts @code{b} into a C @code{long long int}. If @code{b} does not
7453 fit into a C @code{long long int}, the results are undefined.
7454 @item unsigned long long bignum_to_ullong(bignum b)
7455 Converts @code{b} into a C @code{unsigned long long int}. If @code{b}
7456 does not fit into a C @code{unsigned long long int}, the results are
7457 undefined.
7458 @item double bignum_to_double(bignum b)
7459 Converts @code{b} into a C @code{double}. If @code{b} is too large to
7460 represent as a C @code{double}, the results are implementation-specific.
7461 Typically, the result is positive or negative infinity, for
7462 implementations that can represent infinity.
7463 @item void bignum_set(bignum b1, bignum b2)
7464 Assigns the value of @code{b2} to the bignum @code{b1} by copying.
7465 @item void bignum_set_string(bignum b, const char *s, int base)
7466 Assigns @code{b} the value of the integer contained in string @code{s},
7467 which is a number in base @code{base}.
7468 @item void bignum_set_long(bignum b, long l)
7469 Assigns @code{b} the value of the long integer @code{l}.
7470 @item void bignum_set_ulong(bignum b, unsigned long l)
7471 Assigns @code{b} the value of the unsigned long integer @code{l}.
7472 @item void bignum_set_llong(bignum b, long long l)
7473 Assigns @code{b} the value of the long long integer @code{l}.
7474 @item void bignum_set_ullong(bignum b, unsigned long long l)
7475 Assigns @code{b} the value of the unsigned long long integer @code{l}.
7476 @item void bignum_set_double(bignum b, double d)
7477 Assigns @code{b} to the truncated value of @code{d}; i.e, the fractional
7478 part of @code{d} is dropped.
7479 @item void bignum_set_ratio(bignum b, ratio r)
7480 Assigns @code{b} to the truncated value of @code{r}; i.e., the
7481 non-integer part of @code{r} is dropped. This function exists only if
7482 the driver supports ratios.
7483 @item void bignum_set_bigfloat(bignum b, bigfloat f)
7484 Assigns @code{b} to the truncated value of @code{f}; i.e., the
7485 fractional part of @code{f} is dropped. This function exists only if
7486 the driver supports bigfloats.
7487 @item int bignum_cmp(bignum b1, bignum b2)
7488 Returns a positive value, zero, or a negative value as @code{b1} is
7489 greater than, equal to, or less than @code{b2}, respectively.
7490 @item int bignum_lt(bignum b1, bignum b2)
7491 Returns nonzero if @code{b1} is less than @code{b2}, zero otherwise.
7492 @item int bignum_le(bignum b1, bignum b2)
7493 Returns nonzero if @code{b1} is less than or equal to @code{b2}, zero
7494 otherwise.
7495 @item int bignum_eql(bignum b1, bignum b2)
7496 Returns nonzero if @code{b1} is equal to @code{b2}, zero otherwise.
7497 @item int bignum_ge(bignum b1, bignum b2)
7498 Returns nonzero if @code{b1} is greater than or equal to @code{b2}, zero
7499 otherwise.
7500 @item int bignum_gt(bignum b1, bignum b2)
7501 Returns nonzero if @code{b1} is greater than @code{b2}, zero otherwise.
7502 @item void bignum_neg(bignum b, bignum b2)
7503 Sets @code{b} to the negation of @code{b2}.
7504 @item void bignum_abs(bignum b, bignum b2)
7505 Sets @code{b} to the absolute value of @code{b2}.
7506 @item void bignum_add(bignum b, bignum b1, bignum b2)
7507 Sets @code{b} to the sum of @code{b1} and @code{b2}.
7508 @item void bignum_sub(bignum b, bignum b1, bignum b2)
7509 Sets @code{b} to the value of @code{b1} minus @code{b2}.
7510 @item void bignum_mul(bignum b, bignum b1, bignum b2)
7511 Sets @code{b} to the product of @code{b1} and @code{b2}.
7512 @item int bignum_divisible_p(bignum b1, bignum b2)
7513 Returns nonzero if @code{b1} is evenly divisible by @code{b2}.
7514 @item void bignum_div(bignum b, bignum b1, bignum b2)
7515 Sets @code{b} to the truncated value of @code{b1} divided by @code{b2}.
7516 That is, this function rounds toward zero.
7517 @item void bignum_ceil(bignum b, bignum b1, bignum b2)
7518 Sets @code{b} to the ceiling of @code{b1} divided by @code{b2}. That
7519 is, ths function rounds toward positive infinity.
7520 @item void bignum_floor(bignum b, bignum b1, bignum b2)
7521 Sets @code{b} to the floor of @code{b1} divided by @code{b2}. That is,
7522 ths function rounds toward negative infinity.
7523 @item void bignum_mod(bignum b, bignum b1, bignum b2)
7524 Sets @code{b} to @code{b1} mod @code{b2}; i.e., the remainder after
7525 dividing @code{b1} by @code{b2}. The sign is ignored; @code{b} is
7526 always nonnegative after this operation.
7527 @item void bignum_pow(bignum res, bignum b, unsigned int pow)
7528 Sets @code{res} to @code{b} to the @code{pow}th power.
7529 @item void bignum_gcd(bignum res, bignum b1, bignum b2)
7530 Sets @code{res} to the greatest common divisor of @code{b1} and
7531 @code{b2}.
7532 @item void bignum_lcm(bignum res, bignum b1, bignum b2)
7533 Sets @code{res} to the least common multiple of @code{b1} and @code{b2}.
7534 @item void bignum_and(bignum res, bignum b1, bignum b2)
7535 Sets @code{res} to the bitwise AND of @code{b1} and @code{b2}.
7536 @item void bignum_ior(bignum res, bignum b1, bignum b2)
7537 Sets @code{res} to the bitwise inclusive OR of @code{b1} and @code{b2}.
7538 @item void bignum_xor(bignum res, bignum b1, bignum b2)
7539 Sets @code{res} to the bitwise exclusive OR of @code{b1} and @code{b2}.
7540 @item void bignum_not(bignum res, bignum b)
7541 Sets @code{res} to the bitwise NOT of @code{b}.
7542 @item void bignum_setbit(bignum b, unsigned int bit)
7543 Sets the @code{bit}th bit of @code{b} to one, where the zeroth bit is
7544 the least significant.
7545 @item void bignum_clrbit(bignum b, unsigned int bit)
7546 Clears the @code{bit}th bit of @code{b} (i.e., sets it to zero), where
7547 the zeroth bit is the least significant.
7548 @item int bignum_testbit(bignum b, unsigned int bit)
7549 Returns the @code{bit}th bit of @code{b}, where the zeroth bit is the
7550 least significant.
7551 @item void bignum_lshift(bignum res, bignum b, unsigned int bits)
7552 Sets @code{res} to the value of @code{b} shifted left by @code{bits}
7553 bits.
7554 @item void bignum_rshift(bignum res, bignum b, unsigned int bits)
7555 Sets @code{res} to the value of @code{b} shifted right by @code{bits}
7556 bits.
7557 @item void bignum_random_seed(unsigned int seed)
7558 If the implementing library has its own pseudorandom number generator,
7559 then this function seeds the generator. If there is no generator, this
7560 function is a no-op.
7561 @item void bignum_random(bignum res, bignum limit)
7562 Sets @code{res} to a random number between zero (inclusive) and
7563 @code{limit} (exclusive).
7564 @end itemize
7565
7566 @node Ratio interface, Bigfloat interface, Bignum interface, Numeric driver interface
7567 @subsection Ratio interface
7568 @cindex ratio interface
7569
7570 Each ratio implementation defines @code{HAVE_RATIO} and an appropriate
7571 ratio type. For example, the GMP driver uses this definition:
7572
7573 @example
7574 typedef mpq_t ratio;
7575 @end example
7576
7577 The following names are defined for each driver, either as real C
7578 functions or as C preprocessor macros.
7579 @itemize
7580 @item void ratio_init(ratio r)
7581 Does any necessary initialization before the ratio @code{r} can be
7582 used. This function typically allocates memory for the ratio.
7583 @item void ratio_fini(ratio r)
7584 Cleans up any resources held by the ratio @code{r}, typically
7585 deallocating the memory dedicated to that ratio. The object referred
7586 to by @code{r} must not be accessed after this call returns.
7587 @item unsigned int ratio_hashcode(ratio r)
7588 Returns a hash code for the ratio, suitable for use in XEmacs hash
7589 tables.
7590 @item int ratio_sign(ratio r)
7591 Returns a positive value, zero, or a negative value to indicate that
7592 @code{r} is positive, zero, or negative, respectively.
7593 @item bignum ratio_numerator(ratio r)
7594 Returns the numerator of @code{r}.
7595 @item bignum ratio_denominator(ratio r)
7596 Returns the denominator of @code{r}.
7597 @item void ratio_canonicalize(ratio r)
7598 Removes any common factors from the numerator and denominator of
7599 @code{r}.
7600 @item void ratio_to_string(ratio r, int base)
7601 Converts @code{r} into a string representation using the given base,
7602 which is an integer between 2 and 36, inclusive.
7603 @item int ratio_to_int(ratio r)
7604 Converts @code{r} into a C @code{int} by truncating the ratio. If the
7605 truncation of @code{r} does not fit into a C @code{int}, the results are
7606 undefined.
7607 @item unsigned int ratio_to_uint(ratio r)
7608 Converts @code{r} into a C @code{unsigned int} by truncating the ratio.
7609 If the truncation of @code{r} does not fit into a C @code{unsigned int},
7610 the results are undefined.
7611 @item long ratio_to_long(ratio r)
7612 Converts @code{r} into a C @code{long int} by truncating the ratio. If
7613 the truncation of @code{r} does not fit into a C @code{long int}, the
7614 results are undefined.
7615 @item unsigned long ratio_to_ulong(ratio r)
7616 Converts @code{r} into a C @code{unsigned long int} by truncating the
7617 ratio. If @code{r} does not fit into a C @code{unsigned long int}, the
7618 results are undefined.
7619 @item double ratio_to_double(ratio r)
7620 Converts @code{r} into a C @code{double}. If @code{r} is too large to
7621 represent as a C @code{double}, the results are implementation-specific.
7622 Typically, the result is positive or negative infinity, for
7623 implementations that can represent infinity.
7624 @item void ratio_set(ratio r1, ratio r2)
7625 Assigns the value of @code{r2} to the ratio @code{r1} by copying.
7626 @item void ratio_set_string(ratio r, const char *s, int base)
7627 Assigns @code{r} the value of the ratio contained in string @code{s},
7628 which is a pair of numbers in base @code{base} separated by a forward
7629 slash.
7630 @item void ratio_set_long(ratio r, long l)
7631 Assigns @code{r} the value of the long integer @code{l}.
7632 @item void ratio_set_ulong(ratio r, unsigned long l)
7633 Assigns @code{r} the value of the unsigned long integer @code{l}.
7634 @item void ratio_set_double(ratio r, double d)
7635 Assigns @code{r} to the exact value of @code{d}. There is no rounding.
7636 @item void ratio_set_bignum(ratio r, bignum b)
7637 Assigns @code{r} to the value of @code{b}; i.e., the denominator is set
7638 to one.
7639 @item void ratio_set_bigfloat(ratio b, bigfloat f)
7640 Assigns @code{b} to the exact value of @code{f}. There is no rounding.
7641 This function exists only if the driver supports bigfloats.
7642 @item void ratio_set_long_ulong(ratio r, long num, unsigned long den)
7643 Assigns @code{r} the canonicalized ratio resulting from the division of
7644 @code{num} by @code{den}.
7645 @item void ratio_set_ulong_ulong(ratio r, unsigned long num, unsigned long den)
7646 Assigns @code{r} the canonicalized ratio resulting from the division of
7647 @code{num} by @code{den}.
7648 @item void ratio_set_bignum_bignum(ratio r, bignum num, bignum den)
7649 Assigns @code{r} the canonicalized ratio resulting from the division of
7650 @code{num} by @code{den}.
7651 @item int ratio_cmp(ratio r1, ratio r2)
7652 Returns a positive value, zero, or a negative value as @code{r1} is
7653 greater than, equal to, or less than @code{r2}, respectively.
7654 @item int ratio_lt(ratio r1, ratio r2)
7655 Returns nonzero if @code{r1} is less than @code{r2}, zero otherwise.
7656 @item int ratio_le(ratio r1, ratio r2)
7657 Returns nonzero if @code{r1} is less than or equal to @code{r2}, zero
7658 otherwise.
7659 @item int ratio_eql(ratio r1, ratio r2)
7660 Returns nonzero if @code{r1} is equal to @code{r2}, zero otherwise.
7661 @item int ratio_ge(ratio r1, ratio r2)
7662 Returns nonzero if @code{r1} is greater than or equal to @code{r2}, zero
7663 otherwise.
7664 @item int ratio_gt(ratio r1, ratio r2)
7665 Returns nonzero if @code{r1} is greater than @code{r2}, zero otherwise.
7666 @item void ratio_neg(ratio q, ratio q2)
7667 Sets @code{q} to the negation of @code{q2}.
7668 @item void ratio_abs(ratio q, ratio q2)
7669 Sets @code{q} to the absolute value of @code{q2}.
7670 @item void ratio_inv(ratio q, ratio q2)
7671 Sets @code{q} to the inverse of @code{q2}.
7672 @item void ratio_add(ratio res, ratio q1, ratio q2)
7673 Sets @code{res} to the sum of @code{q1} and @code{q2}.
7674 @item void ratio_sub(ratio res, ratio q1, ratio q2)
7675 Sets @code{res} to the value of @code{q1} minus @code{q2}.
7676 @item void ratio_mul(ratio res, ratio q1, ratio q2)
7677 Sets @code{res} to the product of @code{q1} and @code{q2}.
7678 @item void ratio_div(ratio res, ratio q1, ratio q2)
7679 Sets @code{res} to the value of @code{q1} divided by @code{q2}.
7680 @end itemize
7681
7682 @node Bigfloat interface, , Ratio interface, Numeric driver interface
7683 @subsection Bigfloat interface
7684 @cindex bigfloat interface
7685
7686 Each bigfloat implementation defines @code{HAVE_BIGFLOAT} and an
7687 appropriate bigfloat type. For example, the GMP driver uses this
7688 definition:
7689
7690 @example
7691 typedef mpf_t bigfloat;
7692 @end example
7693
7694 The following names are defined for each driver, either as real C
7695 functions or as C preprocessor macros.
7696 @itemize
7697 @item void bigfloat_init(bigfloat f)
7698 Does any necessary initialization before the bigfloat @code{f} can be
7699 used. This function typically allocates memory for the bigfloat.
7700 @item void bigfloat_init_prec(bigfloat f, unsigned int prec)
7701 Like @code{bigfloat_init}, but also sets the precision of @code{f} to
7702 @emph{at least} @code{prec} bits.
7703 @item void bigfloat_fini(bigfloat f)
7704 Cleans up any resources held by the bigfloat @code{f}, typically
7705 deallocating the memory dedicated to that bigfloat. The object referred
7706 to by @code{f} must not be accessed after this call returns.
7707 @item unsigned int bigfloat_hashcode(bigfloat f)
7708 Returns a hash code for the bigfloat, suitable for use in XEmacs hash
7709 tables.
7710 @item int bigfloat_sign(bigfloat f)
7711 Returns a positive value, zero, or a negative value to indicate that
7712 @code{f} is positive, zero, or negative, respectively.
7713 @item unsigned int bigfloat_get_prec(bigfloat f)
7714 Returns the precision of @code{f} in bits.
7715 @item void bigfloat_set_prec(bigfloat f, unsigned int prec)
7716 Sets the precision of @code{f} to @emph{at least} @code{prec} bits.
7717 @item void bigfloat_set_default_prec(unsigned int prec)
7718 Sets the default precision of newly created bigfloats.
7719 @item unsigned int bigfloat_get_default_prec(void)
7720 Gets the default precision of newly created bigfloats.
7721 @item void bigfloat_to_string(bigfloat f, int base)
7722 Converts @code{f} into a string representation using the given base,
7723 which is an integer between 2 and 36, inclusive.
7724 @item int bigfloat_to_int(bigfloat f)
7725 Converts @code{f} into a C @code{int} by truncating the bigfloat. If the
7726 truncation of @code{f} does not fit into a C @code{int}, the results are
7727 undefined.
7728 @item unsigned int bigfloat_to_uint(bigfloat f)
7729 Converts @code{f} into a C @code{unsigned int} by truncating the bigfloat.
7730 If the truncation of @code{f} does not fit into a C @code{unsigned int},
7731 the results are undefined.
7732 @item long bigfloat_to_long(bigfloat f)
7733 Converts @code{f} into a C @code{long int} by truncating the bigfloat. If
7734 the truncation of @code{f} does not fit into a C @code{long int}, the
7735 results are undefined.
7736 @item unsigned long bigfloat_to_ulong(bigfloat f)
7737 Converts @code{f} into a C @code{unsigned long int} by truncating the
7738 bigfloat. If @code{f} does not fit into a C @code{unsigned long int}, the
7739 results are undefined.
7740 @item double bigfloat_to_double(bigfloat f)
7741 Converts @code{f} into a C @code{double}. If @code{f} is too large to
7742 represent as a C @code{double}, the results are implementation-specific.
7743 Typically, the result is positive or negative infinity, for
7744 implementations that can represent infinity.
7745 @item void bigfloat_set(bigfloat f1, bigfloat f2)
7746 Assigns the value of @code{f2} to the bigfloat @code{f1} by copying.
7747 @item void bigfloat_set_string(bigfloat f, const char *s, int base)
7748 Assigns @code{f} the value of the bigfloat contained in string @code{s}.
7749 @item void bigfloat_set_long(bigfloat f, long l)
7750 Assigns @code{f} the value of the long integer @code{l}.
7751 @item void bigfloat_set_ulong(bigfloat f, unsigned long l)
7752 Assigns @code{f} the value of the unsigned long integer @code{l}.
7753 @item void bigfloat_set_double(bigfloat f, double d)
7754 Assigns @code{f} the value of @code{d}.
7755 @item void bigfloat_set_bignum(bigfloat f, bignum b)
7756 Assigns @code{f} to the value of @code{b}.
7757 @item void bigfloat_set_ratio(bigfloat b, ratio r)
7758 Assigns @code{b} to the result of dividing the numerator of @code{r} by
7759 its denominator.
7760 @item int bigfloat_cmp(bigfloat f1, bigfloat f2)
7761 Returns a positive value, zero, or a negative value as @code{f1} is
7762 greater than, equal to, or less than @code{f2}, respectively.
7763 @item int bigfloat_lt(bigfloat f1, bigfloat f2)
7764 Returns nonzero if @code{f1} is less than @code{f2}, zero otherwise.
7765 @item int bigfloat_le(bigfloat f1, bigfloat f2)
7766 Returns nonzero if @code{f1} is less than or equal to @code{f2}, zero
7767 otherwise.
7768 @item int bigfloat_eql(bigfloat f1, bigfloat f2)
7769 Returns nonzero if @code{f1} is equal to @code{f2}, zero otherwise.
7770 @item int bigfloat_ge(bigfloat f1, bigfloat f2)
7771 Returns nonzero if @code{f1} is greater than or equal to @code{f2}, zero
7772 otherwise.
7773 @item int bigfloat_gt(bigfloat f1, bigfloat f2)
7774 Returns nonzero if @code{f1} is greater than @code{f2}, zero otherwise.
7775 @item void bigfloat_neg(bigfloat f, bigfloat f2)
7776 Sets @code{f} to the negation of @code{f2}.
7777 @item void bigfloat_abs(bigfloat f, bigfloat f2)
7778 Sets @code{f} to the absolute value of @code{f2}.
7779 @item void bigfloat_add(bigfloat res, bigfloat f1, bigfloat f2)
7780 Sets @code{res} to the sum of @code{f1} and @code{f2}.
7781 @item void bigfloat_sub(bigfloat res, bigfloat f1, bigfloat f2)
7782 Sets @code{res} to the value of @code{f1} minus @code{f2}.
7783 @item void bigfloat_mul(bigfloat res, bigfloat f1, bigfloat f2)
7784 Sets @code{res} to the product of @code{f1} and @code{f2}.
7785 @item void bigfloat_div(bigfloat res, bigfloat f1, bigfloat f2)
7786 Sets @code{res} to the value of @code{f1} divided by @code{f2}.
7787 @item void bigfloat_ceil(bigfloat res, bigfloat f)
7788 Sets @code{res} to the ceiling of @code{f}.
7789 @item void bigfloat_floor(bigfloat res, bigfloat f)
7790 Sets @code{res} to the floor of @code{f}.
7791 @item void bigfloat_trunc(bigfloat res, bigfloat f)
7792 Sets @code{res} to the truncation of @code{f}.
7793 @item void bigfloat_sqrt(bigfloat res, bigfloat f)
7794 Sets @code{res} to the square root of @code{f}.
7795 @item void bigfloat_pow(bigfloat res, bigfloat f, unsigned int exp)
7796 Sets @code{res} to the value of @code{f} raised to the @code{exp}th power.
7797 @end itemize
7798
7799 @node Low-Level Allocation, The XEmacs Object System (Abstractly Speaking), Numeric Types, Top
7241 @chapter Low-Level Allocation 7800 @chapter Low-Level Allocation
7242 @cindex low-level allocation 7801 @cindex low-level allocation
7243 @cindex allocation, low-level 7802 @cindex allocation, low-level
7244 7803
7245 @menu 7804 @menu
21335 * Ben's separate stderr notes:: Probably obsolete. 21894 * Ben's separate stderr notes:: Probably obsolete.
21336 @end menu 21895 @end menu
21337 21896
21338 21897
21339 @node Ben's separate stderr notes, , Subprocesses, Subprocesses 21898 @node Ben's separate stderr notes, , Subprocesses, Subprocesses
21340 @subsection Ben's separate stderr notes (probably obsolete) 21899 @section Ben's separate stderr notes (probably obsolete)
21341 21900
21342 This node contains some notes that Ben kept on his separate subprocess 21901 This node contains some notes that Ben kept on his separate subprocess
21343 workspace. These notes probably describe changes and features that have 21902 workspace. These notes probably describe changes and features that have
21344 already been included in XEmacs 21.5; somebody should check and/or ask 21903 already been included in XEmacs 21.5; somebody should check and/or ask
21345 Ben. 21904 Ben.