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 void *malloc (size_t);
42 void *realloc (void *, size_t);
45 extern void * (*_mp_allocate_func) (size_t);
46 extern void * (*_mp_reallocate_func) (void *, size_t, size_t);
47 extern void (*_mp_free_func) (void *, size_t);
49 void *_mp_default_allocate (size_t);
50 void *_mp_default_reallocate (void *, size_t, size_t);
51 void _mp_default_free (void *, size_t);
53 char *_mpz_get_str (char *, int, const MP_INT *);
54 int _mpz_set_str (MP_INT *, const char *, int);
55 void _mpz_impl_sqrt (MP_INT *, MP_INT *, const MP_INT *);
57 #define const /* Empty */
58 #define signed /* Empty */
64 extern void * (*_mp_allocate_func) ();
65 extern void * (*_mp_reallocate_func) ();
66 extern void (*_mp_free_func) ();
68 void *_mp_default_allocate ();
69 void *_mp_default_reallocate ();
70 void _mp_default_free ();
72 char *_mpz_get_str ();
74 void _mpz_impl_sqrt ();
77 /* Copy NLIMBS *limbs* from SRC to DST. */
78 #define MPN_COPY(DST, SRC, NLIMBS) \
81 for (i = 0; i < (NLIMBS); i++) \
82 (DST)[i] = (SRC)[i]; \
84 /* Zero NLIMBS *limbs* AT DST. */
85 #define MPN_ZERO(DST, NLIMBS) \
88 for (i = 0; i < (NLIMBS); i++) \
92 /* Initialize the MP_INT X with space for NLIMBS limbs.
93 X should be a temporary variable, and it will be automatically
94 cleared out when the running function returns. */
95 #define MPZ_TMP_INIT(X, NLIMBS) \
97 (X)->alloc = (NLIMBS); \
98 (X)->d = (mp_ptr) alloca ((NLIMBS) * BYTES_PER_MP_LIMB); \
101 /* Structure for conversion between internal binary format and
102 strings in base 2..36. */
105 /* Number of digits in the conversion base that always fits in
106 an mp_limb. For example, for base 10 this is 10, since
107 2**32 = 4294967296 has ten digits. */
110 /* big_base is conversion_base**chars_per_limb, i.e. the biggest
111 number that fits a word, built by factors of conversion_base.
112 Exception: For 2, 4, 8, etc, big_base is log2(base), i.e. the
113 number of bits used to represent each digit in the base. */
116 /* big_base_inverted is a BITS_PER_MP_LIMB bit approximation to
117 1/big_base, represented as a fixed-point number. Instead of
118 dividing by big_base an application can choose to multiply
119 by big_base_inverted. */
120 mp_limb big_base_inverted;
122 /* log(2)/log(conversion_base) */
123 float chars_per_bit_exactly;
126 extern const struct bases __mp_bases[37];