2 Copyright (C) 2007, 2009, 2011 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17 /* Written by Bruno Haible <bruno@clisp.org>, 2011. */
19 #if ! defined USE_LONG_DOUBLE
34 #include "integer_length.h"
37 #ifdef USE_LONG_DOUBLE
39 # define DOUBLE long double
42 # define MIN_EXP LDBL_MIN_EXP
43 # define MANT_BIT LDBL_MANT_BIT
44 # define DECL_ROUNDING DECL_LONG_DOUBLE_ROUNDING
45 # define BEGIN_ROUNDING() BEGIN_LONG_DOUBLE_ROUNDING ()
46 # define END_ROUNDING() END_LONG_DOUBLE_ROUNDING ()
47 # define L_(literal) literal##L
48 #elif ! defined USE_FLOAT
50 # define DOUBLE double
53 # define MIN_EXP DBL_MIN_EXP
54 # define MANT_BIT DBL_MANT_BIT
55 # define DECL_ROUNDING
56 # define BEGIN_ROUNDING()
57 # define END_ROUNDING()
58 # define L_(literal) literal
59 #else /* defined USE_FLOAT */
64 # define MIN_EXP FLT_MIN_EXP
65 # define MANT_BIT FLT_MANT_BIT
66 # define DECL_ROUNDING
67 # define BEGIN_ROUNDING()
68 # define END_ROUNDING()
69 # define L_(literal) literal##f
73 #define MAX(a,b) ((a) > (b) ? (a) : (b))
76 #define MIN(a,b) ((a) < (b) ? (a) : (b))
78 /* It is possible to write an implementation of fused multiply-add with
79 floating-point operations alone. See
80 Sylvie Boldo, Guillaume Melquiond:
81 Emulation of FMA and correctly-rounded sums: proved algorithms using
83 <http://www.lri.fr/~melquion/doc/08-tc.pdf>
84 But is it complicated.
85 Here we take the simpler (and probably slower) approach of doing
86 multi-precision arithmetic. */
88 /* We use the naming conventions of GNU gmp, but vastly simpler (and slower)
91 typedef unsigned int mp_limb_t;
92 #define GMP_LIMB_BITS 32
93 verify (sizeof (mp_limb_t) * CHAR_BIT == GMP_LIMB_BITS);
95 typedef unsigned long long mp_twolimb_t;
96 #define GMP_TWOLIMB_BITS 64
97 verify (sizeof (mp_twolimb_t) * CHAR_BIT == GMP_TWOLIMB_BITS);
99 /* Number of limbs needed for a single DOUBLE. */
100 #define NLIMBS1 ((MANT_BIT + GMP_LIMB_BITS - 1) / GMP_LIMB_BITS)
102 /* Number of limbs needed for the accumulator. */
103 #define NLIMBS3 (3 * NLIMBS1 + 1)
105 /* Assuming 0.5 <= x < 1.0:
106 Convert the mantissa (x * 2^DBL_MANT_BIT) to a sequence of limbs. */
108 decode (DOUBLE x, mp_limb_t limbs[NLIMBS1])
110 /* I'm not sure whether it's safe to cast a 'double' value between
111 2^31 and 2^32 to 'unsigned int', therefore play safe and cast only
112 'double' values between 0 and 2^31 (to 'unsigned int' or 'int',
114 So, we split the MANT_BIT bits of x into a number of chunks of
116 enum { chunk_count = (MANT_BIT - 1) / 31 + 1 };
117 /* Variables used for storing the bits limb after limb. */
118 mp_limb_t *p = limbs + NLIMBS1 - 1;
120 unsigned int bits_needed = MANT_BIT - (NLIMBS1 - 1) * GMP_LIMB_BITS;
121 /* The bits bits_needed-1...0 need to be ORed into the accu.
122 1 <= bits_needed <= GMP_LIMB_BITS. */
123 /* Unroll the first 4 loop rounds. */
126 /* Here we still have MANT_BIT-0*31 bits to extract from x. */
127 enum { chunk_bits = MIN (31, MANT_BIT - 0 * 31) }; /* > 0, <= 31 */
129 x *= (mp_limb_t) 1 << chunk_bits;
130 d = (int) x; /* 0 <= d < 2^chunk_bits. */
132 if (!(x >= L_(0.0) && x < L_(1.0)))
134 if (bits_needed < chunk_bits)
136 /* store bits_needed bits */
137 accu |= d >> (chunk_bits - bits_needed);
142 /* hold (chunk_bits - bits_needed) bits */
143 accu = d << (GMP_LIMB_BITS - (chunk_bits - bits_needed));
144 bits_needed = GMP_LIMB_BITS - (chunk_bits - bits_needed);
148 /* store chunk_bits bits */
149 accu |= d << (bits_needed - chunk_bits);
150 bits_needed -= chunk_bits;
151 if (bits_needed == 0)
158 bits_needed = GMP_LIMB_BITS;
164 /* Here we still have MANT_BIT-1*31 bits to extract from x. */
165 enum { chunk_bits = MIN (31, MAX (MANT_BIT - 1 * 31, 0)) }; /* > 0, <= 31 */
167 x *= (mp_limb_t) 1 << chunk_bits;
168 d = (int) x; /* 0 <= d < 2^chunk_bits. */
170 if (!(x >= L_(0.0) && x < L_(1.0)))
172 if (bits_needed < chunk_bits)
174 /* store bits_needed bits */
175 accu |= d >> (chunk_bits - bits_needed);
180 /* hold (chunk_bits - bits_needed) bits */
181 accu = d << (GMP_LIMB_BITS - (chunk_bits - bits_needed));
182 bits_needed = GMP_LIMB_BITS - (chunk_bits - bits_needed);
186 /* store chunk_bits bits */
187 accu |= d << (bits_needed - chunk_bits);
188 bits_needed -= chunk_bits;
189 if (bits_needed == 0)
196 bits_needed = GMP_LIMB_BITS;
202 /* Here we still have MANT_BIT-2*31 bits to extract from x. */
203 enum { chunk_bits = MIN (31, MAX (MANT_BIT - 2 * 31, 0)) }; /* > 0, <= 31 */
205 x *= (mp_limb_t) 1 << chunk_bits;
206 d = (int) x; /* 0 <= d < 2^chunk_bits. */
208 if (!(x >= L_(0.0) && x < L_(1.0)))
210 if (bits_needed < chunk_bits)
212 /* store bits_needed bits */
213 accu |= d >> (chunk_bits - bits_needed);
218 /* hold (chunk_bits - bits_needed) bits */
219 accu = d << (GMP_LIMB_BITS - (chunk_bits - bits_needed));
220 bits_needed = GMP_LIMB_BITS - (chunk_bits - bits_needed);
224 /* store chunk_bits bits */
225 accu |= d << (bits_needed - chunk_bits);
226 bits_needed -= chunk_bits;
227 if (bits_needed == 0)
234 bits_needed = GMP_LIMB_BITS;
240 /* Here we still have MANT_BIT-3*31 bits to extract from x. */
241 enum { chunk_bits = MIN (31, MAX (MANT_BIT - 3 * 31, 0)) }; /* > 0, <= 31 */
243 x *= (mp_limb_t) 1 << chunk_bits;
244 d = (int) x; /* 0 <= d < 2^chunk_bits. */
246 if (!(x >= L_(0.0) && x < L_(1.0)))
248 if (bits_needed < chunk_bits)
250 /* store bits_needed bits */
251 accu |= d >> (chunk_bits - bits_needed);
256 /* hold (chunk_bits - bits_needed) bits */
257 accu = d << (GMP_LIMB_BITS - (chunk_bits - bits_needed));
258 bits_needed = GMP_LIMB_BITS - (chunk_bits - bits_needed);
262 /* store chunk_bits bits */
263 accu |= d << (bits_needed - chunk_bits);
264 bits_needed -= chunk_bits;
265 if (bits_needed == 0)
272 bits_needed = GMP_LIMB_BITS;
278 /* Here we still have MANT_BIT-4*31 bits to extract from x. */
281 for (k = 4; k < chunk_count; k++)
283 size_t chunk_bits = MIN (31, MANT_BIT - k * 31); /* > 0, <= 31 */
285 x *= (mp_limb_t) 1 << chunk_bits;
286 d = (int) x; /* 0 <= d < 2^chunk_bits. */
288 if (!(x >= L_(0.0) && x < L_(1.0)))
290 if (bits_needed < chunk_bits)
292 /* store bits_needed bits */
293 accu |= d >> (chunk_bits - bits_needed);
298 /* hold (chunk_bits - bits_needed) bits */
299 accu = d << (GMP_LIMB_BITS - (chunk_bits - bits_needed));
300 bits_needed = GMP_LIMB_BITS - (chunk_bits - bits_needed);
304 /* store chunk_bits bits */
305 accu |= d << (bits_needed - chunk_bits);
306 bits_needed -= chunk_bits;
307 if (bits_needed == 0)
314 bits_needed = GMP_LIMB_BITS;
319 /* We shouldn't get here. */
323 #ifndef USE_LONG_DOUBLE /* On FreeBSD 6.1/x86, 'long double' numbers sometimes
324 have excess precision. */
330 /* Multiply two sequences of limbs. */
332 multiply (mp_limb_t xlimbs[NLIMBS1], mp_limb_t ylimbs[NLIMBS1],
333 mp_limb_t prod_limbs[2 * NLIMBS1])
336 enum { len1 = NLIMBS1 };
337 enum { len2 = NLIMBS1 };
339 for (k = len2; k > 0; )
341 for (i = 0; i < len1; i++)
343 mp_limb_t digit1 = xlimbs[i];
344 mp_twolimb_t carry = 0;
345 for (j = 0; j < len2; j++)
347 mp_limb_t digit2 = ylimbs[j];
348 carry += (mp_twolimb_t) digit1 * (mp_twolimb_t) digit2;
349 carry += prod_limbs[i + j];
350 prod_limbs[i + j] = (mp_limb_t) carry;
351 carry = carry >> GMP_LIMB_BITS;
353 prod_limbs[i + len2] = (mp_limb_t) carry;
358 FUNC (DOUBLE x, DOUBLE y, DOUBLE z)
360 if (isfinite (x) && isfinite (y))
364 /* x, y, z are all finite. */
365 if (x == L_(0.0) || y == L_(0.0))
369 /* x, y, z are all non-zero.
370 The result is x * y + z. */
372 int e; /* exponent of x * y + z */
374 mp_limb_t sum[NLIMBS3];
378 int xys; /* sign of x * y */
379 int zs; /* sign of z */
380 int xye; /* sum of exponents of x and y */
381 int ze; /* exponent of z */
382 mp_limb_t summand1[NLIMBS3];
384 mp_limb_t summand2[NLIMBS3];
388 mp_limb_t zlimbs[NLIMBS1];
389 mp_limb_t xylimbs[2 * NLIMBS1];
392 DOUBLE xn; /* normalized part of x */
393 DOUBLE yn; /* normalized part of y */
394 DOUBLE zn; /* normalized part of z */
395 int xe; /* exponent of x */
396 int ye; /* exponent of y */
397 mp_limb_t xlimbs[NLIMBS1];
398 mp_limb_t ylimbs[NLIMBS1];
422 /* xn, yn, zn are all positive.
423 The result is (-1)^xys * xn * yn + (-1)^zs * zn. */
424 xn = FREXP (xn, &xe);
425 yn = FREXP (yn, &ye);
426 zn = FREXP (zn, &ze);
428 /* xn, yn, zn are all < 1.0 and >= 0.5.
430 (-1)^xys * 2^xye * xn * yn + (-1)^zs * 2^ze * zn. */
431 if (xye < ze - MANT_BIT)
433 /* 2^xye * xn * yn < 2^xye <= 2^(ze-MANT_BIT-1) */
436 if (xye - 2 * MANT_BIT > ze)
438 /* 2^ze * zn < 2^ze <= 2^(xye-2*MANT_BIT-1).
441 because it would round differently: A round-to-even
442 in the multiplication can be a round-up or round-down
443 here, due to z. So replace z with a value that doesn't
444 require the use of long bignums but that rounds the
447 ze = xye - 2 * MANT_BIT - 1;
449 /* Convert mantissas of xn, yn, zn to limb sequences:
450 xlimbs = 2^MANT_BIT * xn
451 ylimbs = 2^MANT_BIT * yn
452 zlimbs = 2^MANT_BIT * zn */
456 /* Multiply the mantissas of xn and yn:
457 xylimbs = xlimbs * ylimbs */
458 multiply (xlimbs, ylimbs, xylimbs);
461 (-1)^xys * 2^(xye-2*MANT_BIT) * xylimbs
462 + (-1)^zs * 2^(ze-MANT_BIT) * zlimbs.
464 e = min (xye-2*MANT_BIT, ze-MANT_BIT)
466 summand1 = 2^(xye-2*MANT_BIT-e) * xylimbs
467 summand2 = 2^(ze-MANT_BIT-e) * zlimbs */
468 e = MIN (xye - 2 * MANT_BIT, ze - MANT_BIT);
469 if (e == xye - 2 * MANT_BIT)
471 /* Simply copy the limbs of xylimbs. */
473 for (i = 0; i < 2 * NLIMBS1; i++)
474 summand1[i] = xylimbs[i];
475 summand1_len = 2 * NLIMBS1;
479 size_t ediff = xye - 2 * MANT_BIT - e;
480 /* Left shift the limbs of xylimbs by ediff bits. */
481 size_t ldiff = ediff / GMP_LIMB_BITS;
482 size_t shift = ediff % GMP_LIMB_BITS;
484 for (i = 0; i < ldiff; i++)
489 for (i = 0; i < 2 * NLIMBS1; i++)
491 summand1[ldiff + i] = (xylimbs[i] << shift) | carry;
492 carry = xylimbs[i] >> (GMP_LIMB_BITS - shift);
494 summand1[ldiff + 2 * NLIMBS1] = carry;
495 summand1_len = ldiff + 2 * NLIMBS1 + 1;
499 for (i = 0; i < 2 * NLIMBS1; i++)
500 summand1[ldiff + i] = xylimbs[i];
501 summand1_len = ldiff + 2 * NLIMBS1;
503 /* Estimation of needed array size:
504 ediff = (xye - 2 * MANT_BIT) - (ze - MANT_BIT) <= MANT_BIT + 1
507 = (ediff + GMP_LIMB_BITS - 1) / GMP_LIMB_BITS + 2 * NLIMBS1
508 <= (MANT_BIT + GMP_LIMB_BITS) / GMP_LIMB_BITS + 2 * NLIMBS1
511 if (!(summand1_len <= NLIMBS3))
514 if (e == ze - MANT_BIT)
516 /* Simply copy the limbs of zlimbs. */
518 for (i = 0; i < NLIMBS1; i++)
519 summand2[i] = zlimbs[i];
520 summand2_len = NLIMBS1;
524 size_t ediff = ze - MANT_BIT - e;
525 /* Left shift the limbs of zlimbs by ediff bits. */
526 size_t ldiff = ediff / GMP_LIMB_BITS;
527 size_t shift = ediff % GMP_LIMB_BITS;
529 for (i = 0; i < ldiff; i++)
534 for (i = 0; i < NLIMBS1; i++)
536 summand2[ldiff + i] = (zlimbs[i] << shift) | carry;
537 carry = zlimbs[i] >> (GMP_LIMB_BITS - shift);
539 summand2[ldiff + NLIMBS1] = carry;
540 summand2_len = ldiff + NLIMBS1 + 1;
544 for (i = 0; i < NLIMBS1; i++)
545 summand2[ldiff + i] = zlimbs[i];
546 summand2_len = ldiff + NLIMBS1;
548 /* Estimation of needed array size:
549 ediff = (ze - MANT_BIT) - (xye - 2 * MANT_BIT) <= 2 * MANT_BIT
552 = (ediff + GMP_LIMB_BITS - 1) / GMP_LIMB_BITS + NLIMBS1
553 <= (2 * MANT_BIT + GMP_LIMB_BITS - 1) / GMP_LIMB_BITS + NLIMBS1
556 if (!(summand2_len <= NLIMBS3))
561 (-1)^xys * 2^e * summand1 + (-1)^zs * 2^e * summand2. */
564 /* Perform an addition. */
570 for (i = 0; i < MIN (summand1_len, summand2_len); i++)
572 mp_limb_t digit1 = summand1[i];
573 mp_limb_t digit2 = summand2[i];
574 sum[i] = digit1 + digit2 + carry;
576 ? digit1 >= (mp_limb_t)-1 - digit2
577 : digit1 > (mp_limb_t)-1 - digit2);
579 if (summand1_len > summand2_len)
580 for (; i < summand1_len; i++)
582 mp_limb_t digit1 = summand1[i];
583 sum[i] = carry + digit1;
584 carry = carry && digit1 == (mp_limb_t)-1;
587 for (; i < summand2_len; i++)
589 mp_limb_t digit2 = summand2[i];
590 sum[i] = carry + digit2;
591 carry = carry && digit2 == (mp_limb_t)-1;
599 /* Perform a subtraction. */
600 /* Compare summand1 and summand2 by magnitude. */
601 while (summand1[summand1_len - 1] == 0)
603 while (summand2[summand2_len - 1] == 0)
605 if (summand1_len > summand2_len)
607 else if (summand1_len < summand2_len)
611 size_t i = summand1_len;
615 if (summand1[i] > summand2[i])
620 if (summand1[i] < summand2[i])
626 /* summand1 and summand2 are equal. */
632 /* Compute summand1 - summand2. */
637 for (i = 0; i < summand2_len; i++)
639 mp_limb_t digit1 = summand1[i];
640 mp_limb_t digit2 = summand2[i];
641 sum[i] = digit1 - digit2 - carry;
642 carry = (carry ? digit1 <= digit2 : digit1 < digit2);
644 for (; i < summand1_len; i++)
646 mp_limb_t digit1 = summand1[i];
647 sum[i] = digit1 - carry;
648 carry = carry && digit1 == 0;
652 sum_len = summand1_len;
656 /* Compute summand2 - summand1. */
661 for (i = 0; i < summand1_len; i++)
663 mp_limb_t digit1 = summand1[i];
664 mp_limb_t digit2 = summand2[i];
665 sum[i] = digit2 - digit1 - carry;
666 carry = (carry ? digit2 <= digit1 : digit2 < digit1);
668 for (; i < summand2_len; i++)
670 mp_limb_t digit2 = summand2[i];
671 sum[i] = digit2 - carry;
672 carry = carry && digit2 == 0;
676 sum_len = summand2_len;
681 (-1)^sign * 2^e * sum. */
682 /* Now perform the rounding to MANT_BIT mantissa bits. */
683 while (sum[sum_len - 1] == 0)
685 /* Here we know that the most significant limb, sum[sum_len - 1], is
688 /* How many bits the sum has. */
689 unsigned int sum_bits =
690 integer_length (sum[sum_len - 1]) + (sum_len - 1) * GMP_LIMB_BITS;
691 /* How many bits to keep when rounding. */
692 unsigned int keep_bits;
693 /* How many bits to round off. */
694 unsigned int roundoff_bits;
695 if (e + (int) sum_bits >= MIN_EXP)
696 /* 2^e * sum >= 2^(MIN_EXP-1).
697 result will be a normalized number. */
698 keep_bits = MANT_BIT;
699 else if (e + (int) sum_bits >= MIN_EXP - MANT_BIT)
700 /* 2^e * sum >= 2^(MIN_EXP-MANT_BIT-1).
701 result will be a denormalized number or rounded to zero. */
702 keep_bits = e + (int) sum_bits - (MIN_EXP + MANT_BIT);
704 /* 2^e * sum < 2^(MIN_EXP-MANT_BIT-1). Round to zero. */
706 /* Note: 0 <= keep_bits <= MANT_BIT. */
707 if (sum_bits <= keep_bits)
711 keep_bits = sum_bits;
716 roundoff_bits = sum_bits - keep_bits; /* > 0, <= sum_bits */
718 #if HAVE_FEGETROUND && defined FE_TOWARDZERO
719 /* Cf. <http://pubs.opengroup.org/onlinepubs/9699919799/functions/fegetround.html> */
720 int rounding_mode = fegetround ();
721 if (rounding_mode == FE_TOWARDZERO)
723 else if (rounding_mode == FE_DOWNWARD)
725 else if (rounding_mode == FE_UPWARD)
728 /* Cf. <http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/float.h.html> */
729 int rounding_mode = FLT_ROUNDS;
730 if (rounding_mode == 0) /* toward zero */
732 else if (rounding_mode == 3) /* toward negative infinity */
734 else if (rounding_mode == 2) /* toward positive infinity */
739 /* Round to nearest. */
741 /* Test bit (roundoff_bits-1). */
742 if ((sum[(roundoff_bits - 1) / GMP_LIMB_BITS]
743 >> ((roundoff_bits - 1) % GMP_LIMB_BITS)) & 1)
745 /* Test bits roundoff_bits-1 .. 0. */
747 ((sum[(roundoff_bits - 1) / GMP_LIMB_BITS]
748 & (((mp_limb_t) 1 << ((roundoff_bits - 1) % GMP_LIMB_BITS)) - 1))
753 for (i = (roundoff_bits - 1) / GMP_LIMB_BITS - 1; i >= 0; i--)
761 /* Round to even. Test bit roundoff_bits. */
762 round_up = ((sum[roundoff_bits / GMP_LIMB_BITS]
763 >> (roundoff_bits % GMP_LIMB_BITS)) & 1);
770 /* Perform the rounding. */
772 size_t i = roundoff_bits / GMP_LIMB_BITS;
783 | (((mp_limb_t) 1 << (roundoff_bits % GMP_LIMB_BITS)) - 1))
787 /* Propagate carry. */
788 while (i < sum_len - 1)
796 /* sum[i] is the most significant limb that was
798 if (i == sum_len - 1 && (sum[i] & (sum[i] - 1)) == 0)
800 /* Through the carry, one more bit is needed. */
805 /* Instead of requiring one more limb of memory,
806 perform a shift by one bit, and adjust the
808 sum[i] = (mp_limb_t) 1 << (GMP_LIMB_BITS - 1);
811 /* The bit sequence has the form 1000...000. */
818 sum[i] &= ((mp_limb_t) -1 << (roundoff_bits % GMP_LIMB_BITS));
819 if (i == sum_len - 1 && sum[i] == 0)
820 /* The entire sum has become zero. */
826 (-1)^sign * 2^e * sum
827 and here we know that
828 2^(sum_bits-1) <= sum < 2^sum_bits,
829 and sum is a multiple of 2^(sum_bits-keep_bits), where
830 0 < keep_bits <= MANT_BIT and keep_bits <= sum_bits.
831 (If keep_bits was initially 0, the rounding either returned zero
832 or produced a bit sequence of the form 1000...000, setting
835 /* Split the keep_bits bits into chunks of at most 32 bits. */
836 unsigned int chunk_count = (keep_bits - 1) / GMP_LIMB_BITS + 1;
837 /* 1 <= chunk_count <= ceil (sum_bits / GMP_LIMB_BITS) = sum_len. */
838 static const DOUBLE chunk_multiplier = /* 2^-GMP_LIMB_BITS */
839 L_(1.0) / ((DOUBLE) (1 << (GMP_LIMB_BITS / 2))
840 * (DOUBLE) (1 << ((GMP_LIMB_BITS + 1) / 2)));
841 unsigned int shift = sum_bits % GMP_LIMB_BITS;
843 if (MANT_BIT <= GMP_LIMB_BITS)
845 /* Since keep_bits <= MANT_BIT <= GMP_LIMB_BITS,
846 chunk_count is 1. No need for a loop. */
848 fsum = (DOUBLE) sum[sum_len - 1];
851 ((sum[sum_len - 1] << (GMP_LIMB_BITS - shift))
852 | (sum_len >= 2 ? sum[sum_len - 2] >> shift : 0));
860 /* First loop round. */
861 fsum = (DOUBLE) sum[sum_len - k - 1];
865 fsum *= chunk_multiplier;
866 fsum += (DOUBLE) sum[sum_len - k - 1];
871 /* First loop round. */
873 ((sum[sum_len - k - 1] << (GMP_LIMB_BITS - shift))
874 | (sum_len >= k + 2 ? sum[sum_len - k - 2] >> shift : 0));
878 fsum *= chunk_multiplier;
880 ((sum[sum_len - k - 1] << (GMP_LIMB_BITS - shift))
881 | (sum[sum_len - k - 2] >> shift));
885 fsum = LDEXP (fsum, e + (int) sum_bits - GMP_LIMB_BITS);
886 return (sign ? - fsum : fsum);