1 /* Include file for internal GNU MP types and definitions.
3 Copyright (C) 1991 Free Software Foundation, Inc.
5 This file is part of the GNU MP Library.
7 The GNU MP Library is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 The GNU MP Library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with the GNU MP Library; see the file COPYING. If not, write to
19 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
21 #if defined (__GNUC__) || defined (__sparc__) || defined (sparc)
22 #define alloca __builtin_alloca
29 #if defined (__GNUC__)
30 volatile void abort (void);
32 #define inline /* Empty */
36 #define ABS(x) (x >= 0 ? x : -x)
38 #include "gmp-mparam.h"
41 Cosmetic, but when running mkdependC on this under linux-2.x,
42 we're warned about redefinition of signed (done in sys/cdefs.h).
43 To avoid this wibble, we've weakened the #if below.
45 #if defined(__STDC__) || defined(__linux__)
46 void *malloc (size_t);
47 void *realloc (void *, size_t);
50 extern void * (*_mp_allocate_func) (size_t);
51 extern void * (*_mp_reallocate_func) (void *, size_t, size_t);
52 extern void (*_mp_free_func) (void *, size_t);
54 void *_mp_default_allocate (size_t);
55 void *_mp_default_reallocate (void *, size_t, size_t);
56 void _mp_default_free (void *, size_t);
58 char *_mpz_get_str (char *, int, const MP_INT *);
59 int _mpz_set_str (MP_INT *, const char *, int);
60 void _mpz_impl_sqrt (MP_INT *, MP_INT *, const MP_INT *);
62 #define const /* Empty */
63 #define signed /* Empty */
69 extern void * (*_mp_allocate_func) ();
70 extern void * (*_mp_reallocate_func) ();
71 extern void (*_mp_free_func) ();
73 void *_mp_default_allocate ();
74 void *_mp_default_reallocate ();
75 void _mp_default_free ();
77 char *_mpz_get_str ();
79 void _mpz_impl_sqrt ();
82 /* Copy NLIMBS *limbs* from SRC to DST. */
83 #define MPN_COPY(DST, SRC, NLIMBS) \
86 for (i = 0; i < (NLIMBS); i++) \
87 (DST)[i] = (SRC)[i]; \
89 /* Zero NLIMBS *limbs* AT DST. */
90 #define MPN_ZERO(DST, NLIMBS) \
93 for (i = 0; i < (NLIMBS); i++) \
97 /* Initialize the MP_INT X with space for NLIMBS limbs.
98 X should be a temporary variable, and it will be automatically
99 cleared out when the running function returns. */
100 #define MPZ_TMP_INIT(X, NLIMBS) \
102 (X)->alloc = (NLIMBS); \
103 (X)->d = (mp_ptr) alloca ((NLIMBS) * BYTES_PER_MP_LIMB); \
106 /* Structure for conversion between internal binary format and
107 strings in base 2..36. */
110 /* Number of digits in the conversion base that always fits in
111 an mp_limb. For example, for base 10 this is 10, since
112 2**32 = 4294967296 has ten digits. */
115 /* big_base is conversion_base**chars_per_limb, i.e. the biggest
116 number that fits a word, built by factors of conversion_base.
117 Exception: For 2, 4, 8, etc, big_base is log2(base), i.e. the
118 number of bits used to represent each digit in the base. */
121 /* big_base_inverted is a BITS_PER_MP_LIMB bit approximation to
122 1/big_base, represented as a fixed-point number. Instead of
123 dividing by big_base an application can choose to multiply
124 by big_base_inverted. */
125 mp_limb big_base_inverted;
127 /* log(2)/log(conversion_base) */
128 float chars_per_bit_exactly;
131 extern const struct bases __mp_bases[37];