Upgrade MPFR from 2.4.1 to 2.4.2-p3 on the vendor branch.
[dragonfly.git] / contrib / mpfr / get_str.c
1 /* mpfr_get_str -- output a floating-point number to a string
2
3 Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
4 Contributed by the Arenaire and Cacao projects, INRIA.
5 Contributed by Alain Delplanque and Paul Zimmermann.
6
7 This file is part of the GNU MPFR Library.
8
9 The GNU MPFR Library is free software; you can redistribute it and/or modify
10 it under the terms of the GNU Lesser General Public License as published by
11 the Free Software Foundation; either version 2.1 of the License, or (at your
12 option) any later version.
13
14 The GNU MPFR Library is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16 or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
17 License for more details.
18
19 You should have received a copy of the GNU Lesser General Public License
20 along with the GNU MPFR Library; see the file COPYING.LIB.  If not, write to
21 the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
22 MA 02110-1301, USA. */
23
24 #define MPFR_NEED_LONGLONG_H
25 #include "mpfr-impl.h"
26
27 static int mpfr_get_str_aux (char *const, mp_exp_t *const, mp_limb_t *const,
28                        mp_size_t, mp_exp_t, long, int, size_t, mp_rnd_t);
29
30 /* The implicit \0 is useless, but we do not write num_to_text[36]
31    otherwise g++ complains. */
32 static const char num_to_text[] = "0123456789abcdefghijklmnopqrstuvwxyz";
33
34 /* copy most important limbs of {op, n2} in {rp, n1} */
35 /* if n1 > n2 put 0 in low limbs of {rp, n1} */
36 #define MPN_COPY2(rp, n1, op, n2) \
37   if ((n1) <= (n2)) \
38     { \
39       MPN_COPY ((rp), (op) + (n2) - (n1), (n1)); \
40     } \
41   else \
42     { \
43       MPN_COPY ((rp) + (n1) - (n2), (op), (n2)); \
44       MPN_ZERO ((rp), (n1) - (n2)); \
45     }
46
47 #define MPFR_ROUND_FAILED 3
48
49 /* Input: an approximation r*2^f of a real Y, with |r*2^f-Y| <= 2^(e+f).
50    Returns if possible in the string s the mantissa corresponding to
51    the integer nearest to Y, within the direction rnd, and returns the
52    exponent in exp.
53    n is the number of limbs of r.
54    e represents the maximal error in the approximation of Y
55       (e < 0 iff the approximation is exact, i.e., r*2^f = Y).
56    b is the wanted base (2 <= b <= 36).
57    m is the number of wanted digits in the mantissa.
58    rnd is the rounding mode.
59    It is assumed that b^(m-1) <= Y < b^(m+1), thus the returned value
60    satisfies b^(m-1) <= rnd(Y) < b^(m+1).
61
62    Rounding may fail for two reasons:
63    - the error is too large to determine the integer N nearest to Y
64    - either the number of digits of N in base b is too large (m+1),
65      N=2*N1+(b/2) and the rounding mode is to nearest. This can
66      only happen when b is even.
67
68    Return value:
69    - the direction of rounding (-1, 0, 1) if rounding is possible
70    - -MPFR_ROUND_FAILED if rounding not possible because m+1 digits
71    - MPFR_ROUND_FAILED otherwise (too large error)
72 */
73 static int
74 mpfr_get_str_aux (char *const str, mp_exp_t *const exp, mp_limb_t *const r,
75                   mp_size_t n, mp_exp_t f, long e, int b, size_t m,
76                   mp_rnd_t rnd)
77 {
78   int dir;                  /* direction of the rounded result */
79   mp_limb_t ret = 0;        /* possible carry in addition */
80   mp_size_t i0, j0;         /* number of limbs and bits of Y */
81   unsigned char *str1;      /* string of m+2 characters */
82   size_t size_s1;           /* length of str1 */
83   mp_rnd_t rnd1;
84   size_t i;
85   int exact = (e < 0);
86   MPFR_TMP_DECL(marker);
87
88   /* if f > 0, then the maximal error 2^(e+f) is larger than 2 so we can't
89      determine the integer Y */
90   MPFR_ASSERTN(f <= 0);
91   /* if f is too small, then r*2^f is smaller than 1 */
92   MPFR_ASSERTN(f > (-n * BITS_PER_MP_LIMB));
93
94   MPFR_TMP_MARK(marker);
95
96   /* R = 2^f sum r[i]K^(i)
97      r[i] = (r_(i,k-1)...r_(i,0))_2
98      R = sum r(i,j)2^(j+ki+f)
99      the bits from R are referenced by pairs (i,j) */
100
101   /* check if is possible to round r with rnd mode
102      where |r*2^f-Y| <= 2^(e+f)
103      the exponent of R is: f + n*BITS_PER_MP_LIMB
104      we must have e + f == f + n*BITS_PER_MP_LIMB - err
105      err = n*BITS_PER_MP_LIMB - e
106      R contains exactly -f bits after the integer point:
107      to determine the nearest integer, we thus need a precision of
108      n * BITS_PER_MP_LIMB + f */
109
110   if (exact || mpfr_can_round_raw (r, n, (mp_size_t) 1,
111             n * BITS_PER_MP_LIMB - e, GMP_RNDN, rnd, n * BITS_PER_MP_LIMB + f))
112     {
113       /* compute the nearest integer to R */
114
115       /* bit of weight 0 in R has position j0 in limb r[i0] */
116       i0 = (-f) / BITS_PER_MP_LIMB;
117       j0 = (-f) % BITS_PER_MP_LIMB;
118
119       ret = mpfr_round_raw (r + i0, r, n * BITS_PER_MP_LIMB, 0,
120                             n * BITS_PER_MP_LIMB + f, rnd, &dir);
121       MPFR_ASSERTD(dir != MPFR_ROUND_FAILED);
122
123       /* warning: mpfr_round_raw_generic returns MPFR_EVEN_INEX (2) or
124          -MPFR_EVEN_INEX (-2) in case of even rounding */
125
126       if (ret) /* Y is a power of 2 */
127         {
128           if (j0)
129             r[n - 1] = MPFR_LIMB_HIGHBIT >> (j0 - 1);
130           else /* j0=0, necessarily i0 >= 1 otherwise f=0 and r is exact */
131             {
132               r[n - 1] = ret;
133               r[--i0] = 0; /* set to zero the new low limb */
134             }
135         }
136       else /* shift r to the right by (-f) bits (i0 already done) */
137         {
138           if (j0)
139             mpn_rshift (r + i0, r + i0, n - i0, j0);
140         }
141
142       /* now the rounded value Y is in {r+i0, n-i0} */
143
144       /* convert r+i0 into base b */
145       str1 = (unsigned char*) MPFR_TMP_ALLOC (m + 3); /* need one extra character for mpn_get_str */
146       size_s1 = mpn_get_str (str1, b, r + i0, n - i0);
147
148       /* round str1 */
149       MPFR_ASSERTN(size_s1 >= m);
150       *exp = size_s1 - m; /* number of superfluous characters */
151
152       /* if size_s1 = m + 2, necessarily we have b^(m+1) as result,
153          and the result will not change */
154
155       /* so we have to double-round only when size_s1 = m + 1 and
156          (i) the result is inexact
157          (ii) or the last digit is non-zero */
158       if ((size_s1 == m + 1) && ((dir != 0) || (str1[size_s1 - 1] != 0)))
159         {
160           /* rounding mode */
161           rnd1 = rnd;
162
163           /* round to nearest case */
164           if (rnd == GMP_RNDN)
165             {
166               if (2 * str1[size_s1 - 1] == b)
167                 {
168                   if (dir == 0 && exact) /* exact: even rounding */
169                     {
170                       rnd1 = ((str1[size_s1 - 2] & 1) == 0)
171                         ? GMP_RNDD : GMP_RNDU;
172                     }
173                   else
174                     {
175                       /* otherwise we cannot round correctly: for example
176                          if b=10, we might have a mantissa of
177                          xxxxxxx5.00000000 which can be rounded to nearest
178                          to 8 digits but not to 7 */
179                       dir = -MPFR_ROUND_FAILED;
180                       MPFR_ASSERTD(dir != MPFR_EVEN_INEX);
181                       goto free_and_return;
182                     }
183                 }
184               else if (2 * str1[size_s1 - 1] < b)
185                 rnd1 = GMP_RNDD;
186               else
187                 rnd1 = GMP_RNDU;
188             }
189
190           /* now rnd1 is either GMP_RNDD or GMP_RNDZ -> truncate
191                              or GMP_RDNU -> round toward infinity */
192
193           /* round away from zero */
194           if (rnd1 == GMP_RNDU)
195             {
196               if (str1[size_s1 - 1] != 0)
197                 {
198                   /* the carry cannot propagate to the whole string, since
199                      Y = x*b^(m-g) < 2*b^m <= b^(m+1)-b
200                      where x is the input float */
201                   MPFR_ASSERTN(size_s1 >= 2);
202                   i = size_s1 - 2;
203                   while (str1[i] == b - 1)
204                     {
205                       MPFR_ASSERTD(i > 0);
206                       str1[i--] = 0;
207                     }
208                   str1[i]++;
209                 }
210               dir = 1;
211             }
212           /* round toward zero (truncate) */
213           else
214             dir = -1;
215         }
216
217       /* copy str1 into str and convert to characters (digits and
218          lowercase letters from the source character set) */
219       for (i = 0; i < m; i++)
220         str[i] = num_to_text[(int) str1[i]]; /* str1[i] is an unsigned char */
221       str[m] = 0;
222     }
223   /* mpfr_can_round_raw failed: rounding is not possible */
224   else
225     {
226       dir = MPFR_ROUND_FAILED; /* should be different from MPFR_EVEN_INEX */
227       MPFR_ASSERTD(dir != MPFR_EVEN_INEX);
228     }
229
230  free_and_return:
231   MPFR_TMP_FREE(marker);
232
233   return dir;
234 }
235
236 /***************************************************************************
237  * __gmpfr_l2b[b-2][0] is a 23-bit upper approximation to log(b)/log(2),   *
238  * __gmpfr_l2b[b-2][1] is a 76-bit upper approximation to log(2)/log(b).   *
239  * The following code is generated by tests/tl2b (with an argument).       *
240  ***************************************************************************/
241
242 #if 0
243 #elif BITS_PER_MP_LIMB == 16
244 const mp_limb_t mpfr_l2b_2_0__tab[] = { 0x0000, 0x8000 };
245 #elif BITS_PER_MP_LIMB == 32
246 const mp_limb_t mpfr_l2b_2_0__tab[] = { 0x80000000 };
247 #elif BITS_PER_MP_LIMB == 64
248 const mp_limb_t mpfr_l2b_2_0__tab[] = { 0x8000000000000000 };
249 #elif BITS_PER_MP_LIMB == 96
250 const mp_limb_t mpfr_l2b_2_0__tab[] = { 0x800000000000000000000000 };
251 #elif BITS_PER_MP_LIMB == 128
252 const mp_limb_t mpfr_l2b_2_0__tab[] = { 0x80000000000000000000000000000000 };
253 #elif BITS_PER_MP_LIMB == 256
254 const mp_limb_t mpfr_l2b_2_0__tab[] = { 0x8000000000000000000000000000000000000000000000000000000000000000 };
255 #endif
256
257 #if 0
258 #elif BITS_PER_MP_LIMB == 16
259 const mp_limb_t mpfr_l2b_2_1__tab[] = { 0x0000, 0x0000, 0x0000, 0x0000, 0x8000 };
260 #elif BITS_PER_MP_LIMB == 32
261 const mp_limb_t mpfr_l2b_2_1__tab[] = { 0x00000000, 0x00000000, 0x80000000 };
262 #elif BITS_PER_MP_LIMB == 64
263 const mp_limb_t mpfr_l2b_2_1__tab[] = { 0x0000000000000000, 0x8000000000000000 };
264 #elif BITS_PER_MP_LIMB == 96
265 const mp_limb_t mpfr_l2b_2_1__tab[] = { 0x800000000000000000000000 };
266 #elif BITS_PER_MP_LIMB == 128
267 const mp_limb_t mpfr_l2b_2_1__tab[] = { 0x80000000000000000000000000000000 };
268 #elif BITS_PER_MP_LIMB == 256
269 const mp_limb_t mpfr_l2b_2_1__tab[] = { 0x8000000000000000000000000000000000000000000000000000000000000000 };
270 #endif
271
272 #if 0
273 #elif BITS_PER_MP_LIMB == 16
274 const mp_limb_t mpfr_l2b_3_0__tab[] = { 0x0e00, 0xcae0 };
275 #elif BITS_PER_MP_LIMB == 32
276 const mp_limb_t mpfr_l2b_3_0__tab[] = { 0xcae00e00 };
277 #elif BITS_PER_MP_LIMB == 64
278 const mp_limb_t mpfr_l2b_3_0__tab[] = { 0xcae00e0000000000 };
279 #elif BITS_PER_MP_LIMB == 96
280 const mp_limb_t mpfr_l2b_3_0__tab[] = { 0xcae00e000000000000000000 };
281 #elif BITS_PER_MP_LIMB == 128
282 const mp_limb_t mpfr_l2b_3_0__tab[] = { 0xcae00e00000000000000000000000000 };
283 #elif BITS_PER_MP_LIMB == 256
284 const mp_limb_t mpfr_l2b_3_0__tab[] = { 0xcae00e0000000000000000000000000000000000000000000000000000000000 };
285 #endif
286
287 #if 0
288 #elif BITS_PER_MP_LIMB == 16
289 const mp_limb_t mpfr_l2b_3_1__tab[] = { 0x0448, 0xe94e, 0xa9a9, 0x9cc1, 0xa184 };
290 #elif BITS_PER_MP_LIMB == 32
291 const mp_limb_t mpfr_l2b_3_1__tab[] = { 0x04480000, 0xa9a9e94e, 0xa1849cc1 };
292 #elif BITS_PER_MP_LIMB == 64
293 const mp_limb_t mpfr_l2b_3_1__tab[] = { 0x0448000000000000, 0xa1849cc1a9a9e94e };
294 #elif BITS_PER_MP_LIMB == 96
295 const mp_limb_t mpfr_l2b_3_1__tab[] = { 0xa1849cc1a9a9e94e04480000 };
296 #elif BITS_PER_MP_LIMB == 128
297 const mp_limb_t mpfr_l2b_3_1__tab[] = { 0xa1849cc1a9a9e94e0448000000000000 };
298 #elif BITS_PER_MP_LIMB == 256
299 const mp_limb_t mpfr_l2b_3_1__tab[] = { 0xa1849cc1a9a9e94e044800000000000000000000000000000000000000000000 };
300 #endif
301
302 #if 0
303 #elif BITS_PER_MP_LIMB == 16
304 const mp_limb_t mpfr_l2b_4_0__tab[] = { 0x0000, 0x8000 };
305 #elif BITS_PER_MP_LIMB == 32
306 const mp_limb_t mpfr_l2b_4_0__tab[] = { 0x80000000 };
307 #elif BITS_PER_MP_LIMB == 64
308 const mp_limb_t mpfr_l2b_4_0__tab[] = { 0x8000000000000000 };
309 #elif BITS_PER_MP_LIMB == 96
310 const mp_limb_t mpfr_l2b_4_0__tab[] = { 0x800000000000000000000000 };
311 #elif BITS_PER_MP_LIMB == 128
312 const mp_limb_t mpfr_l2b_4_0__tab[] = { 0x80000000000000000000000000000000 };
313 #elif BITS_PER_MP_LIMB == 256
314 const mp_limb_t mpfr_l2b_4_0__tab[] = { 0x8000000000000000000000000000000000000000000000000000000000000000 };
315 #endif
316
317 #if 0
318 #elif BITS_PER_MP_LIMB == 16
319 const mp_limb_t mpfr_l2b_4_1__tab[] = { 0x0000, 0x0000, 0x0000, 0x0000, 0x8000 };
320 #elif BITS_PER_MP_LIMB == 32
321 const mp_limb_t mpfr_l2b_4_1__tab[] = { 0x00000000, 0x00000000, 0x80000000 };
322 #elif BITS_PER_MP_LIMB == 64
323 const mp_limb_t mpfr_l2b_4_1__tab[] = { 0x0000000000000000, 0x8000000000000000 };
324 #elif BITS_PER_MP_LIMB == 96
325 const mp_limb_t mpfr_l2b_4_1__tab[] = { 0x800000000000000000000000 };
326 #elif BITS_PER_MP_LIMB == 128
327 const mp_limb_t mpfr_l2b_4_1__tab[] = { 0x80000000000000000000000000000000 };
328 #elif BITS_PER_MP_LIMB == 256
329 const mp_limb_t mpfr_l2b_4_1__tab[] = { 0x8000000000000000000000000000000000000000000000000000000000000000 };
330 #endif
331
332 #if 0
333 #elif BITS_PER_MP_LIMB == 16
334 const mp_limb_t mpfr_l2b_5_0__tab[] = { 0x7a00, 0x949a };
335 #elif BITS_PER_MP_LIMB == 32
336 const mp_limb_t mpfr_l2b_5_0__tab[] = { 0x949a7a00 };
337 #elif BITS_PER_MP_LIMB == 64
338 const mp_limb_t mpfr_l2b_5_0__tab[] = { 0x949a7a0000000000 };
339 #elif BITS_PER_MP_LIMB == 96
340 const mp_limb_t mpfr_l2b_5_0__tab[] = { 0x949a7a000000000000000000 };
341 #elif BITS_PER_MP_LIMB == 128
342 const mp_limb_t mpfr_l2b_5_0__tab[] = { 0x949a7a00000000000000000000000000 };
343 #elif BITS_PER_MP_LIMB == 256
344 const mp_limb_t mpfr_l2b_5_0__tab[] = { 0x949a7a0000000000000000000000000000000000000000000000000000000000 };
345 #endif
346
347 #if 0
348 #elif BITS_PER_MP_LIMB == 16
349 const mp_limb_t mpfr_l2b_5_1__tab[] = { 0x67b8, 0x9728, 0x287b, 0xa348, 0xdc81 };
350 #elif BITS_PER_MP_LIMB == 32
351 const mp_limb_t mpfr_l2b_5_1__tab[] = { 0x67b80000, 0x287b9728, 0xdc81a348 };
352 #elif BITS_PER_MP_LIMB == 64
353 const mp_limb_t mpfr_l2b_5_1__tab[] = { 0x67b8000000000000, 0xdc81a348287b9728 };
354 #elif BITS_PER_MP_LIMB == 96
355 const mp_limb_t mpfr_l2b_5_1__tab[] = { 0xdc81a348287b972867b80000 };
356 #elif BITS_PER_MP_LIMB == 128
357 const mp_limb_t mpfr_l2b_5_1__tab[] = { 0xdc81a348287b972867b8000000000000 };
358 #elif BITS_PER_MP_LIMB == 256
359 const mp_limb_t mpfr_l2b_5_1__tab[] = { 0xdc81a348287b972867b800000000000000000000000000000000000000000000 };
360 #endif
361
362 #if 0
363 #elif BITS_PER_MP_LIMB == 16
364 const mp_limb_t mpfr_l2b_6_0__tab[] = { 0x0800, 0xa570 };
365 #elif BITS_PER_MP_LIMB == 32
366 const mp_limb_t mpfr_l2b_6_0__tab[] = { 0xa5700800 };
367 #elif BITS_PER_MP_LIMB == 64
368 const mp_limb_t mpfr_l2b_6_0__tab[] = { 0xa570080000000000 };
369 #elif BITS_PER_MP_LIMB == 96
370 const mp_limb_t mpfr_l2b_6_0__tab[] = { 0xa57008000000000000000000 };
371 #elif BITS_PER_MP_LIMB == 128
372 const mp_limb_t mpfr_l2b_6_0__tab[] = { 0xa5700800000000000000000000000000 };
373 #elif BITS_PER_MP_LIMB == 256
374 const mp_limb_t mpfr_l2b_6_0__tab[] = { 0xa570080000000000000000000000000000000000000000000000000000000000 };
375 #endif
376
377 #if 0
378 #elif BITS_PER_MP_LIMB == 16
379 const mp_limb_t mpfr_l2b_6_1__tab[] = { 0xff10, 0xf9e9, 0xe054, 0x9236, 0xc611 };
380 #elif BITS_PER_MP_LIMB == 32
381 const mp_limb_t mpfr_l2b_6_1__tab[] = { 0xff100000, 0xe054f9e9, 0xc6119236 };
382 #elif BITS_PER_MP_LIMB == 64
383 const mp_limb_t mpfr_l2b_6_1__tab[] = { 0xff10000000000000, 0xc6119236e054f9e9 };
384 #elif BITS_PER_MP_LIMB == 96
385 const mp_limb_t mpfr_l2b_6_1__tab[] = { 0xc6119236e054f9e9ff100000 };
386 #elif BITS_PER_MP_LIMB == 128
387 const mp_limb_t mpfr_l2b_6_1__tab[] = { 0xc6119236e054f9e9ff10000000000000 };
388 #elif BITS_PER_MP_LIMB == 256
389 const mp_limb_t mpfr_l2b_6_1__tab[] = { 0xc6119236e054f9e9ff1000000000000000000000000000000000000000000000 };
390 #endif
391
392 #if 0
393 #elif BITS_PER_MP_LIMB == 16
394 const mp_limb_t mpfr_l2b_7_0__tab[] = { 0xb400, 0xb3ab };
395 #elif BITS_PER_MP_LIMB == 32
396 const mp_limb_t mpfr_l2b_7_0__tab[] = { 0xb3abb400 };
397 #elif BITS_PER_MP_LIMB == 64
398 const mp_limb_t mpfr_l2b_7_0__tab[] = { 0xb3abb40000000000 };
399 #elif BITS_PER_MP_LIMB == 96
400 const mp_limb_t mpfr_l2b_7_0__tab[] = { 0xb3abb4000000000000000000 };
401 #elif BITS_PER_MP_LIMB == 128
402 const mp_limb_t mpfr_l2b_7_0__tab[] = { 0xb3abb400000000000000000000000000 };
403 #elif BITS_PER_MP_LIMB == 256
404 const mp_limb_t mpfr_l2b_7_0__tab[] = { 0xb3abb40000000000000000000000000000000000000000000000000000000000 };
405 #endif
406
407 #if 0
408 #elif BITS_PER_MP_LIMB == 16
409 const mp_limb_t mpfr_l2b_7_1__tab[] = { 0x37b8, 0xa711, 0x754d, 0xc9d6, 0xb660 };
410 #elif BITS_PER_MP_LIMB == 32
411 const mp_limb_t mpfr_l2b_7_1__tab[] = { 0x37b80000, 0x754da711, 0xb660c9d6 };
412 #elif BITS_PER_MP_LIMB == 64
413 const mp_limb_t mpfr_l2b_7_1__tab[] = { 0x37b8000000000000, 0xb660c9d6754da711 };
414 #elif BITS_PER_MP_LIMB == 96
415 const mp_limb_t mpfr_l2b_7_1__tab[] = { 0xb660c9d6754da71137b80000 };
416 #elif BITS_PER_MP_LIMB == 128
417 const mp_limb_t mpfr_l2b_7_1__tab[] = { 0xb660c9d6754da71137b8000000000000 };
418 #elif BITS_PER_MP_LIMB == 256
419 const mp_limb_t mpfr_l2b_7_1__tab[] = { 0xb660c9d6754da71137b800000000000000000000000000000000000000000000 };
420 #endif
421
422 #if 0
423 #elif BITS_PER_MP_LIMB == 16
424 const mp_limb_t mpfr_l2b_8_0__tab[] = { 0x0000, 0xc000 };
425 #elif BITS_PER_MP_LIMB == 32
426 const mp_limb_t mpfr_l2b_8_0__tab[] = { 0xc0000000 };
427 #elif BITS_PER_MP_LIMB == 64
428 const mp_limb_t mpfr_l2b_8_0__tab[] = { 0xc000000000000000 };
429 #elif BITS_PER_MP_LIMB == 96
430 const mp_limb_t mpfr_l2b_8_0__tab[] = { 0xc00000000000000000000000 };
431 #elif BITS_PER_MP_LIMB == 128
432 const mp_limb_t mpfr_l2b_8_0__tab[] = { 0xc0000000000000000000000000000000 };
433 #elif BITS_PER_MP_LIMB == 256
434 const mp_limb_t mpfr_l2b_8_0__tab[] = { 0xc000000000000000000000000000000000000000000000000000000000000000 };
435 #endif
436
437 #if 0
438 #elif BITS_PER_MP_LIMB == 16
439 const mp_limb_t mpfr_l2b_8_1__tab[] = { 0xaab0, 0xaaaa, 0xaaaa, 0xaaaa, 0xaaaa };
440 #elif BITS_PER_MP_LIMB == 32
441 const mp_limb_t mpfr_l2b_8_1__tab[] = { 0xaab00000, 0xaaaaaaaa, 0xaaaaaaaa };
442 #elif BITS_PER_MP_LIMB == 64
443 const mp_limb_t mpfr_l2b_8_1__tab[] = { 0xaab0000000000000, 0xaaaaaaaaaaaaaaaa };
444 #elif BITS_PER_MP_LIMB == 96
445 const mp_limb_t mpfr_l2b_8_1__tab[] = { 0xaaaaaaaaaaaaaaaaaab00000 };
446 #elif BITS_PER_MP_LIMB == 128
447 const mp_limb_t mpfr_l2b_8_1__tab[] = { 0xaaaaaaaaaaaaaaaaaab0000000000000 };
448 #elif BITS_PER_MP_LIMB == 256
449 const mp_limb_t mpfr_l2b_8_1__tab[] = { 0xaaaaaaaaaaaaaaaaaab000000000000000000000000000000000000000000000 };
450 #endif
451
452 #if 0
453 #elif BITS_PER_MP_LIMB == 16
454 const mp_limb_t mpfr_l2b_9_0__tab[] = { 0x0e00, 0xcae0 };
455 #elif BITS_PER_MP_LIMB == 32
456 const mp_limb_t mpfr_l2b_9_0__tab[] = { 0xcae00e00 };
457 #elif BITS_PER_MP_LIMB == 64
458 const mp_limb_t mpfr_l2b_9_0__tab[] = { 0xcae00e0000000000 };
459 #elif BITS_PER_MP_LIMB == 96
460 const mp_limb_t mpfr_l2b_9_0__tab[] = { 0xcae00e000000000000000000 };
461 #elif BITS_PER_MP_LIMB == 128
462 const mp_limb_t mpfr_l2b_9_0__tab[] = { 0xcae00e00000000000000000000000000 };
463 #elif BITS_PER_MP_LIMB == 256
464 const mp_limb_t mpfr_l2b_9_0__tab[] = { 0xcae00e0000000000000000000000000000000000000000000000000000000000 };
465 #endif
466
467 #if 0
468 #elif BITS_PER_MP_LIMB == 16
469 const mp_limb_t mpfr_l2b_9_1__tab[] = { 0x0448, 0xe94e, 0xa9a9, 0x9cc1, 0xa184 };
470 #elif BITS_PER_MP_LIMB == 32
471 const mp_limb_t mpfr_l2b_9_1__tab[] = { 0x04480000, 0xa9a9e94e, 0xa1849cc1 };
472 #elif BITS_PER_MP_LIMB == 64
473 const mp_limb_t mpfr_l2b_9_1__tab[] = { 0x0448000000000000, 0xa1849cc1a9a9e94e };
474 #elif BITS_PER_MP_LIMB == 96
475 const mp_limb_t mpfr_l2b_9_1__tab[] = { 0xa1849cc1a9a9e94e04480000 };
476 #elif BITS_PER_MP_LIMB == 128
477 const mp_limb_t mpfr_l2b_9_1__tab[] = { 0xa1849cc1a9a9e94e0448000000000000 };
478 #elif BITS_PER_MP_LIMB == 256
479 const mp_limb_t mpfr_l2b_9_1__tab[] = { 0xa1849cc1a9a9e94e044800000000000000000000000000000000000000000000 };
480 #endif
481
482 #if 0
483 #elif BITS_PER_MP_LIMB == 16
484 const mp_limb_t mpfr_l2b_10_0__tab[] = { 0x7a00, 0xd49a };
485 #elif BITS_PER_MP_LIMB == 32
486 const mp_limb_t mpfr_l2b_10_0__tab[] = { 0xd49a7a00 };
487 #elif BITS_PER_MP_LIMB == 64
488 const mp_limb_t mpfr_l2b_10_0__tab[] = { 0xd49a7a0000000000 };
489 #elif BITS_PER_MP_LIMB == 96
490 const mp_limb_t mpfr_l2b_10_0__tab[] = { 0xd49a7a000000000000000000 };
491 #elif BITS_PER_MP_LIMB == 128
492 const mp_limb_t mpfr_l2b_10_0__tab[] = { 0xd49a7a00000000000000000000000000 };
493 #elif BITS_PER_MP_LIMB == 256
494 const mp_limb_t mpfr_l2b_10_0__tab[] = { 0xd49a7a0000000000000000000000000000000000000000000000000000000000 };
495 #endif
496
497 #if 0
498 #elif BITS_PER_MP_LIMB == 16
499 const mp_limb_t mpfr_l2b_10_1__tab[] = { 0x8f90, 0xf798, 0xfbcf, 0x9a84, 0x9a20 };
500 #elif BITS_PER_MP_LIMB == 32
501 const mp_limb_t mpfr_l2b_10_1__tab[] = { 0x8f900000, 0xfbcff798, 0x9a209a84 };
502 #elif BITS_PER_MP_LIMB == 64
503 const mp_limb_t mpfr_l2b_10_1__tab[] = { 0x8f90000000000000, 0x9a209a84fbcff798 };
504 #elif BITS_PER_MP_LIMB == 96
505 const mp_limb_t mpfr_l2b_10_1__tab[] = { 0x9a209a84fbcff7988f900000 };
506 #elif BITS_PER_MP_LIMB == 128
507 const mp_limb_t mpfr_l2b_10_1__tab[] = { 0x9a209a84fbcff7988f90000000000000 };
508 #elif BITS_PER_MP_LIMB == 256
509 const mp_limb_t mpfr_l2b_10_1__tab[] = { 0x9a209a84fbcff7988f9000000000000000000000000000000000000000000000 };
510 #endif
511
512 #if 0
513 #elif BITS_PER_MP_LIMB == 16
514 const mp_limb_t mpfr_l2b_11_0__tab[] = { 0x5400, 0xdd67 };
515 #elif BITS_PER_MP_LIMB == 32
516 const mp_limb_t mpfr_l2b_11_0__tab[] = { 0xdd675400 };
517 #elif BITS_PER_MP_LIMB == 64
518 const mp_limb_t mpfr_l2b_11_0__tab[] = { 0xdd67540000000000 };
519 #elif BITS_PER_MP_LIMB == 96
520 const mp_limb_t mpfr_l2b_11_0__tab[] = { 0xdd6754000000000000000000 };
521 #elif BITS_PER_MP_LIMB == 128
522 const mp_limb_t mpfr_l2b_11_0__tab[] = { 0xdd675400000000000000000000000000 };
523 #elif BITS_PER_MP_LIMB == 256
524 const mp_limb_t mpfr_l2b_11_0__tab[] = { 0xdd67540000000000000000000000000000000000000000000000000000000000 };
525 #endif
526
527 #if 0
528 #elif BITS_PER_MP_LIMB == 16
529 const mp_limb_t mpfr_l2b_11_1__tab[] = { 0xe170, 0x9d10, 0xeb22, 0x4e0e, 0x9400 };
530 #elif BITS_PER_MP_LIMB == 32
531 const mp_limb_t mpfr_l2b_11_1__tab[] = { 0xe1700000, 0xeb229d10, 0x94004e0e };
532 #elif BITS_PER_MP_LIMB == 64
533 const mp_limb_t mpfr_l2b_11_1__tab[] = { 0xe170000000000000, 0x94004e0eeb229d10 };
534 #elif BITS_PER_MP_LIMB == 96
535 const mp_limb_t mpfr_l2b_11_1__tab[] = { 0x94004e0eeb229d10e1700000 };
536 #elif BITS_PER_MP_LIMB == 128
537 const mp_limb_t mpfr_l2b_11_1__tab[] = { 0x94004e0eeb229d10e170000000000000 };
538 #elif BITS_PER_MP_LIMB == 256
539 const mp_limb_t mpfr_l2b_11_1__tab[] = { 0x94004e0eeb229d10e17000000000000000000000000000000000000000000000 };
540 #endif
541
542 #if 0
543 #elif BITS_PER_MP_LIMB == 16
544 const mp_limb_t mpfr_l2b_12_0__tab[] = { 0x0800, 0xe570 };
545 #elif BITS_PER_MP_LIMB == 32
546 const mp_limb_t mpfr_l2b_12_0__tab[] = { 0xe5700800 };
547 #elif BITS_PER_MP_LIMB == 64
548 const mp_limb_t mpfr_l2b_12_0__tab[] = { 0xe570080000000000 };
549 #elif BITS_PER_MP_LIMB == 96
550 const mp_limb_t mpfr_l2b_12_0__tab[] = { 0xe57008000000000000000000 };
551 #elif BITS_PER_MP_LIMB == 128
552 const mp_limb_t mpfr_l2b_12_0__tab[] = { 0xe5700800000000000000000000000000 };
553 #elif BITS_PER_MP_LIMB == 256
554 const mp_limb_t mpfr_l2b_12_0__tab[] = { 0xe570080000000000000000000000000000000000000000000000000000000000 };
555 #endif
556
557 #if 0
558 #elif BITS_PER_MP_LIMB == 16
559 const mp_limb_t mpfr_l2b_12_1__tab[] = { 0xfe28, 0x1c24, 0x0b03, 0x9c1a, 0x8ed1 };
560 #elif BITS_PER_MP_LIMB == 32
561 const mp_limb_t mpfr_l2b_12_1__tab[] = { 0xfe280000, 0x0b031c24, 0x8ed19c1a };
562 #elif BITS_PER_MP_LIMB == 64
563 const mp_limb_t mpfr_l2b_12_1__tab[] = { 0xfe28000000000000, 0x8ed19c1a0b031c24 };
564 #elif BITS_PER_MP_LIMB == 96
565 const mp_limb_t mpfr_l2b_12_1__tab[] = { 0x8ed19c1a0b031c24fe280000 };
566 #elif BITS_PER_MP_LIMB == 128
567 const mp_limb_t mpfr_l2b_12_1__tab[] = { 0x8ed19c1a0b031c24fe28000000000000 };
568 #elif BITS_PER_MP_LIMB == 256
569 const mp_limb_t mpfr_l2b_12_1__tab[] = { 0x8ed19c1a0b031c24fe2800000000000000000000000000000000000000000000 };
570 #endif
571
572 #if 0
573 #elif BITS_PER_MP_LIMB == 16
574 const mp_limb_t mpfr_l2b_13_0__tab[] = { 0x0200, 0xecd4 };
575 #elif BITS_PER_MP_LIMB == 32
576 const mp_limb_t mpfr_l2b_13_0__tab[] = { 0xecd40200 };
577 #elif BITS_PER_MP_LIMB == 64
578 const mp_limb_t mpfr_l2b_13_0__tab[] = { 0xecd4020000000000 };
579 #elif BITS_PER_MP_LIMB == 96
580 const mp_limb_t mpfr_l2b_13_0__tab[] = { 0xecd402000000000000000000 };
581 #elif BITS_PER_MP_LIMB == 128
582 const mp_limb_t mpfr_l2b_13_0__tab[] = { 0xecd40200000000000000000000000000 };
583 #elif BITS_PER_MP_LIMB == 256
584 const mp_limb_t mpfr_l2b_13_0__tab[] = { 0xecd4020000000000000000000000000000000000000000000000000000000000 };
585 #endif
586
587 #if 0
588 #elif BITS_PER_MP_LIMB == 16
589 const mp_limb_t mpfr_l2b_13_1__tab[] = { 0x57f8, 0xf7b4, 0xcb20, 0xa7c6, 0x8a5c };
590 #elif BITS_PER_MP_LIMB == 32
591 const mp_limb_t mpfr_l2b_13_1__tab[] = { 0x57f80000, 0xcb20f7b4, 0x8a5ca7c6 };
592 #elif BITS_PER_MP_LIMB == 64
593 const mp_limb_t mpfr_l2b_13_1__tab[] = { 0x57f8000000000000, 0x8a5ca7c6cb20f7b4 };
594 #elif BITS_PER_MP_LIMB == 96
595 const mp_limb_t mpfr_l2b_13_1__tab[] = { 0x8a5ca7c6cb20f7b457f80000 };
596 #elif BITS_PER_MP_LIMB == 128
597 const mp_limb_t mpfr_l2b_13_1__tab[] = { 0x8a5ca7c6cb20f7b457f8000000000000 };
598 #elif BITS_PER_MP_LIMB == 256
599 const mp_limb_t mpfr_l2b_13_1__tab[] = { 0x8a5ca7c6cb20f7b457f800000000000000000000000000000000000000000000 };
600 #endif
601
602 #if 0
603 #elif BITS_PER_MP_LIMB == 16
604 const mp_limb_t mpfr_l2b_14_0__tab[] = { 0xb400, 0xf3ab };
605 #elif BITS_PER_MP_LIMB == 32
606 const mp_limb_t mpfr_l2b_14_0__tab[] = { 0xf3abb400 };
607 #elif BITS_PER_MP_LIMB == 64
608 const mp_limb_t mpfr_l2b_14_0__tab[] = { 0xf3abb40000000000 };
609 #elif BITS_PER_MP_LIMB == 96
610 const mp_limb_t mpfr_l2b_14_0__tab[] = { 0xf3abb4000000000000000000 };
611 #elif BITS_PER_MP_LIMB == 128
612 const mp_limb_t mpfr_l2b_14_0__tab[] = { 0xf3abb400000000000000000000000000 };
613 #elif BITS_PER_MP_LIMB == 256
614 const mp_limb_t mpfr_l2b_14_0__tab[] = { 0xf3abb40000000000000000000000000000000000000000000000000000000000 };
615 #endif
616
617 #if 0
618 #elif BITS_PER_MP_LIMB == 16
619 const mp_limb_t mpfr_l2b_14_1__tab[] = { 0x85a8, 0x5cab, 0x96b5, 0xfff6, 0x8679 };
620 #elif BITS_PER_MP_LIMB == 32
621 const mp_limb_t mpfr_l2b_14_1__tab[] = { 0x85a80000, 0x96b55cab, 0x8679fff6 };
622 #elif BITS_PER_MP_LIMB == 64
623 const mp_limb_t mpfr_l2b_14_1__tab[] = { 0x85a8000000000000, 0x8679fff696b55cab };
624 #elif BITS_PER_MP_LIMB == 96
625 const mp_limb_t mpfr_l2b_14_1__tab[] = { 0x8679fff696b55cab85a80000 };
626 #elif BITS_PER_MP_LIMB == 128
627 const mp_limb_t mpfr_l2b_14_1__tab[] = { 0x8679fff696b55cab85a8000000000000 };
628 #elif BITS_PER_MP_LIMB == 256
629 const mp_limb_t mpfr_l2b_14_1__tab[] = { 0x8679fff696b55cab85a800000000000000000000000000000000000000000000 };
630 #endif
631
632 #if 0
633 #elif BITS_PER_MP_LIMB == 16
634 const mp_limb_t mpfr_l2b_15_0__tab[] = { 0x8000, 0xfa0a };
635 #elif BITS_PER_MP_LIMB == 32
636 const mp_limb_t mpfr_l2b_15_0__tab[] = { 0xfa0a8000 };
637 #elif BITS_PER_MP_LIMB == 64
638 const mp_limb_t mpfr_l2b_15_0__tab[] = { 0xfa0a800000000000 };
639 #elif BITS_PER_MP_LIMB == 96
640 const mp_limb_t mpfr_l2b_15_0__tab[] = { 0xfa0a80000000000000000000 };
641 #elif BITS_PER_MP_LIMB == 128
642 const mp_limb_t mpfr_l2b_15_0__tab[] = { 0xfa0a8000000000000000000000000000 };
643 #elif BITS_PER_MP_LIMB == 256
644 const mp_limb_t mpfr_l2b_15_0__tab[] = { 0xfa0a800000000000000000000000000000000000000000000000000000000000 };
645 #endif
646
647 #if 0
648 #elif BITS_PER_MP_LIMB == 16
649 const mp_limb_t mpfr_l2b_15_1__tab[] = { 0x6f80, 0xa6aa, 0x69f0, 0xee23, 0x830c };
650 #elif BITS_PER_MP_LIMB == 32
651 const mp_limb_t mpfr_l2b_15_1__tab[] = { 0x6f800000, 0x69f0a6aa, 0x830cee23 };
652 #elif BITS_PER_MP_LIMB == 64
653 const mp_limb_t mpfr_l2b_15_1__tab[] = { 0x6f80000000000000, 0x830cee2369f0a6aa };
654 #elif BITS_PER_MP_LIMB == 96
655 const mp_limb_t mpfr_l2b_15_1__tab[] = { 0x830cee2369f0a6aa6f800000 };
656 #elif BITS_PER_MP_LIMB == 128
657 const mp_limb_t mpfr_l2b_15_1__tab[] = { 0x830cee2369f0a6aa6f80000000000000 };
658 #elif BITS_PER_MP_LIMB == 256
659 const mp_limb_t mpfr_l2b_15_1__tab[] = { 0x830cee2369f0a6aa6f8000000000000000000000000000000000000000000000 };
660 #endif
661
662 #if 0
663 #elif BITS_PER_MP_LIMB == 16
664 const mp_limb_t mpfr_l2b_16_0__tab[] = { 0x0000, 0x8000 };
665 #elif BITS_PER_MP_LIMB == 32
666 const mp_limb_t mpfr_l2b_16_0__tab[] = { 0x80000000 };
667 #elif BITS_PER_MP_LIMB == 64
668 const mp_limb_t mpfr_l2b_16_0__tab[] = { 0x8000000000000000 };
669 #elif BITS_PER_MP_LIMB == 96
670 const mp_limb_t mpfr_l2b_16_0__tab[] = { 0x800000000000000000000000 };
671 #elif BITS_PER_MP_LIMB == 128
672 const mp_limb_t mpfr_l2b_16_0__tab[] = { 0x80000000000000000000000000000000 };
673 #elif BITS_PER_MP_LIMB == 256
674 const mp_limb_t mpfr_l2b_16_0__tab[] = { 0x8000000000000000000000000000000000000000000000000000000000000000 };
675 #endif
676
677 #if 0
678 #elif BITS_PER_MP_LIMB == 16
679 const mp_limb_t mpfr_l2b_16_1__tab[] = { 0x0000, 0x0000, 0x0000, 0x0000, 0x8000 };
680 #elif BITS_PER_MP_LIMB == 32
681 const mp_limb_t mpfr_l2b_16_1__tab[] = { 0x00000000, 0x00000000, 0x80000000 };
682 #elif BITS_PER_MP_LIMB == 64
683 const mp_limb_t mpfr_l2b_16_1__tab[] = { 0x0000000000000000, 0x8000000000000000 };
684 #elif BITS_PER_MP_LIMB == 96
685 const mp_limb_t mpfr_l2b_16_1__tab[] = { 0x800000000000000000000000 };
686 #elif BITS_PER_MP_LIMB == 128
687 const mp_limb_t mpfr_l2b_16_1__tab[] = { 0x80000000000000000000000000000000 };
688 #elif BITS_PER_MP_LIMB == 256
689 const mp_limb_t mpfr_l2b_16_1__tab[] = { 0x8000000000000000000000000000000000000000000000000000000000000000 };
690 #endif
691
692 #if 0
693 #elif BITS_PER_MP_LIMB == 16
694 const mp_limb_t mpfr_l2b_17_0__tab[] = { 0x8000, 0x82cc };
695 #elif BITS_PER_MP_LIMB == 32
696 const mp_limb_t mpfr_l2b_17_0__tab[] = { 0x82cc8000 };
697 #elif BITS_PER_MP_LIMB == 64
698 const mp_limb_t mpfr_l2b_17_0__tab[] = { 0x82cc800000000000 };
699 #elif BITS_PER_MP_LIMB == 96
700 const mp_limb_t mpfr_l2b_17_0__tab[] = { 0x82cc80000000000000000000 };
701 #elif BITS_PER_MP_LIMB == 128
702 const mp_limb_t mpfr_l2b_17_0__tab[] = { 0x82cc8000000000000000000000000000 };
703 #elif BITS_PER_MP_LIMB == 256
704 const mp_limb_t mpfr_l2b_17_0__tab[] = { 0x82cc800000000000000000000000000000000000000000000000000000000000 };
705 #endif
706
707 #if 0
708 #elif BITS_PER_MP_LIMB == 16
709 const mp_limb_t mpfr_l2b_17_1__tab[] = { 0x8720, 0x259b, 0x62c4, 0xabf5, 0xfa85 };
710 #elif BITS_PER_MP_LIMB == 32
711 const mp_limb_t mpfr_l2b_17_1__tab[] = { 0x87200000, 0x62c4259b, 0xfa85abf5 };
712 #elif BITS_PER_MP_LIMB == 64
713 const mp_limb_t mpfr_l2b_17_1__tab[] = { 0x8720000000000000, 0xfa85abf562c4259b };
714 #elif BITS_PER_MP_LIMB == 96
715 const mp_limb_t mpfr_l2b_17_1__tab[] = { 0xfa85abf562c4259b87200000 };
716 #elif BITS_PER_MP_LIMB == 128
717 const mp_limb_t mpfr_l2b_17_1__tab[] = { 0xfa85abf562c4259b8720000000000000 };
718 #elif BITS_PER_MP_LIMB == 256
719 const mp_limb_t mpfr_l2b_17_1__tab[] = { 0xfa85abf562c4259b872000000000000000000000000000000000000000000000 };
720 #endif
721
722 #if 0
723 #elif BITS_PER_MP_LIMB == 16
724 const mp_limb_t mpfr_l2b_18_0__tab[] = { 0x0800, 0x8570 };
725 #elif BITS_PER_MP_LIMB == 32
726 const mp_limb_t mpfr_l2b_18_0__tab[] = { 0x85700800 };
727 #elif BITS_PER_MP_LIMB == 64
728 const mp_limb_t mpfr_l2b_18_0__tab[] = { 0x8570080000000000 };
729 #elif BITS_PER_MP_LIMB == 96
730 const mp_limb_t mpfr_l2b_18_0__tab[] = { 0x857008000000000000000000 };
731 #elif BITS_PER_MP_LIMB == 128
732 const mp_limb_t mpfr_l2b_18_0__tab[] = { 0x85700800000000000000000000000000 };
733 #elif BITS_PER_MP_LIMB == 256
734 const mp_limb_t mpfr_l2b_18_0__tab[] = { 0x8570080000000000000000000000000000000000000000000000000000000000 };
735 #endif
736
737 #if 0
738 #elif BITS_PER_MP_LIMB == 16
739 const mp_limb_t mpfr_l2b_18_1__tab[] = { 0x3698, 0x1378, 0x5537, 0x6634, 0xf591 };
740 #elif BITS_PER_MP_LIMB == 32
741 const mp_limb_t mpfr_l2b_18_1__tab[] = { 0x36980000, 0x55371378, 0xf5916634 };
742 #elif BITS_PER_MP_LIMB == 64
743 const mp_limb_t mpfr_l2b_18_1__tab[] = { 0x3698000000000000, 0xf591663455371378 };
744 #elif BITS_PER_MP_LIMB == 96
745 const mp_limb_t mpfr_l2b_18_1__tab[] = { 0xf59166345537137836980000 };
746 #elif BITS_PER_MP_LIMB == 128
747 const mp_limb_t mpfr_l2b_18_1__tab[] = { 0xf5916634553713783698000000000000 };
748 #elif BITS_PER_MP_LIMB == 256
749 const mp_limb_t mpfr_l2b_18_1__tab[] = { 0xf591663455371378369800000000000000000000000000000000000000000000 };
750 #endif
751
752 #if 0
753 #elif BITS_PER_MP_LIMB == 16
754 const mp_limb_t mpfr_l2b_19_0__tab[] = { 0x0600, 0x87ef };
755 #elif BITS_PER_MP_LIMB == 32
756 const mp_limb_t mpfr_l2b_19_0__tab[] = { 0x87ef0600 };
757 #elif BITS_PER_MP_LIMB == 64
758 const mp_limb_t mpfr_l2b_19_0__tab[] = { 0x87ef060000000000 };
759 #elif BITS_PER_MP_LIMB == 96
760 const mp_limb_t mpfr_l2b_19_0__tab[] = { 0x87ef06000000000000000000 };
761 #elif BITS_PER_MP_LIMB == 128
762 const mp_limb_t mpfr_l2b_19_0__tab[] = { 0x87ef0600000000000000000000000000 };
763 #elif BITS_PER_MP_LIMB == 256
764 const mp_limb_t mpfr_l2b_19_0__tab[] = { 0x87ef060000000000000000000000000000000000000000000000000000000000 };
765 #endif
766
767 #if 0
768 #elif BITS_PER_MP_LIMB == 16
769 const mp_limb_t mpfr_l2b_19_1__tab[] = { 0x0db8, 0x558c, 0x62ed, 0x08c0, 0xf10f };
770 #elif BITS_PER_MP_LIMB == 32
771 const mp_limb_t mpfr_l2b_19_1__tab[] = { 0x0db80000, 0x62ed558c, 0xf10f08c0 };
772 #elif BITS_PER_MP_LIMB == 64
773 const mp_limb_t mpfr_l2b_19_1__tab[] = { 0x0db8000000000000, 0xf10f08c062ed558c };
774 #elif BITS_PER_MP_LIMB == 96
775 const mp_limb_t mpfr_l2b_19_1__tab[] = { 0xf10f08c062ed558c0db80000 };
776 #elif BITS_PER_MP_LIMB == 128
777 const mp_limb_t mpfr_l2b_19_1__tab[] = { 0xf10f08c062ed558c0db8000000000000 };
778 #elif BITS_PER_MP_LIMB == 256
779 const mp_limb_t mpfr_l2b_19_1__tab[] = { 0xf10f08c062ed558c0db800000000000000000000000000000000000000000000 };
780 #endif
781
782 #if 0
783 #elif BITS_PER_MP_LIMB == 16
784 const mp_limb_t mpfr_l2b_20_0__tab[] = { 0x3e00, 0x8a4d };
785 #elif BITS_PER_MP_LIMB == 32
786 const mp_limb_t mpfr_l2b_20_0__tab[] = { 0x8a4d3e00 };
787 #elif BITS_PER_MP_LIMB == 64
788 const mp_limb_t mpfr_l2b_20_0__tab[] = { 0x8a4d3e0000000000 };
789 #elif BITS_PER_MP_LIMB == 96
790 const mp_limb_t mpfr_l2b_20_0__tab[] = { 0x8a4d3e000000000000000000 };
791 #elif BITS_PER_MP_LIMB == 128
792 const mp_limb_t mpfr_l2b_20_0__tab[] = { 0x8a4d3e00000000000000000000000000 };
793 #elif BITS_PER_MP_LIMB == 256
794 const mp_limb_t mpfr_l2b_20_0__tab[] = { 0x8a4d3e0000000000000000000000000000000000000000000000000000000000 };
795 #endif
796
797 #if 0
798 #elif BITS_PER_MP_LIMB == 16
799 const mp_limb_t mpfr_l2b_20_1__tab[] = { 0x0b40, 0xa71c, 0x1cc1, 0x690a, 0xecee };
800 #elif BITS_PER_MP_LIMB == 32
801 const mp_limb_t mpfr_l2b_20_1__tab[] = { 0x0b400000, 0x1cc1a71c, 0xecee690a };
802 #elif BITS_PER_MP_LIMB == 64
803 const mp_limb_t mpfr_l2b_20_1__tab[] = { 0x0b40000000000000, 0xecee690a1cc1a71c };
804 #elif BITS_PER_MP_LIMB == 96
805 const mp_limb_t mpfr_l2b_20_1__tab[] = { 0xecee690a1cc1a71c0b400000 };
806 #elif BITS_PER_MP_LIMB == 128
807 const mp_limb_t mpfr_l2b_20_1__tab[] = { 0xecee690a1cc1a71c0b40000000000000 };
808 #elif BITS_PER_MP_LIMB == 256
809 const mp_limb_t mpfr_l2b_20_1__tab[] = { 0xecee690a1cc1a71c0b4000000000000000000000000000000000000000000000 };
810 #endif
811
812 #if 0
813 #elif BITS_PER_MP_LIMB == 16
814 const mp_limb_t mpfr_l2b_21_0__tab[] = { 0xde00, 0x8c8d };
815 #elif BITS_PER_MP_LIMB == 32
816 const mp_limb_t mpfr_l2b_21_0__tab[] = { 0x8c8dde00 };
817 #elif BITS_PER_MP_LIMB == 64
818 const mp_limb_t mpfr_l2b_21_0__tab[] = { 0x8c8dde0000000000 };
819 #elif BITS_PER_MP_LIMB == 96
820 const mp_limb_t mpfr_l2b_21_0__tab[] = { 0x8c8dde000000000000000000 };
821 #elif BITS_PER_MP_LIMB == 128
822 const mp_limb_t mpfr_l2b_21_0__tab[] = { 0x8c8dde00000000000000000000000000 };
823 #elif BITS_PER_MP_LIMB == 256
824 const mp_limb_t mpfr_l2b_21_0__tab[] = { 0x8c8dde0000000000000000000000000000000000000000000000000000000000 };
825 #endif
826
827 #if 0
828 #elif BITS_PER_MP_LIMB == 16
829 const mp_limb_t mpfr_l2b_21_1__tab[] = { 0x4108, 0x6b26, 0xb3d0, 0x63c1, 0xe922 };
830 #elif BITS_PER_MP_LIMB == 32
831 const mp_limb_t mpfr_l2b_21_1__tab[] = { 0x41080000, 0xb3d06b26, 0xe92263c1 };
832 #elif BITS_PER_MP_LIMB == 64
833 const mp_limb_t mpfr_l2b_21_1__tab[] = { 0x4108000000000000, 0xe92263c1b3d06b26 };
834 #elif BITS_PER_MP_LIMB == 96
835 const mp_limb_t mpfr_l2b_21_1__tab[] = { 0xe92263c1b3d06b2641080000 };
836 #elif BITS_PER_MP_LIMB == 128
837 const mp_limb_t mpfr_l2b_21_1__tab[] = { 0xe92263c1b3d06b264108000000000000 };
838 #elif BITS_PER_MP_LIMB == 256
839 const mp_limb_t mpfr_l2b_21_1__tab[] = { 0xe92263c1b3d06b26410800000000000000000000000000000000000000000000 };
840 #endif
841
842 #if 0
843 #elif BITS_PER_MP_LIMB == 16
844 const mp_limb_t mpfr_l2b_22_0__tab[] = { 0xaa00, 0x8eb3 };
845 #elif BITS_PER_MP_LIMB == 32
846 const mp_limb_t mpfr_l2b_22_0__tab[] = { 0x8eb3aa00 };
847 #elif BITS_PER_MP_LIMB == 64
848 const mp_limb_t mpfr_l2b_22_0__tab[] = { 0x8eb3aa0000000000 };
849 #elif BITS_PER_MP_LIMB == 96
850 const mp_limb_t mpfr_l2b_22_0__tab[] = { 0x8eb3aa000000000000000000 };
851 #elif BITS_PER_MP_LIMB == 128
852 const mp_limb_t mpfr_l2b_22_0__tab[] = { 0x8eb3aa00000000000000000000000000 };
853 #elif BITS_PER_MP_LIMB == 256
854 const mp_limb_t mpfr_l2b_22_0__tab[] = { 0x8eb3aa0000000000000000000000000000000000000000000000000000000000 };
855 #endif
856
857 #if 0
858 #elif BITS_PER_MP_LIMB == 16
859 const mp_limb_t mpfr_l2b_22_1__tab[] = { 0xdbe8, 0xf061, 0x60b9, 0x2c4d, 0xe5a0 };
860 #elif BITS_PER_MP_LIMB == 32
861 const mp_limb_t mpfr_l2b_22_1__tab[] = { 0xdbe80000, 0x60b9f061, 0xe5a02c4d };
862 #elif BITS_PER_MP_LIMB == 64
863 const mp_limb_t mpfr_l2b_22_1__tab[] = { 0xdbe8000000000000, 0xe5a02c4d60b9f061 };
864 #elif BITS_PER_MP_LIMB == 96
865 const mp_limb_t mpfr_l2b_22_1__tab[] = { 0xe5a02c4d60b9f061dbe80000 };
866 #elif BITS_PER_MP_LIMB == 128
867 const mp_limb_t mpfr_l2b_22_1__tab[] = { 0xe5a02c4d60b9f061dbe8000000000000 };
868 #elif BITS_PER_MP_LIMB == 256
869 const mp_limb_t mpfr_l2b_22_1__tab[] = { 0xe5a02c4d60b9f061dbe800000000000000000000000000000000000000000000 };
870 #endif
871
872 #if 0
873 #elif BITS_PER_MP_LIMB == 16
874 const mp_limb_t mpfr_l2b_23_0__tab[] = { 0x0600, 0x90c1 };
875 #elif BITS_PER_MP_LIMB == 32
876 const mp_limb_t mpfr_l2b_23_0__tab[] = { 0x90c10600 };
877 #elif BITS_PER_MP_LIMB == 64
878 const mp_limb_t mpfr_l2b_23_0__tab[] = { 0x90c1060000000000 };
879 #elif BITS_PER_MP_LIMB == 96
880 const mp_limb_t mpfr_l2b_23_0__tab[] = { 0x90c106000000000000000000 };
881 #elif BITS_PER_MP_LIMB == 128
882 const mp_limb_t mpfr_l2b_23_0__tab[] = { 0x90c10600000000000000000000000000 };
883 #elif BITS_PER_MP_LIMB == 256
884 const mp_limb_t mpfr_l2b_23_0__tab[] = { 0x90c1060000000000000000000000000000000000000000000000000000000000 };
885 #endif
886
887 #if 0
888 #elif BITS_PER_MP_LIMB == 16
889 const mp_limb_t mpfr_l2b_23_1__tab[] = { 0xc3e0, 0x586a, 0x46b9, 0xcadd, 0xe25e };
890 #elif BITS_PER_MP_LIMB == 32
891 const mp_limb_t mpfr_l2b_23_1__tab[] = { 0xc3e00000, 0x46b9586a, 0xe25ecadd };
892 #elif BITS_PER_MP_LIMB == 64
893 const mp_limb_t mpfr_l2b_23_1__tab[] = { 0xc3e0000000000000, 0xe25ecadd46b9586a };
894 #elif BITS_PER_MP_LIMB == 96
895 const mp_limb_t mpfr_l2b_23_1__tab[] = { 0xe25ecadd46b9586ac3e00000 };
896 #elif BITS_PER_MP_LIMB == 128
897 const mp_limb_t mpfr_l2b_23_1__tab[] = { 0xe25ecadd46b9586ac3e0000000000000 };
898 #elif BITS_PER_MP_LIMB == 256
899 const mp_limb_t mpfr_l2b_23_1__tab[] = { 0xe25ecadd46b9586ac3e000000000000000000000000000000000000000000000 };
900 #endif
901
902 #if 0
903 #elif BITS_PER_MP_LIMB == 16
904 const mp_limb_t mpfr_l2b_24_0__tab[] = { 0x0400, 0x92b8 };
905 #elif BITS_PER_MP_LIMB == 32
906 const mp_limb_t mpfr_l2b_24_0__tab[] = { 0x92b80400 };
907 #elif BITS_PER_MP_LIMB == 64
908 const mp_limb_t mpfr_l2b_24_0__tab[] = { 0x92b8040000000000 };
909 #elif BITS_PER_MP_LIMB == 96
910 const mp_limb_t mpfr_l2b_24_0__tab[] = { 0x92b804000000000000000000 };
911 #elif BITS_PER_MP_LIMB == 128
912 const mp_limb_t mpfr_l2b_24_0__tab[] = { 0x92b80400000000000000000000000000 };
913 #elif BITS_PER_MP_LIMB == 256
914 const mp_limb_t mpfr_l2b_24_0__tab[] = { 0x92b8040000000000000000000000000000000000000000000000000000000000 };
915 #endif
916
917 #if 0
918 #elif BITS_PER_MP_LIMB == 16
919 const mp_limb_t mpfr_l2b_24_1__tab[] = { 0x3668, 0x7263, 0xc7c6, 0xbb44, 0xdf56 };
920 #elif BITS_PER_MP_LIMB == 32
921 const mp_limb_t mpfr_l2b_24_1__tab[] = { 0x36680000, 0xc7c67263, 0xdf56bb44 };
922 #elif BITS_PER_MP_LIMB == 64
923 const mp_limb_t mpfr_l2b_24_1__tab[] = { 0x3668000000000000, 0xdf56bb44c7c67263 };
924 #elif BITS_PER_MP_LIMB == 96
925 const mp_limb_t mpfr_l2b_24_1__tab[] = { 0xdf56bb44c7c6726336680000 };
926 #elif BITS_PER_MP_LIMB == 128
927 const mp_limb_t mpfr_l2b_24_1__tab[] = { 0xdf56bb44c7c672633668000000000000 };
928 #elif BITS_PER_MP_LIMB == 256
929 const mp_limb_t mpfr_l2b_24_1__tab[] = { 0xdf56bb44c7c67263366800000000000000000000000000000000000000000000 };
930 #endif
931
932 #if 0
933 #elif BITS_PER_MP_LIMB == 16
934 const mp_limb_t mpfr_l2b_25_0__tab[] = { 0x7a00, 0x949a };
935 #elif BITS_PER_MP_LIMB == 32
936 const mp_limb_t mpfr_l2b_25_0__tab[] = { 0x949a7a00 };
937 #elif BITS_PER_MP_LIMB == 64
938 const mp_limb_t mpfr_l2b_25_0__tab[] = { 0x949a7a0000000000 };
939 #elif BITS_PER_MP_LIMB == 96
940 const mp_limb_t mpfr_l2b_25_0__tab[] = { 0x949a7a000000000000000000 };
941 #elif BITS_PER_MP_LIMB == 128
942 const mp_limb_t mpfr_l2b_25_0__tab[] = { 0x949a7a00000000000000000000000000 };
943 #elif BITS_PER_MP_LIMB == 256
944 const mp_limb_t mpfr_l2b_25_0__tab[] = { 0x949a7a0000000000000000000000000000000000000000000000000000000000 };
945 #endif
946
947 #if 0
948 #elif BITS_PER_MP_LIMB == 16
949 const mp_limb_t mpfr_l2b_25_1__tab[] = { 0x67b8, 0x9728, 0x287b, 0xa348, 0xdc81 };
950 #elif BITS_PER_MP_LIMB == 32
951 const mp_limb_t mpfr_l2b_25_1__tab[] = { 0x67b80000, 0x287b9728, 0xdc81a348 };
952 #elif BITS_PER_MP_LIMB == 64
953 const mp_limb_t mpfr_l2b_25_1__tab[] = { 0x67b8000000000000, 0xdc81a348287b9728 };
954 #elif BITS_PER_MP_LIMB == 96
955 const mp_limb_t mpfr_l2b_25_1__tab[] = { 0xdc81a348287b972867b80000 };
956 #elif BITS_PER_MP_LIMB == 128
957 const mp_limb_t mpfr_l2b_25_1__tab[] = { 0xdc81a348287b972867b8000000000000 };
958 #elif BITS_PER_MP_LIMB == 256
959 const mp_limb_t mpfr_l2b_25_1__tab[] = { 0xdc81a348287b972867b800000000000000000000000000000000000000000000 };
960 #endif
961
962 #if 0
963 #elif BITS_PER_MP_LIMB == 16
964 const mp_limb_t mpfr_l2b_26_0__tab[] = { 0x0200, 0x966a };
965 #elif BITS_PER_MP_LIMB == 32
966 const mp_limb_t mpfr_l2b_26_0__tab[] = { 0x966a0200 };
967 #elif BITS_PER_MP_LIMB == 64
968 const mp_limb_t mpfr_l2b_26_0__tab[] = { 0x966a020000000000 };
969 #elif BITS_PER_MP_LIMB == 96
970 const mp_limb_t mpfr_l2b_26_0__tab[] = { 0x966a02000000000000000000 };
971 #elif BITS_PER_MP_LIMB == 128
972 const mp_limb_t mpfr_l2b_26_0__tab[] = { 0x966a0200000000000000000000000000 };
973 #elif BITS_PER_MP_LIMB == 256
974 const mp_limb_t mpfr_l2b_26_0__tab[] = { 0x966a020000000000000000000000000000000000000000000000000000000000 };
975 #endif
976
977 #if 0
978 #elif BITS_PER_MP_LIMB == 16
979 const mp_limb_t mpfr_l2b_26_1__tab[] = { 0x6458, 0x78a4, 0x7583, 0x19f9, 0xd9da };
980 #elif BITS_PER_MP_LIMB == 32
981 const mp_limb_t mpfr_l2b_26_1__tab[] = { 0x64580000, 0x758378a4, 0xd9da19f9 };
982 #elif BITS_PER_MP_LIMB == 64
983 const mp_limb_t mpfr_l2b_26_1__tab[] = { 0x6458000000000000, 0xd9da19f9758378a4 };
984 #elif BITS_PER_MP_LIMB == 96
985 const mp_limb_t mpfr_l2b_26_1__tab[] = { 0xd9da19f9758378a464580000 };
986 #elif BITS_PER_MP_LIMB == 128
987 const mp_limb_t mpfr_l2b_26_1__tab[] = { 0xd9da19f9758378a46458000000000000 };
988 #elif BITS_PER_MP_LIMB == 256
989 const mp_limb_t mpfr_l2b_26_1__tab[] = { 0xd9da19f9758378a4645800000000000000000000000000000000000000000000 };
990 #endif
991
992 #if 0
993 #elif BITS_PER_MP_LIMB == 16
994 const mp_limb_t mpfr_l2b_27_0__tab[] = { 0x0a00, 0x9828 };
995 #elif BITS_PER_MP_LIMB == 32
996 const mp_limb_t mpfr_l2b_27_0__tab[] = { 0x98280a00 };
997 #elif BITS_PER_MP_LIMB == 64
998 const mp_limb_t mpfr_l2b_27_0__tab[] = { 0x98280a0000000000 };
999 #elif BITS_PER_MP_LIMB == 96
1000 const mp_limb_t mpfr_l2b_27_0__tab[] = { 0x98280a000000000000000000 };
1001 #elif BITS_PER_MP_LIMB == 128
1002 const mp_limb_t mpfr_l2b_27_0__tab[] = { 0x98280a00000000000000000000000000 };
1003 #elif BITS_PER_MP_LIMB == 256
1004 const mp_limb_t mpfr_l2b_27_0__tab[] = { 0x98280a0000000000000000000000000000000000000000000000000000000000 };
1005 #endif
1006
1007 #if 0
1008 #elif BITS_PER_MP_LIMB == 16
1009 const mp_limb_t mpfr_l2b_27_1__tab[] = { 0x5b08, 0xe1bd, 0xe237, 0x7bac, 0xd75b };
1010 #elif BITS_PER_MP_LIMB == 32
1011 const mp_limb_t mpfr_l2b_27_1__tab[] = { 0x5b080000, 0xe237e1bd, 0xd75b7bac };
1012 #elif BITS_PER_MP_LIMB == 64
1013 const mp_limb_t mpfr_l2b_27_1__tab[] = { 0x5b08000000000000, 0xd75b7bace237e1bd };
1014 #elif BITS_PER_MP_LIMB == 96
1015 const mp_limb_t mpfr_l2b_27_1__tab[] = { 0xd75b7bace237e1bd5b080000 };
1016 #elif BITS_PER_MP_LIMB == 128
1017 const mp_limb_t mpfr_l2b_27_1__tab[] = { 0xd75b7bace237e1bd5b08000000000000 };
1018 #elif BITS_PER_MP_LIMB == 256
1019 const mp_limb_t mpfr_l2b_27_1__tab[] = { 0xd75b7bace237e1bd5b0800000000000000000000000000000000000000000000 };
1020 #endif
1021
1022 #if 0
1023 #elif BITS_PER_MP_LIMB == 16
1024 const mp_limb_t mpfr_l2b_28_0__tab[] = { 0xda00, 0x99d5 };
1025 #elif BITS_PER_MP_LIMB == 32
1026 const mp_limb_t mpfr_l2b_28_0__tab[] = { 0x99d5da00 };
1027 #elif BITS_PER_MP_LIMB == 64
1028 const mp_limb_t mpfr_l2b_28_0__tab[] = { 0x99d5da0000000000 };
1029 #elif BITS_PER_MP_LIMB == 96
1030 const mp_limb_t mpfr_l2b_28_0__tab[] = { 0x99d5da000000000000000000 };
1031 #elif BITS_PER_MP_LIMB == 128
1032 const mp_limb_t mpfr_l2b_28_0__tab[] = { 0x99d5da00000000000000000000000000 };
1033 #elif BITS_PER_MP_LIMB == 256
1034 const mp_limb_t mpfr_l2b_28_0__tab[] = { 0x99d5da0000000000000000000000000000000000000000000000000000000000 };
1035 #endif
1036
1037 #if 0
1038 #elif BITS_PER_MP_LIMB == 16
1039 const mp_limb_t mpfr_l2b_28_1__tab[] = { 0xdeb8, 0xe8b8, 0x71df, 0xc758, 0xd501 };
1040 #elif BITS_PER_MP_LIMB == 32
1041 const mp_limb_t mpfr_l2b_28_1__tab[] = { 0xdeb80000, 0x71dfe8b8, 0xd501c758 };
1042 #elif BITS_PER_MP_LIMB == 64
1043 const mp_limb_t mpfr_l2b_28_1__tab[] = { 0xdeb8000000000000, 0xd501c75871dfe8b8 };
1044 #elif BITS_PER_MP_LIMB == 96
1045 const mp_limb_t mpfr_l2b_28_1__tab[] = { 0xd501c75871dfe8b8deb80000 };
1046 #elif BITS_PER_MP_LIMB == 128
1047 const mp_limb_t mpfr_l2b_28_1__tab[] = { 0xd501c75871dfe8b8deb8000000000000 };
1048 #elif BITS_PER_MP_LIMB == 256
1049 const mp_limb_t mpfr_l2b_28_1__tab[] = { 0xd501c75871dfe8b8deb800000000000000000000000000000000000000000000 };
1050 #endif
1051
1052 #if 0
1053 #elif BITS_PER_MP_LIMB == 16
1054 const mp_limb_t mpfr_l2b_29_0__tab[] = { 0x9600, 0x9b74 };
1055 #elif BITS_PER_MP_LIMB == 32
1056 const mp_limb_t mpfr_l2b_29_0__tab[] = { 0x9b749600 };
1057 #elif BITS_PER_MP_LIMB == 64
1058 const mp_limb_t mpfr_l2b_29_0__tab[] = { 0x9b74960000000000 };
1059 #elif BITS_PER_MP_LIMB == 96
1060 const mp_limb_t mpfr_l2b_29_0__tab[] = { 0x9b7496000000000000000000 };
1061 #elif BITS_PER_MP_LIMB == 128
1062 const mp_limb_t mpfr_l2b_29_0__tab[] = { 0x9b749600000000000000000000000000 };
1063 #elif BITS_PER_MP_LIMB == 256
1064 const mp_limb_t mpfr_l2b_29_0__tab[] = { 0x9b74960000000000000000000000000000000000000000000000000000000000 };
1065 #endif
1066
1067 #if 0
1068 #elif BITS_PER_MP_LIMB == 16
1069 const mp_limb_t mpfr_l2b_29_1__tab[] = { 0xccc8, 0x62b3, 0x9c6c, 0x8315, 0xd2c9 };
1070 #elif BITS_PER_MP_LIMB == 32
1071 const mp_limb_t mpfr_l2b_29_1__tab[] = { 0xccc80000, 0x9c6c62b3, 0xd2c98315 };
1072 #elif BITS_PER_MP_LIMB == 64
1073 const mp_limb_t mpfr_l2b_29_1__tab[] = { 0xccc8000000000000, 0xd2c983159c6c62b3 };
1074 #elif BITS_PER_MP_LIMB == 96
1075 const mp_limb_t mpfr_l2b_29_1__tab[] = { 0xd2c983159c6c62b3ccc80000 };
1076 #elif BITS_PER_MP_LIMB == 128
1077 const mp_limb_t mpfr_l2b_29_1__tab[] = { 0xd2c983159c6c62b3ccc8000000000000 };
1078 #elif BITS_PER_MP_LIMB == 256
1079 const mp_limb_t mpfr_l2b_29_1__tab[] = { 0xd2c983159c6c62b3ccc800000000000000000000000000000000000000000000 };
1080 #endif
1081
1082 #if 0
1083 #elif BITS_PER_MP_LIMB == 16
1084 const mp_limb_t mpfr_l2b_30_0__tab[] = { 0x4000, 0x9d05 };
1085 #elif BITS_PER_MP_LIMB == 32
1086 const mp_limb_t mpfr_l2b_30_0__tab[] = { 0x9d054000 };
1087 #elif BITS_PER_MP_LIMB == 64
1088 const mp_limb_t mpfr_l2b_30_0__tab[] = { 0x9d05400000000000 };
1089 #elif BITS_PER_MP_LIMB == 96
1090 const mp_limb_t mpfr_l2b_30_0__tab[] = { 0x9d0540000000000000000000 };
1091 #elif BITS_PER_MP_LIMB == 128
1092 const mp_limb_t mpfr_l2b_30_0__tab[] = { 0x9d054000000000000000000000000000 };
1093 #elif BITS_PER_MP_LIMB == 256
1094 const mp_limb_t mpfr_l2b_30_0__tab[] = { 0x9d05400000000000000000000000000000000000000000000000000000000000 };
1095 #endif
1096
1097 #if 0
1098 #elif BITS_PER_MP_LIMB == 16
1099 const mp_limb_t mpfr_l2b_30_1__tab[] = { 0x3588, 0x1732, 0x5cad, 0xa619, 0xd0af };
1100 #elif BITS_PER_MP_LIMB == 32
1101 const mp_limb_t mpfr_l2b_30_1__tab[] = { 0x35880000, 0x5cad1732, 0xd0afa619 };
1102 #elif BITS_PER_MP_LIMB == 64
1103 const mp_limb_t mpfr_l2b_30_1__tab[] = { 0x3588000000000000, 0xd0afa6195cad1732 };
1104 #elif BITS_PER_MP_LIMB == 96
1105 const mp_limb_t mpfr_l2b_30_1__tab[] = { 0xd0afa6195cad173235880000 };
1106 #elif BITS_PER_MP_LIMB == 128
1107 const mp_limb_t mpfr_l2b_30_1__tab[] = { 0xd0afa6195cad17323588000000000000 };
1108 #elif BITS_PER_MP_LIMB == 256
1109 const mp_limb_t mpfr_l2b_30_1__tab[] = { 0xd0afa6195cad1732358800000000000000000000000000000000000000000000 };
1110 #endif
1111
1112 #if 0
1113 #elif BITS_PER_MP_LIMB == 16
1114 const mp_limb_t mpfr_l2b_31_0__tab[] = { 0xc800, 0x9e88 };
1115 #elif BITS_PER_MP_LIMB == 32
1116 const mp_limb_t mpfr_l2b_31_0__tab[] = { 0x9e88c800 };
1117 #elif BITS_PER_MP_LIMB == 64
1118 const mp_limb_t mpfr_l2b_31_0__tab[] = { 0x9e88c80000000000 };
1119 #elif BITS_PER_MP_LIMB == 96
1120 const mp_limb_t mpfr_l2b_31_0__tab[] = { 0x9e88c8000000000000000000 };
1121 #elif BITS_PER_MP_LIMB == 128
1122 const mp_limb_t mpfr_l2b_31_0__tab[] = { 0x9e88c800000000000000000000000000 };
1123 #elif BITS_PER_MP_LIMB == 256
1124 const mp_limb_t mpfr_l2b_31_0__tab[] = { 0x9e88c80000000000000000000000000000000000000000000000000000000000 };
1125 #endif
1126
1127 #if 0
1128 #elif BITS_PER_MP_LIMB == 16
1129 const mp_limb_t mpfr_l2b_31_1__tab[] = { 0xd578, 0xf7ca, 0x63ee, 0x86e6, 0xceb1 };
1130 #elif BITS_PER_MP_LIMB == 32
1131 const mp_limb_t mpfr_l2b_31_1__tab[] = { 0xd5780000, 0x63eef7ca, 0xceb186e6 };
1132 #elif BITS_PER_MP_LIMB == 64
1133 const mp_limb_t mpfr_l2b_31_1__tab[] = { 0xd578000000000000, 0xceb186e663eef7ca };
1134 #elif BITS_PER_MP_LIMB == 96
1135 const mp_limb_t mpfr_l2b_31_1__tab[] = { 0xceb186e663eef7cad5780000 };
1136 #elif BITS_PER_MP_LIMB == 128
1137 const mp_limb_t mpfr_l2b_31_1__tab[] = { 0xceb186e663eef7cad578000000000000 };
1138 #elif BITS_PER_MP_LIMB == 256
1139 const mp_limb_t mpfr_l2b_31_1__tab[] = { 0xceb186e663eef7cad57800000000000000000000000000000000000000000000 };
1140 #endif
1141
1142 #if 0
1143 #elif BITS_PER_MP_LIMB == 16
1144 const mp_limb_t mpfr_l2b_32_0__tab[] = { 0x0000, 0xa000 };
1145 #elif BITS_PER_MP_LIMB == 32
1146 const mp_limb_t mpfr_l2b_32_0__tab[] = { 0xa0000000 };
1147 #elif BITS_PER_MP_LIMB == 64
1148 const mp_limb_t mpfr_l2b_32_0__tab[] = { 0xa000000000000000 };
1149 #elif BITS_PER_MP_LIMB == 96
1150 const mp_limb_t mpfr_l2b_32_0__tab[] = { 0xa00000000000000000000000 };
1151 #elif BITS_PER_MP_LIMB == 128
1152 const mp_limb_t mpfr_l2b_32_0__tab[] = { 0xa0000000000000000000000000000000 };
1153 #elif BITS_PER_MP_LIMB == 256
1154 const mp_limb_t mpfr_l2b_32_0__tab[] = { 0xa000000000000000000000000000000000000000000000000000000000000000 };
1155 #endif
1156
1157 #if 0
1158 #elif BITS_PER_MP_LIMB == 16
1159 const mp_limb_t mpfr_l2b_32_1__tab[] = { 0xccd0, 0xcccc, 0xcccc, 0xcccc, 0xcccc };
1160 #elif BITS_PER_MP_LIMB == 32
1161 const mp_limb_t mpfr_l2b_32_1__tab[] = { 0xccd00000, 0xcccccccc, 0xcccccccc };
1162 #elif BITS_PER_MP_LIMB == 64
1163 const mp_limb_t mpfr_l2b_32_1__tab[] = { 0xccd0000000000000, 0xcccccccccccccccc };
1164 #elif BITS_PER_MP_LIMB == 96
1165 const mp_limb_t mpfr_l2b_32_1__tab[] = { 0xccccccccccccccccccd00000 };
1166 #elif BITS_PER_MP_LIMB == 128
1167 const mp_limb_t mpfr_l2b_32_1__tab[] = { 0xccccccccccccccccccd0000000000000 };
1168 #elif BITS_PER_MP_LIMB == 256
1169 const mp_limb_t mpfr_l2b_32_1__tab[] = { 0xccccccccccccccccccd000000000000000000000000000000000000000000000 };
1170 #endif
1171
1172 #if 0
1173 #elif BITS_PER_MP_LIMB == 16
1174 const mp_limb_t mpfr_l2b_33_0__tab[] = { 0xae00, 0xa16b };
1175 #elif BITS_PER_MP_LIMB == 32
1176 const mp_limb_t mpfr_l2b_33_0__tab[] = { 0xa16bae00 };
1177 #elif BITS_PER_MP_LIMB == 64
1178 const mp_limb_t mpfr_l2b_33_0__tab[] = { 0xa16bae0000000000 };
1179 #elif BITS_PER_MP_LIMB == 96
1180 const mp_limb_t mpfr_l2b_33_0__tab[] = { 0xa16bae000000000000000000 };
1181 #elif BITS_PER_MP_LIMB == 128
1182 const mp_limb_t mpfr_l2b_33_0__tab[] = { 0xa16bae00000000000000000000000000 };
1183 #elif BITS_PER_MP_LIMB == 256
1184 const mp_limb_t mpfr_l2b_33_0__tab[] = { 0xa16bae0000000000000000000000000000000000000000000000000000000000 };
1185 #endif
1186
1187 #if 0
1188 #elif BITS_PER_MP_LIMB == 16
1189 const mp_limb_t mpfr_l2b_33_1__tab[] = { 0x0888, 0xa187, 0x5304, 0x6404, 0xcaff };
1190 #elif BITS_PER_MP_LIMB == 32
1191 const mp_limb_t mpfr_l2b_33_1__tab[] = { 0x08880000, 0x5304a187, 0xcaff6404 };
1192 #elif BITS_PER_MP_LIMB == 64
1193 const mp_limb_t mpfr_l2b_33_1__tab[] = { 0x0888000000000000, 0xcaff64045304a187 };
1194 #elif BITS_PER_MP_LIMB == 96
1195 const mp_limb_t mpfr_l2b_33_1__tab[] = { 0xcaff64045304a18708880000 };
1196 #elif BITS_PER_MP_LIMB == 128
1197 const mp_limb_t mpfr_l2b_33_1__tab[] = { 0xcaff64045304a1870888000000000000 };
1198 #elif BITS_PER_MP_LIMB == 256
1199 const mp_limb_t mpfr_l2b_33_1__tab[] = { 0xcaff64045304a187088800000000000000000000000000000000000000000000 };
1200 #endif
1201
1202 #if 0
1203 #elif BITS_PER_MP_LIMB == 16
1204 const mp_limb_t mpfr_l2b_34_0__tab[] = { 0x8000, 0xa2cc };
1205 #elif BITS_PER_MP_LIMB == 32
1206 const mp_limb_t mpfr_l2b_34_0__tab[] = { 0xa2cc8000 };
1207 #elif BITS_PER_MP_LIMB == 64
1208 const mp_limb_t mpfr_l2b_34_0__tab[] = { 0xa2cc800000000000 };
1209 #elif BITS_PER_MP_LIMB == 96
1210 const mp_limb_t mpfr_l2b_34_0__tab[] = { 0xa2cc80000000000000000000 };
1211 #elif BITS_PER_MP_LIMB == 128
1212 const mp_limb_t mpfr_l2b_34_0__tab[] = { 0xa2cc8000000000000000000000000000 };
1213 #elif BITS_PER_MP_LIMB == 256
1214 const mp_limb_t mpfr_l2b_34_0__tab[] = { 0xa2cc800000000000000000000000000000000000000000000000000000000000 };
1215 #endif
1216
1217 #if 0
1218 #elif BITS_PER_MP_LIMB == 16
1219 const mp_limb_t mpfr_l2b_34_1__tab[] = { 0xfb50, 0x17ca, 0x5a79, 0x73d8, 0xc947 };
1220 #elif BITS_PER_MP_LIMB == 32
1221 const mp_limb_t mpfr_l2b_34_1__tab[] = { 0xfb500000, 0x5a7917ca, 0xc94773d8 };
1222 #elif BITS_PER_MP_LIMB == 64
1223 const mp_limb_t mpfr_l2b_34_1__tab[] = { 0xfb50000000000000, 0xc94773d85a7917ca };
1224 #elif BITS_PER_MP_LIMB == 96
1225 const mp_limb_t mpfr_l2b_34_1__tab[] = { 0xc94773d85a7917cafb500000 };
1226 #elif BITS_PER_MP_LIMB == 128
1227 const mp_limb_t mpfr_l2b_34_1__tab[] = { 0xc94773d85a7917cafb50000000000000 };
1228 #elif BITS_PER_MP_LIMB == 256
1229 const mp_limb_t mpfr_l2b_34_1__tab[] = { 0xc94773d85a7917cafb5000000000000000000000000000000000000000000000 };
1230 #endif
1231
1232 #if 0
1233 #elif BITS_PER_MP_LIMB == 16
1234 const mp_limb_t mpfr_l2b_35_0__tab[] = { 0x1800, 0xa423 };
1235 #elif BITS_PER_MP_LIMB == 32
1236 const mp_limb_t mpfr_l2b_35_0__tab[] = { 0xa4231800 };
1237 #elif BITS_PER_MP_LIMB == 64
1238 const mp_limb_t mpfr_l2b_35_0__tab[] = { 0xa423180000000000 };
1239 #elif BITS_PER_MP_LIMB == 96
1240 const mp_limb_t mpfr_l2b_35_0__tab[] = { 0xa42318000000000000000000 };
1241 #elif BITS_PER_MP_LIMB == 128
1242 const mp_limb_t mpfr_l2b_35_0__tab[] = { 0xa4231800000000000000000000000000 };
1243 #elif BITS_PER_MP_LIMB == 256
1244 const mp_limb_t mpfr_l2b_35_0__tab[] = { 0xa423180000000000000000000000000000000000000000000000000000000000 };
1245 #endif
1246
1247 #if 0
1248 #elif BITS_PER_MP_LIMB == 16
1249 const mp_limb_t mpfr_l2b_35_1__tab[] = { 0x6960, 0x18c2, 0x6037, 0x567c, 0xc7a3 };
1250 #elif BITS_PER_MP_LIMB == 32
1251 const mp_limb_t mpfr_l2b_35_1__tab[] = { 0x69600000, 0x603718c2, 0xc7a3567c };
1252 #elif BITS_PER_MP_LIMB == 64
1253 const mp_limb_t mpfr_l2b_35_1__tab[] = { 0x6960000000000000, 0xc7a3567c603718c2 };
1254 #elif BITS_PER_MP_LIMB == 96
1255 const mp_limb_t mpfr_l2b_35_1__tab[] = { 0xc7a3567c603718c269600000 };
1256 #elif BITS_PER_MP_LIMB == 128
1257 const mp_limb_t mpfr_l2b_35_1__tab[] = { 0xc7a3567c603718c26960000000000000 };
1258 #elif BITS_PER_MP_LIMB == 256
1259 const mp_limb_t mpfr_l2b_35_1__tab[] = { 0xc7a3567c603718c2696000000000000000000000000000000000000000000000 };
1260 #endif
1261
1262 #if 0
1263 #elif BITS_PER_MP_LIMB == 16
1264 const mp_limb_t mpfr_l2b_36_0__tab[] = { 0x0800, 0xa570 };
1265 #elif BITS_PER_MP_LIMB == 32
1266 const mp_limb_t mpfr_l2b_36_0__tab[] = { 0xa5700800 };
1267 #elif BITS_PER_MP_LIMB == 64
1268 const mp_limb_t mpfr_l2b_36_0__tab[] = { 0xa570080000000000 };
1269 #elif BITS_PER_MP_LIMB == 96
1270 const mp_limb_t mpfr_l2b_36_0__tab[] = { 0xa57008000000000000000000 };
1271 #elif BITS_PER_MP_LIMB == 128
1272 const mp_limb_t mpfr_l2b_36_0__tab[] = { 0xa5700800000000000000000000000000 };
1273 #elif BITS_PER_MP_LIMB == 256
1274 const mp_limb_t mpfr_l2b_36_0__tab[] = { 0xa570080000000000000000000000000000000000000000000000000000000000 };
1275 #endif
1276
1277 #if 0
1278 #elif BITS_PER_MP_LIMB == 16
1279 const mp_limb_t mpfr_l2b_36_1__tab[] = { 0xff10, 0xf9e9, 0xe054, 0x9236, 0xc611 };
1280 #elif BITS_PER_MP_LIMB == 32
1281 const mp_limb_t mpfr_l2b_36_1__tab[] = { 0xff100000, 0xe054f9e9, 0xc6119236 };
1282 #elif BITS_PER_MP_LIMB == 64
1283 const mp_limb_t mpfr_l2b_36_1__tab[] = { 0xff10000000000000, 0xc6119236e054f9e9 };
1284 #elif BITS_PER_MP_LIMB == 96
1285 const mp_limb_t mpfr_l2b_36_1__tab[] = { 0xc6119236e054f9e9ff100000 };
1286 #elif BITS_PER_MP_LIMB == 128
1287 const mp_limb_t mpfr_l2b_36_1__tab[] = { 0xc6119236e054f9e9ff10000000000000 };
1288 #elif BITS_PER_MP_LIMB == 256
1289 const mp_limb_t mpfr_l2b_36_1__tab[] = { 0xc6119236e054f9e9ff1000000000000000000000000000000000000000000000 };
1290 #endif
1291
1292 const __mpfr_struct __gmpfr_l2b[BASE_MAX-1][2] = {
1293   { { 23, 1,  1, (mp_limb_t *) mpfr_l2b_2_0__tab },
1294     { 77, 1,  1, (mp_limb_t *) mpfr_l2b_2_1__tab } },
1295   { { 23, 1,  1, (mp_limb_t *) mpfr_l2b_3_0__tab },
1296     { 77, 1,  0, (mp_limb_t *) mpfr_l2b_3_1__tab } },
1297   { { 23, 1,  2, (mp_limb_t *) mpfr_l2b_4_0__tab },
1298     { 77, 1,  0, (mp_limb_t *) mpfr_l2b_4_1__tab } },
1299   { { 23, 1,  2, (mp_limb_t *) mpfr_l2b_5_0__tab },
1300     { 77, 1, -1, (mp_limb_t *) mpfr_l2b_5_1__tab } },
1301   { { 23, 1,  2, (mp_limb_t *) mpfr_l2b_6_0__tab },
1302     { 77, 1, -1, (mp_limb_t *) mpfr_l2b_6_1__tab } },
1303   { { 23, 1,  2, (mp_limb_t *) mpfr_l2b_7_0__tab },
1304     { 77, 1, -1, (mp_limb_t *) mpfr_l2b_7_1__tab } },
1305   { { 23, 1,  2, (mp_limb_t *) mpfr_l2b_8_0__tab },
1306     { 77, 1, -1, (mp_limb_t *) mpfr_l2b_8_1__tab } },
1307   { { 23, 1,  2, (mp_limb_t *) mpfr_l2b_9_0__tab },
1308     { 77, 1, -1, (mp_limb_t *) mpfr_l2b_9_1__tab } },
1309   { { 23, 1,  2, (mp_limb_t *) mpfr_l2b_10_0__tab },
1310     { 77, 1, -1, (mp_limb_t *) mpfr_l2b_10_1__tab } },
1311   { { 23, 1,  2, (mp_limb_t *) mpfr_l2b_11_0__tab },
1312     { 77, 1, -1, (mp_limb_t *) mpfr_l2b_11_1__tab } },
1313   { { 23, 1,  2, (mp_limb_t *) mpfr_l2b_12_0__tab },
1314     { 77, 1, -1, (mp_limb_t *) mpfr_l2b_12_1__tab } },
1315   { { 23, 1,  2, (mp_limb_t *) mpfr_l2b_13_0__tab },
1316     { 77, 1, -1, (mp_limb_t *) mpfr_l2b_13_1__tab } },
1317   { { 23, 1,  2, (mp_limb_t *) mpfr_l2b_14_0__tab },
1318     { 77, 1, -1, (mp_limb_t *) mpfr_l2b_14_1__tab } },
1319   { { 23, 1,  2, (mp_limb_t *) mpfr_l2b_15_0__tab },
1320     { 77, 1, -1, (mp_limb_t *) mpfr_l2b_15_1__tab } },
1321   { { 23, 1,  3, (mp_limb_t *) mpfr_l2b_16_0__tab },
1322     { 77, 1, -1, (mp_limb_t *) mpfr_l2b_16_1__tab } },
1323   { { 23, 1,  3, (mp_limb_t *) mpfr_l2b_17_0__tab },
1324     { 77, 1, -2, (mp_limb_t *) mpfr_l2b_17_1__tab } },
1325   { { 23, 1,  3, (mp_limb_t *) mpfr_l2b_18_0__tab },
1326     { 77, 1, -2, (mp_limb_t *) mpfr_l2b_18_1__tab } },
1327   { { 23, 1,  3, (mp_limb_t *) mpfr_l2b_19_0__tab },
1328     { 77, 1, -2, (mp_limb_t *) mpfr_l2b_19_1__tab } },
1329   { { 23, 1,  3, (mp_limb_t *) mpfr_l2b_20_0__tab },
1330     { 77, 1, -2, (mp_limb_t *) mpfr_l2b_20_1__tab } },
1331   { { 23, 1,  3, (mp_limb_t *) mpfr_l2b_21_0__tab },
1332     { 77, 1, -2, (mp_limb_t *) mpfr_l2b_21_1__tab } },
1333   { { 23, 1,  3, (mp_limb_t *) mpfr_l2b_22_0__tab },
1334     { 77, 1, -2, (mp_limb_t *) mpfr_l2b_22_1__tab } },
1335   { { 23, 1,  3, (mp_limb_t *) mpfr_l2b_23_0__tab },
1336     { 77, 1, -2, (mp_limb_t *) mpfr_l2b_23_1__tab } },
1337   { { 23, 1,  3, (mp_limb_t *) mpfr_l2b_24_0__tab },
1338     { 77, 1, -2, (mp_limb_t *) mpfr_l2b_24_1__tab } },
1339   { { 23, 1,  3, (mp_limb_t *) mpfr_l2b_25_0__tab },
1340     { 77, 1, -2, (mp_limb_t *) mpfr_l2b_25_1__tab } },
1341   { { 23, 1,  3, (mp_limb_t *) mpfr_l2b_26_0__tab },
1342     { 77, 1, -2, (mp_limb_t *) mpfr_l2b_26_1__tab } },
1343   { { 23, 1,  3, (mp_limb_t *) mpfr_l2b_27_0__tab },
1344     { 77, 1, -2, (mp_limb_t *) mpfr_l2b_27_1__tab } },
1345   { { 23, 1,  3, (mp_limb_t *) mpfr_l2b_28_0__tab },
1346     { 77, 1, -2, (mp_limb_t *) mpfr_l2b_28_1__tab } },
1347   { { 23, 1,  3, (mp_limb_t *) mpfr_l2b_29_0__tab },
1348     { 77, 1, -2, (mp_limb_t *) mpfr_l2b_29_1__tab } },
1349   { { 23, 1,  3, (mp_limb_t *) mpfr_l2b_30_0__tab },
1350     { 77, 1, -2, (mp_limb_t *) mpfr_l2b_30_1__tab } },
1351   { { 23, 1,  3, (mp_limb_t *) mpfr_l2b_31_0__tab },
1352     { 77, 1, -2, (mp_limb_t *) mpfr_l2b_31_1__tab } },
1353   { { 23, 1,  3, (mp_limb_t *) mpfr_l2b_32_0__tab },
1354     { 77, 1, -2, (mp_limb_t *) mpfr_l2b_32_1__tab } },
1355   { { 23, 1,  3, (mp_limb_t *) mpfr_l2b_33_0__tab },
1356     { 77, 1, -2, (mp_limb_t *) mpfr_l2b_33_1__tab } },
1357   { { 23, 1,  3, (mp_limb_t *) mpfr_l2b_34_0__tab },
1358     { 77, 1, -2, (mp_limb_t *) mpfr_l2b_34_1__tab } },
1359   { { 23, 1,  3, (mp_limb_t *) mpfr_l2b_35_0__tab },
1360     { 77, 1, -2, (mp_limb_t *) mpfr_l2b_35_1__tab } },
1361   { { 23, 1,  3, (mp_limb_t *) mpfr_l2b_36_0__tab },
1362     { 77, 1, -2, (mp_limb_t *) mpfr_l2b_36_1__tab } } };
1363
1364 /***************************************************************************/
1365
1366 /* returns ceil(e * log2(b)^((-1)^i)), or ... + 1 */
1367 static mp_exp_t
1368 ceil_mul (mp_exp_t e, int beta, int i)
1369 {
1370   mpfr_srcptr p;
1371   mpfr_t t;
1372   mp_exp_t r;
1373
1374   p = &__gmpfr_l2b[beta-2][i];
1375   mpfr_init2 (t, sizeof (mp_exp_t) * CHAR_BIT);
1376   mpfr_set_exp_t (t, e, GMP_RNDU);
1377   mpfr_mul (t, t, p, GMP_RNDU);
1378   r = mpfr_get_exp_t (t, GMP_RNDU);
1379   mpfr_clear (t);
1380   return r;
1381 }
1382
1383 /* prints the mantissa of x in the string s, and writes the corresponding
1384    exponent in e.
1385    x is rounded with direction rnd, m is the number of digits of the mantissa,
1386    b is the given base (2 <= b <= 36).
1387
1388    Return value:
1389    if s=NULL, allocates a string to store the mantissa, with
1390    m characters, plus a final '\0', plus a possible minus sign
1391    (thus m+1 or m+2 characters).
1392
1393    Important: when you call this function with s=NULL, don't forget to free
1394    the memory space allocated, with free(s, strlen(s)).
1395 */
1396 char*
1397 mpfr_get_str (char *s, mp_exp_t *e, int b, size_t m, mpfr_srcptr x, mp_rnd_t rnd)
1398 {
1399   int exact;                      /* exact result */
1400   mp_exp_t exp, g;
1401   mp_exp_t prec; /* precision of the computation */
1402   long err;
1403   mp_limb_t *a;
1404   mp_exp_t exp_a;
1405   mp_limb_t *result;
1406   mp_limb_t *xp;
1407   mp_limb_t *reste;
1408   size_t nx, nx1;
1409   size_t n, i;
1410   char *s0;
1411   int neg;
1412   int ret; /* return value of mpfr_get_str_aux */
1413   MPFR_ZIV_DECL (loop);
1414   MPFR_SAVE_EXPO_DECL (expo);
1415   MPFR_TMP_DECL(marker);
1416
1417   /* if exact = 1 then err is undefined */
1418   /* otherwise err is such that |x*b^(m-g)-a*2^exp_a| < 2^(err+exp_a) */
1419
1420   /* is the base valid? */
1421   if (b < 2 || b > 36)
1422     return NULL;
1423
1424   if (MPFR_UNLIKELY (MPFR_IS_NAN (x)))
1425     {
1426       if (s == NULL)
1427         s = (char *) (*__gmp_allocate_func) (6);
1428       strcpy (s, "@NaN@");
1429       return s;
1430     }
1431
1432   neg = MPFR_SIGN(x) < 0; /* 0 if positive, 1 if negative */
1433
1434   if (MPFR_UNLIKELY (MPFR_IS_INF (x)))
1435     {
1436       if (s == NULL)
1437         s = (char *) (*__gmp_allocate_func) (neg + 6);
1438       strcpy (s, (neg) ? "-@Inf@" : "@Inf@");
1439       return s;
1440     }
1441
1442   MPFR_SAVE_EXPO_MARK (expo);  /* needed for ceil_mul (at least) */
1443
1444   if (m == 0)
1445     {
1446
1447       /* take at least 1 + ceil(n*log(2)/log(b)) digits, where n is the
1448          number of bits of the mantissa, to ensure back conversion from
1449          the output gives the same floating-point.
1450
1451          Warning: if b = 2^k, this may be too large. The worst case is when
1452          the first base-b digit contains only one bit, so we get
1453          1 + ceil((n-1)/k) = 2 + floor((n-2)/k) instead.
1454       */
1455       m = 1 + ceil_mul (IS_POW2(b) ? MPFR_PREC(x) - 1 : MPFR_PREC(x), b, 1);
1456       if (m < 2)
1457         m = 2;
1458     }
1459
1460   /* the code below for non-power-of-two bases works for m=1 */
1461   MPFR_ASSERTN (m >= 2 || (IS_POW2(b) == 0 && m >= 1));
1462
1463   /* x is a floating-point number */
1464
1465   if (MPFR_IS_ZERO(x))
1466     {
1467       if (s == NULL)
1468         s = (char*) (*__gmp_allocate_func) (neg + m + 1);
1469       s0 = s;
1470       if (neg)
1471         *s++ = '-';
1472       memset (s, '0', m);
1473       s[m] = '\0';
1474       *e = 0; /* a bit like frexp() in ISO C99 */
1475       MPFR_SAVE_EXPO_FREE (expo);
1476       return s0; /* strlen(s0) = neg + m */
1477     }
1478
1479   if (s == NULL)
1480     s = (char*) (*__gmp_allocate_func) (neg + m + 1);
1481   s0 = s;
1482   if (neg)
1483     *s++ = '-';
1484
1485   xp = MPFR_MANT(x);
1486
1487   if (IS_POW2(b))
1488     {
1489       int pow2;
1490       mp_exp_t f, r;
1491       mp_limb_t *x1;
1492       mp_size_t nb;
1493       int inexp;
1494
1495       count_leading_zeros (pow2, (mp_limb_t) b);
1496       pow2 = BITS_PER_MP_LIMB - pow2 - 1; /* base = 2^pow2 */
1497
1498       /* set MPFR_EXP(x) = f*pow2 + r, 1 <= r <= pow2 */
1499       f = (MPFR_GET_EXP (x) - 1) / pow2;
1500       r = MPFR_GET_EXP (x) - f * pow2;
1501       if (r <= 0)
1502         {
1503           f --;
1504           r += pow2;
1505         }
1506
1507       /* the first digit will contain only r bits */
1508       prec = (m - 1) * pow2 + r; /* total number of bits */
1509       n = (prec - 1) / BITS_PER_MP_LIMB + 1;
1510
1511       MPFR_TMP_MARK (marker);
1512       x1 = (mp_limb_t*) MPFR_TMP_ALLOC((n + 1) * sizeof (mp_limb_t));
1513       nb = n * BITS_PER_MP_LIMB - prec;
1514       /* round xp to the precision prec, and put it into x1
1515          put the carry into x1[n] */
1516       if ((x1[n] = mpfr_round_raw (x1, xp, MPFR_PREC(x),
1517                                   MPFR_IS_STRICTNEG(x),
1518                                    prec, rnd, &inexp)))
1519         {
1520           /* overflow when rounding x: x1 = 2^prec */
1521           if (r == pow2)    /* prec = m * pow2,
1522                                2^prec will need (m+1) digits in base 2^pow2 */
1523             {
1524               /* divide x1 by 2^pow2, and increase the exponent */
1525               mpn_rshift (x1, x1, n + 1, pow2);
1526               f ++;
1527             }
1528           else /* 2^prec needs still m digits, but x1 may need n+1 limbs */
1529             n ++;
1530         }
1531
1532       /* it remains to shift x1 by nb limbs to the right, since mpn_get_str
1533          expects a right-normalized number */
1534       if (nb != 0)
1535         {
1536           mpn_rshift (x1, x1, n, nb);
1537           /* the most significant word may be zero */
1538           if (x1[n - 1] == 0)
1539             n --;
1540         }
1541
1542       mpn_get_str ((unsigned char*) s, b, x1, n);
1543       for (i=0; i<m; i++)
1544         s[i] = num_to_text[(int) s[i]];
1545       s[m] = 0;
1546
1547       /* the exponent of s is f + 1 */
1548       *e = f + 1;
1549
1550       MPFR_TMP_FREE(marker);
1551       MPFR_SAVE_EXPO_FREE (expo);
1552       return (s0);
1553     }
1554
1555   /* if x < 0, reduce to x > 0 */
1556   if (neg)
1557     rnd = MPFR_INVERT_RND(rnd);
1558
1559   g = ceil_mul (MPFR_GET_EXP (x) - 1, b, 1);
1560   exact = 1;
1561   prec = ceil_mul (m, b, 0) + 1;
1562   exp = ((mp_exp_t) m < g) ? g - (mp_exp_t) m : (mp_exp_t) m - g;
1563   prec += MPFR_INT_CEIL_LOG2 (prec); /* number of guard bits */
1564   if (exp != 0) /* add maximal exponentiation error */
1565     prec += 3 * (mp_exp_t) MPFR_INT_CEIL_LOG2 (exp);
1566
1567   MPFR_ZIV_INIT (loop, prec);
1568   for (;;)
1569     {
1570       MPFR_TMP_MARK(marker);
1571
1572       exact = 1;
1573
1574       /* number of limbs */
1575       n = 1 + (prec - 1) / BITS_PER_MP_LIMB;
1576
1577       /* a will contain the approximation of the mantissa */
1578       a = (mp_limb_t*) MPFR_TMP_ALLOC (n * sizeof (mp_limb_t));
1579
1580       nx = 1 + (MPFR_PREC(x) - 1) / BITS_PER_MP_LIMB;
1581
1582       if ((mp_exp_t) m == g) /* final exponent is 0, no multiplication or
1583                                 division to perform */
1584         {
1585           if (nx > n)
1586             exact = mpn_scan1 (xp, 0) >= (nx - n) * BITS_PER_MP_LIMB;
1587           err = !exact;
1588           MPN_COPY2 (a, n, xp, nx);
1589           exp_a = MPFR_GET_EXP (x) - n * BITS_PER_MP_LIMB;
1590         }
1591       else if ((mp_exp_t) m > g) /* we have to multiply x by b^exp */
1592         {
1593           mp_limb_t *x1;
1594
1595           /* a2*2^exp_a =  b^e */
1596           err = mpfr_mpn_exp (a, &exp_a, b, exp, n);
1597           /* here, the error on a is at most 2^err ulps */
1598           exact = (err == -1);
1599
1600           /* x = x1*2^(n*BITS_PER_MP_LIMB) */
1601           x1 = (nx >= n) ? xp + nx - n : xp;
1602           nx1 = (nx >= n) ? n : nx; /* nx1 = min(n, nx) */
1603
1604           /* test si exact */
1605           if (nx > n)
1606             exact = (exact &&
1607                      ((mpn_scan1 (xp, 0) >= (nx - n) * BITS_PER_MP_LIMB)));
1608
1609           /* we loose one more bit in the multiplication,
1610              except when err=0 where we loose two bits */
1611           err = (err <= 0) ? 2 : err + 1;
1612
1613           /* result = a * x */
1614           result = (mp_limb_t*) MPFR_TMP_ALLOC ((n + nx1) * sizeof (mp_limb_t));
1615           mpn_mul (result, a, n, x1, nx1);
1616           exp_a += MPFR_GET_EXP (x);
1617           if (mpn_scan1 (result, 0) < (nx1 * BITS_PER_MP_LIMB))
1618             exact = 0;
1619
1620           /* normalize a and truncate */
1621           if ((result[n + nx1 - 1] & MPFR_LIMB_HIGHBIT) == 0)
1622             {
1623               mpn_lshift (a, result + nx1, n , 1);
1624               a[0] |= result[nx1 - 1] >> (BITS_PER_MP_LIMB - 1);
1625               exp_a --;
1626             }
1627           else
1628             MPN_COPY (a, result + nx1, n);
1629         }
1630       else
1631         {
1632           mp_limb_t *x1;
1633
1634           /* a2*2^exp_a =  b^e */
1635           err = mpfr_mpn_exp (a, &exp_a, b, exp, n);
1636           exact = (err == -1);
1637
1638           /* allocate memory for x1, result and reste */
1639           x1 = (mp_limb_t*) MPFR_TMP_ALLOC (2 * n * sizeof (mp_limb_t));
1640           result = (mp_limb_t*) MPFR_TMP_ALLOC ((n + 1) * sizeof (mp_limb_t));
1641           reste = (mp_limb_t*) MPFR_TMP_ALLOC (n * sizeof (mp_limb_t));
1642
1643           /* initialize x1 = x */
1644           MPN_COPY2 (x1, 2 * n, xp, nx);
1645           if ((exact) && (nx > 2 * n) &&
1646               (mpn_scan1 (xp, 0) < (nx - 2 * n) * BITS_PER_MP_LIMB))
1647             exact = 0;
1648
1649           /* result = x / a */
1650           mpn_tdiv_qr (result, reste, 0, x1, 2 * n, a, n);
1651           exp_a = MPFR_GET_EXP (x) - exp_a - 2 * n * BITS_PER_MP_LIMB;
1652
1653           /* test if division was exact */
1654           if (exact)
1655             exact = mpn_popcount (reste, n) == 0;
1656
1657           /* normalize the result and copy into a */
1658           if (result[n] == 1)
1659             {
1660               mpn_rshift (a, result, n, 1);
1661               a[n - 1] |= MPFR_LIMB_HIGHBIT;;
1662               exp_a ++;
1663             }
1664           else
1665             MPN_COPY (a, result, n);
1666
1667           err = (err == -1) ? 2 : err + 2;
1668         }
1669
1670       /* check if rounding is possible */
1671       if (exact)
1672         err = -1;
1673       ret = mpfr_get_str_aux (s, e, a, n, exp_a, err, b, m, rnd);
1674       if (ret == MPFR_ROUND_FAILED)
1675         {
1676           /* too large error: increment the working precision */
1677           MPFR_ZIV_NEXT (loop, prec);
1678         }
1679       else if (ret == -MPFR_ROUND_FAILED)
1680         {
1681           /* too many digits in mantissa: exp = |m-g| */
1682           if ((mp_exp_t) m > g) /* exp = m - g, multiply by b^exp */
1683             {
1684               g++;
1685               exp --;
1686             }
1687           else /* exp = g - m, divide by b^exp */
1688             {
1689               g++;
1690               exp ++;
1691             }
1692         }
1693       else
1694         break;
1695
1696       MPFR_TMP_FREE(marker);
1697     }
1698   MPFR_ZIV_FREE (loop);
1699
1700   *e += g;
1701
1702   MPFR_TMP_FREE(marker);
1703   MPFR_SAVE_EXPO_FREE (expo);
1704   return s0;
1705 }
1706
1707 void mpfr_free_str (char *str)
1708 {
1709    (*__gmp_free_func) (str, strlen (str) + 1);
1710 }