Code coverage tests

This page documents the degree to which the PARI/GP source code is tested by our public test suite, distributed with the source distribution in directory src/test/. This is measured by the gcov utility; we then process gcov output using the lcov frond-end.

We test a few variants depending on Configure flags on the pari.math.u-bordeaux.fr machine (x86_64 architecture), and agregate them in the final report:

The target is 90% coverage for all mathematical modules (given that branches depending on DEBUGLEVEL or DEBUGMEM are not covered). This script is run to produce the results below.

LCOV - code coverage report
Current view: top level - kernel/none - mp_indep.c (source / functions) Hit Total Coverage
Test: PARI/GP v2.10.0 lcov report (development 20777-d2a9243) Lines: 521 566 92.0 %
Date: 2017-06-25 05:59:24 Functions: 51 53 96.2 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : #line 2 "../src/kernel/none/mp_indep.c"
       2             : /* Copyright (C) 2000  The PARI group.
       3             : 
       4             : This file is part of the PARI/GP package.
       5             : 
       6             : PARI/GP is free software; you can redistribute it and/or modify it under the
       7             : terms of the GNU General Public License as published by the Free Software
       8             : Foundation. It is distributed in the hope that it will be useful, but WITHOUT
       9             : ANY WARRANTY WHATSOEVER.
      10             : 
      11             : Check the License for details. You should have received a copy of it, along
      12             : with the package; see the file 'COPYING'. If not, write to the Free Software
      13             : Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
      14             : 
      15             : /* Find c such that 1=c*b mod 2^BITS_IN_LONG, assuming b odd (unchecked) */
      16             : ulong
      17    17789973 : invmod2BIL(ulong b)
      18             : {
      19             :   static int tab[] = { 0, 0, 0, 8, 0, 8, 0, 0 };
      20    17789973 :   ulong x = b + tab[b & 7]; /* b^(-1) mod 2^4 */
      21             : 
      22             :   /* Newton applied to 1/x - b = 0 */
      23             : #ifdef LONG_IS_64BIT
      24    17789973 :   x = x*(2-b*x); /* one more pass necessary */
      25             : #endif
      26    17789973 :   x = x*(2-b*x);
      27    17789973 :   x = x*(2-b*x); return x*(2-b*x);
      28             : }
      29             : 
      30             : void
      31   962852262 : affrr(GEN x, GEN y)
      32             : {
      33             :   long lx,ly,i;
      34             : 
      35   962852262 :   y[1] = x[1]; if (!signe(x)) return;
      36             : 
      37   957376651 :   lx=lg(x); ly=lg(y);
      38   957376651 :   if (lx <= ly)
      39             :   {
      40   898610944 :     for (i=2; i<lx; i++) y[i]=x[i];
      41   898610944 :     for (   ; i<ly; i++) y[i]=0;
      42   898610944 :     return;
      43             :   }
      44    58765707 :   for (i=2; i<ly; i++) y[i]=x[i];
      45             :   /* lx > ly: round properly */
      46    58765707 :   if (x[ly] & HIGHBIT) roundr_up_ip(y, ly);
      47             : }
      48             : 
      49             : GEN
      50     6634004 : trunc2nr(GEN x, long n)
      51             : {
      52             :   long ex;
      53     6634004 :   if (!signe(x)) return gen_0;
      54     6584618 :   ex = expo(x) + n; if (ex < 0) return gen_0;
      55     6247590 :   return mantissa2nr(x, ex - bit_prec(x) + 1);
      56             : }
      57             : 
      58             : /* x a t_REAL, x = i/2^e, i a t_INT */
      59             : GEN
      60    14863935 : mantissa_real(GEN x, long *e)
      61             : {
      62    14863935 :   *e = bit_prec(x)-1-expo(x);
      63    14863935 :   return mantissa2nr(x, 0);
      64             : }
      65             : 
      66             : GEN
      67   849663834 : mului(ulong x, GEN y)
      68             : {
      69   849663834 :   long s = signe(y);
      70             :   GEN z;
      71             : 
      72   849663834 :   if (!s || !x) return gen_0;
      73   795267664 :   z = muluispec(x, y+2, lgefint(y)-2);
      74   794560117 :   setsigne(z,s); return z;
      75             : }
      76             : 
      77             : GEN
      78   209981164 : mulsi(long x, GEN y)
      79             : {
      80   209981164 :   long s = signe(y);
      81             :   GEN z;
      82             : 
      83   209981164 :   if (!s || !x) return gen_0;
      84   161394800 :   if (x<0) { s = -s; x = -x; }
      85   161394800 :   z = muluispec((ulong)x, y+2, lgefint(y)-2);
      86   161394794 :   setsigne(z,s); return z;
      87             : }
      88             : 
      89             : GEN
      90   177094817 : mulss(long x, long y)
      91             : {
      92             :   long p1;
      93             :   LOCAL_HIREMAINDER;
      94             : 
      95   177094817 :   if (!x || !y) return gen_0;
      96   176997181 :   if (x<0) {
      97       59724 :     x = -x;
      98       59724 :     if (y<0) { y = -y; p1 = mulll(x,y); return uutoi(hiremainder, p1); }
      99       59724 :     p1 = mulll(x,y); return uutoineg(hiremainder, p1);
     100             :   } else {
     101   176937457 :     if (y<0) { y = -y; p1 = mulll(x,y); return uutoineg(hiremainder, p1); }
     102   176936868 :     p1 = mulll(x,y); return uutoi(hiremainder, p1);
     103             :   }
     104             : }
     105             : GEN
     106      898402 : sqrs(long x)
     107             : {
     108             :   long p1;
     109             :   LOCAL_HIREMAINDER;
     110             : 
     111      898402 :   if (!x) return gen_0;
     112      898304 :   if (x<0) x = -x;
     113      898304 :   p1 = mulll(x,x); return uutoi(hiremainder, p1);
     114             : }
     115             : GEN
     116  1792173334 : muluu(ulong x, ulong y)
     117             : {
     118             :   long p1;
     119             :   LOCAL_HIREMAINDER;
     120             : 
     121  1792173334 :   if (!x || !y) return gen_0;
     122  1792131376 :   p1 = mulll(x,y); return uutoi(hiremainder, p1);
     123             : }
     124             : GEN
     125   589159214 : sqru(ulong x)
     126             : {
     127             :   long p1;
     128             :   LOCAL_HIREMAINDER;
     129             : 
     130   589159214 :   if (!x) return gen_0;
     131   589131487 :   p1 = mulll(x,x); return uutoi(hiremainder, p1);
     132             : }
     133             : 
     134             : /* assume x > 1, y != 0. Return u * y with sign s */
     135             : static GEN
     136   435822834 : mulur_2(ulong x, GEN y, long s)
     137             : {
     138   435822834 :   long m, sh, i, lx = lg(y), e = expo(y);
     139   435822834 :   GEN z = cgetr(lx);
     140             :   ulong garde;
     141             :   LOCAL_HIREMAINDER;
     142             : 
     143   435822834 :   y--; garde = mulll(x,y[lx]);
     144   435822834 :   for (i=lx-1; i>=3; i--) z[i]=addmul(x,y[i]);
     145   435822834 :   z[2]=hiremainder; /* != 0 since y normalized and |x| > 1 */
     146   435822834 :   sh = bfffo(hiremainder); m = BITS_IN_LONG-sh;
     147   435822834 :   if (sh) shift_left(z,z, 2,lx-1, garde,sh);
     148   435822834 :   z[1] = evalsigne(s) | evalexpo(m+e);
     149   435822834 :   if ((garde << sh) & HIGHBIT) roundr_up_ip(z, lx);
     150   435822834 :   return z;
     151             : }
     152             : 
     153             : INLINE GEN
     154     1168298 : mul0r(GEN x)
     155             : {
     156     1168298 :   long l = lg(x), e = expo(x);
     157     1168298 :   e = (l > 2)? -prec2nbits(l) + e: (e < 0? 2*e: 0);
     158     1168298 :   return real_0_bit(e);
     159             : }
     160             : /* lg(x) > 2 */
     161             : INLINE GEN
     162       63608 : div0r(GEN x) {
     163       63608 :   long l = lg(x), e = expo(x);
     164       63608 :   return real_0_bit(-prec2nbits(l) - e);
     165             : }
     166             : 
     167             : GEN
     168    38929332 : mulsr(long x, GEN y)
     169             : {
     170             :   long s;
     171             : 
     172    38929332 :   if (!x) return mul0r(y);
     173    37911939 :   s = signe(y);
     174    37911939 :   if (!s)
     175             :   {
     176      222770 :     if (x < 0) x = -x;
     177      222770 :     return real_0_bit( expo(y) + expu(x) );
     178             :   }
     179    37689169 :   if (x==1)  return rcopy(y);
     180    36945175 :   if (x==-1) return negr(y);
     181    35954608 :   if (x < 0)
     182    20960332 :     return mulur_2((ulong)-x, y, -s);
     183             :   else
     184    14994276 :     return mulur_2((ulong)x, y, s);
     185             : }
     186             : 
     187             : GEN
     188   446443323 : mulur(ulong x, GEN y)
     189             : {
     190             :   long s;
     191             : 
     192   446443323 :   if (!x) return mul0r(y);
     193   446443323 :   s = signe(y);
     194   446443323 :   if (!s) return real_0_bit( expo(y) + expu(x) );
     195   444650699 :   if (x==1) return rcopy(y);
     196   399868226 :   return mulur_2(x, y, s);
     197             : }
     198             : 
     199             : INLINE void
     200  1014378646 : mulrrz_end(GEN z, GEN hi, long lz, long sz, long ez, ulong garde)
     201             : {
     202             :   long i;
     203  1014378646 :   if (hi[2] < 0)
     204             :   {
     205   461361959 :     if (z != hi)
     206    29614095 :       for (i=2; i<lz ; i++) z[i] = hi[i];
     207   461361959 :     ez++;
     208             :   }
     209             :   else
     210             :   {
     211   553016687 :     shift_left(z,hi,2,lz-1, garde, 1);
     212   553016687 :     garde <<= 1;
     213             :   }
     214  1014378646 :   if (garde & HIGHBIT)
     215             :   { /* round to nearest */
     216   495601706 :     i = lz; do ((ulong*)z)[--i]++; while (i>1 && z[i]==0);
     217   495601706 :     if (i == 1) { z[2] = (long)HIGHBIT; ez++; }
     218             :   }
     219  1014378646 :   z[1] = evalsigne(sz)|evalexpo(ez);
     220  1014378646 : }
     221             : /* mulrrz_end for lz = 3, minor simplifications. z[2]=hiremainder from mulll */
     222             : INLINE void
     223   728238343 : mulrrz_3end(GEN z, long sz, long ez, ulong garde)
     224             : {
     225   728238343 :   if (z[2] < 0)
     226             :   { /* z2 < (2^BIL-1)^2 / 2^BIL, hence z2+1 != 0 */
     227   393488410 :     if (garde & HIGHBIT) z[2]++; /* round properly */
     228   393488410 :     ez++;
     229             :   }
     230             :   else
     231             :   {
     232   334749933 :     uel(z,2) = (uel(z,2)<<1) | (garde>>(BITS_IN_LONG-1));
     233   334749933 :     if (garde & (1UL<<(BITS_IN_LONG-2)))
     234             :     {
     235   154260582 :       uel(z,2)++; /* round properly, z2+1 can overflow */
     236   154260582 :       if (!uel(z,2)) { uel(z,2) = HIGHBIT; ez++; }
     237             :     }
     238             :   }
     239   728238343 :   z[1] = evalsigne(sz)|evalexpo(ez);
     240   728238343 : }
     241             : 
     242             : /* set z <-- x^2 != 0, floating point multiplication.
     243             :  * lz = lg(z) = lg(x) */
     244             : INLINE void
     245    76572441 : sqrz_i(GEN z, GEN x, long lz)
     246             : {
     247    76572441 :   long ez = 2*expo(x);
     248             :   long i, j, lzz, p1;
     249             :   ulong garde;
     250             :   GEN x1;
     251             :   LOCAL_HIREMAINDER;
     252             :   LOCAL_OVERFLOW;
     253             : 
     254    76572441 :   if (lz > MULRR_MULII_LIMIT)
     255             :   {
     256     4785584 :     pari_sp av = avma;
     257     4785584 :     GEN hi = sqrispec_mirror(x+2, lz-2);
     258     4785584 :     mulrrz_end(z, hi, lz, 1, ez, hi[lz]);
     259     4785584 :     avma = av; return;
     260             :   }
     261    71786857 :   if (lz == 3)
     262             :   {
     263    12412718 :     garde = mulll(x[2],x[2]);
     264    12412718 :     z[2] = hiremainder;
     265    12412718 :     mulrrz_3end(z, 1, ez, garde);
     266    12412718 :     return;
     267             :   }
     268             : 
     269    59374139 :   lzz = lz-1; p1 = x[lzz];
     270    59374139 :   if (p1)
     271             :   {
     272    52532282 :     (void)mulll(p1,x[3]);
     273    52532282 :     garde = addmul(p1,x[2]);
     274    52532282 :     z[lzz] = hiremainder;
     275             :   }
     276             :   else
     277             :   {
     278     6841857 :     garde = 0;
     279     6841857 :     z[lzz] = 0;
     280             :   }
     281   198339518 :   for (j=lz-2, x1=x-j; j>=3; j--)
     282             :   {
     283   138965379 :     p1 = x[j]; x1++;
     284   138965379 :     if (p1)
     285             :     {
     286   133815430 :       (void)mulll(p1,x1[lz+1]);
     287   133815430 :       garde = addll(addmul(p1,x1[lz]), garde);
     288   603341897 :       for (i=lzz; i>j; i--)
     289             :       {
     290   469526467 :         hiremainder += overflow;
     291   469526467 :         z[i] = addll(addmul(p1,x1[i]), z[i]);
     292             :       }
     293   133815430 :       z[j] = hiremainder+overflow;
     294             :     }
     295     5149949 :     else z[j]=0;
     296             :   }
     297    59374139 :   p1 = x[2]; x1++;
     298    59374139 :   garde = addll(mulll(p1,x1[lz]), garde);
     299   257713657 :   for (i=lzz; i>2; i--)
     300             :   {
     301   198339518 :     hiremainder += overflow;
     302   198339518 :     z[i] = addll(addmul(p1,x1[i]), z[i]);
     303             :   }
     304    59374139 :   z[2] = hiremainder+overflow;
     305    59374139 :   mulrrz_end(z, z, lz, 1, ez, garde);
     306             : }
     307             : 
     308             : /* lz "large" = lg(y) = lg(z), lg(x) > lz if flag = 1 and >= if flag = 0 */
     309             : INLINE void
     310    59779556 : mulrrz_int(GEN z, GEN x, GEN y, long lz, long flag, long sz)
     311             : {
     312    59779556 :   pari_sp av = avma;
     313    59779556 :   GEN hi = muliispec_mirror(y+2, x+2, lz+flag-2, lz-2);
     314    59779556 :   mulrrz_end(z, hi, lz, sz, expo(x)+expo(y), hi[lz]);
     315    59779556 :   avma = av;
     316    59779556 : }
     317             : 
     318             : /* lz = 3 */
     319             : INLINE void
     320   715825625 : mulrrz_3(GEN z, GEN x, GEN y, long flag, long sz)
     321             : {
     322             :   ulong garde;
     323             :   LOCAL_HIREMAINDER;
     324   715825625 :   if (flag)
     325             :   {
     326    14257882 :     (void)mulll(x[2],y[3]);
     327    14257882 :     garde = addmul(x[2],y[2]);
     328             :   }
     329             :   else
     330   701567743 :     garde = mulll(x[2],y[2]);
     331   715825625 :   z[2] = hiremainder;
     332   715825625 :   mulrrz_3end(z, sz, expo(x)+expo(y), garde);
     333   715825625 : }
     334             : 
     335             : /* set z <-- x*y, floating point multiplication. Trailing 0s for x are
     336             :  * treated efficiently (important application: mulir).
     337             :  * lz = lg(z) = lg(x) <= ly <= lg(y), sz = signe(z). flag = lg(x) < lg(y) */
     338             : INLINE void
     339  1664803753 : mulrrz_i(GEN z, GEN x, GEN y, long lz, long flag, long sz)
     340             : {
     341             :   long ez, i, j, lzz, p1;
     342             :   ulong garde;
     343             :   GEN y1;
     344             :   LOCAL_HIREMAINDER;
     345             :   LOCAL_OVERFLOW;
     346             : 
     347  1664803753 :   if (x == y) { sqrz_i(z,x,lz); return; }
     348  1664803753 :   if (lz > MULRR_MULII_LIMIT) { mulrrz_int(z,x,y,lz,flag,sz); return; }
     349  1605024197 :   if (lz == 3) { mulrrz_3(z,x,y,flag,sz); return; }
     350   889198572 :   ez = expo(x) + expo(y);
     351   889198572 :   if (flag) { (void)mulll(x[2],y[lz]); garde = hiremainder; } else garde = 0;
     352   889198572 :   lzz=lz-1; p1=x[lzz];
     353   889198572 :   if (p1)
     354             :   {
     355   856964214 :     (void)mulll(p1,y[3]);
     356   856964214 :     garde = addll(addmul(p1,y[2]), garde);
     357   856964214 :     z[lzz] = overflow+hiremainder;
     358             :   }
     359    32234358 :   else z[lzz]=0;
     360  2803162500 :   for (j=lz-2, y1=y-j; j>=3; j--)
     361             :   {
     362  1913963928 :     p1 = x[j]; y1++;
     363  1913963928 :     if (p1)
     364             :     {
     365  1852618673 :       (void)mulll(p1,y1[lz+1]);
     366  1852618673 :       garde = addll(addmul(p1,y1[lz]), garde);
     367  7681928989 :       for (i=lzz; i>j; i--)
     368             :       {
     369  5829310316 :         hiremainder += overflow;
     370  5829310316 :         z[i] = addll(addmul(p1,y1[i]), z[i]);
     371             :       }
     372  1852618673 :       z[j] = hiremainder+overflow;
     373             :     }
     374    61345255 :     else z[j]=0;
     375             :   }
     376   889198572 :   p1 = x[2]; y1++;
     377   889198572 :   garde = addll(mulll(p1,y1[lz]), garde);
     378  3692361072 :   for (i=lzz; i>2; i--)
     379             :   {
     380  2803162500 :     hiremainder += overflow;
     381  2803162500 :     z[i] = addll(addmul(p1,y1[i]), z[i]);
     382             :   }
     383   889198572 :   z[2] = hiremainder+overflow;
     384   889198572 :   mulrrz_end(z, z, lz, sz, ez, garde);
     385             : }
     386             : 
     387             : GEN
     388  1680700016 : mulrr(GEN x, GEN y)
     389             : {
     390             :   long flag, ly, lz, sx, sy;
     391             :   GEN z;
     392             : 
     393  1680700016 :   if (x == y) return sqrr(x);
     394  1680562931 :   sx = signe(x); if (!sx) return real_0_bit(expo(x) + expo(y));
     395  1656134616 :   sy = signe(y); if (!sy) return real_0_bit(expo(x) + expo(y));
     396  1646843817 :   if (sy < 0) sx = -sx;
     397  1646843817 :   lz = lg(x);
     398  1646843817 :   ly = lg(y);
     399  1646843817 :   if (lz > ly) { lz = ly; swap(x, y); flag = 1; } else flag = (lz != ly);
     400  1646843817 :   z = cgetr(lz);
     401  1646843817 :   mulrrz_i(z, x,y, lz,flag, sx);
     402  1646843817 :   return z;
     403             : }
     404             : 
     405             : GEN
     406    77380826 : sqrr(GEN x)
     407             : {
     408    77380826 :   long lz, sx = signe(x);
     409             :   GEN z;
     410             : 
     411    77380826 :   if (!sx) return real_0_bit(2*expo(x));
     412    76572441 :   lz = lg(x); z = cgetr(lz);
     413    76572441 :   sqrz_i(z, x, lz);
     414    76572441 :   return z;
     415             : }
     416             : 
     417             : GEN
     418   156438265 : mulir(GEN x, GEN y)
     419             : {
     420   156438265 :   long sx = signe(x), sy;
     421   156438265 :   if (!sx) return mul0r(y);
     422   156287360 :   if (lgefint(x) == 3) {
     423   136021109 :     GEN z = mulur(uel(x,2), y);
     424   136021109 :     if (sx < 0) togglesign(z);
     425   136021109 :     return z;
     426             :   }
     427    20266251 :   sy = signe(y);
     428    20266251 :   if (!sy) return real_0_bit(expi(x) + expo(y));
     429    19200731 :   if (sy < 0) sx = -sx;
     430             :   {
     431    19200731 :     long lz = lg(y), lx = lgefint(x);
     432    19200731 :     GEN hi, z = cgetr(lz);
     433    19200731 :     pari_sp av = avma;
     434    19200731 :     if (lx < (lz>>1) || (lx < lz && lz > MULRR_MULII_LIMIT))
     435             :     { /* size mantissa of x < half size of mantissa z, or lx < lz so large
     436             :        * that mulrr will call mulii anyway: mulii */
     437     1240795 :       x = itor(x, lx);
     438     1240795 :       hi = muliispec_mirror(y+2, x+2, lz-2, lx-2);
     439     1240795 :       mulrrz_end(z, hi, lz, sx, expo(x)+expo(y), hi[lz]);
     440             :     }
     441             :     else /* dubious: complete x with 0s and call mulrr */
     442    17959936 :       mulrrz_i(z, itor(x,lz), y, lz, 0, sx);
     443    19200731 :     avma = av; return z;
     444             :   }
     445             : }
     446             : 
     447             : /* x + y*z, generic. If lgefint(z) <= 3, caller should use faster variants  */
     448             : static GEN
     449    22104670 : addmulii_gen(GEN x, GEN y, GEN z, long lz)
     450             : {
     451    22104670 :   long lx = lgefint(x), ly;
     452             :   pari_sp av;
     453             :   GEN t;
     454    22104670 :   if (lx == 2) return mulii(z,y);
     455    21506367 :   ly = lgefint(y);
     456    21506367 :   if (ly == 2) return icopy(x); /* y = 0, wasteful copy */
     457    21499705 :   av = avma; (void)new_chunk(lx+ly+lz); /*HACK*/
     458    21499705 :   t = mulii(z, y);
     459    21499705 :   avma = av; return addii(t,x);
     460             : }
     461             : /* x + y*z, lgefint(z) == 3 */
     462             : static GEN
     463   199082246 : addmulii_lg3(GEN x, GEN y, GEN z)
     464             : {
     465   199082246 :   long s = signe(z), lx, ly;
     466   199082246 :   ulong w = z[2];
     467             :   pari_sp av;
     468             :   GEN t;
     469   199082246 :   if (w == 1) return (s > 0)? addii(x,y): subii(x,y); /* z = +- 1 */
     470   154738081 :   lx = lgefint(x);
     471   154738081 :   ly = lgefint(y);
     472   154738081 :   if (lx == 2)
     473             :   { /* x = 0 */
     474    21663077 :     if (ly == 2) return gen_0;
     475    17853956 :     t = muluispec(w, y+2, ly-2);
     476    17853956 :     if (signe(y) < 0) s = -s;
     477    17853956 :     setsigne(t, s); return t;
     478             :   }
     479   133075004 :   if (ly == 2) return icopy(x); /* y = 0, wasteful copy */
     480   128494688 :   av = avma; (void)new_chunk(1+lx+ly);/*HACK*/
     481   128494688 :   t = muluispec(w, y+2, ly-2);
     482   128494688 :   if (signe(y) < 0) s = -s;
     483   128494688 :   setsigne(t, s);
     484   128494688 :   avma = av; return addii(x,t);
     485             : }
     486             : /* x + y*z */
     487             : GEN
     488    27111567 : addmulii(GEN x, GEN y, GEN z)
     489             : {
     490    27111567 :   long lz = lgefint(z);
     491    27111567 :   switch(lz)
     492             :   {
     493      259487 :     case 2: return icopy(x); /* z = 0, wasteful copy */
     494    24851954 :     case 3: return addmulii_lg3(x, y, z);
     495     2000126 :     default:return addmulii_gen(x, y, z, lz);
     496             :   }
     497             : }
     498             : /* x + y*z, returns x itself and not a copy when y*z = 0 */
     499             : GEN
     500   716494419 : addmulii_inplace(GEN x, GEN y, GEN z)
     501             : {
     502             :   long lz;
     503   716494419 :   if (lgefint(y) == 2) return x;
     504   194334836 :   lz = lgefint(z);
     505   194334836 :   switch(lz)
     506             :   {
     507           0 :     case 2: return x;
     508   174230292 :     case 3: return addmulii_lg3(x, y, z);
     509    20104544 :     default:return addmulii_gen(x, y, z, lz);
     510             :   }
     511             : }
     512             : 
     513             : /* written by Bruno Haible following an idea of Robert Harley */
     514             : long
     515  2628269986 : vals(ulong z)
     516             : {
     517             :   static char tab[64]={-1,0,1,12,2,6,-1,13,3,-1,7,-1,-1,-1,-1,14,10,4,-1,-1,8,-1,-1,25,-1,-1,-1,-1,-1,21,27,15,31,11,5,-1,-1,-1,-1,-1,9,-1,-1,24,-1,-1,20,26,30,-1,-1,-1,-1,23,-1,19,29,-1,22,18,28,17,16,-1};
     518             : #ifdef LONG_IS_64BIT
     519             :   long s;
     520             : #endif
     521             : 
     522  2628269986 :   if (!z) return -1;
     523             : #ifdef LONG_IS_64BIT
     524  2340679113 :   if (! (z&0xffffffff)) { s = 32; z >>=32; } else s = 0;
     525             : #endif
     526  2628269986 :   z |= ~z + 1;
     527  2628269986 :   z += z << 4;
     528  2628269986 :   z += z << 6;
     529  2628269986 :   z ^= z << 16; /* or  z -= z<<16 */
     530             : #ifdef LONG_IS_64BIT
     531  2340679113 :   return s + tab[(z&0xffffffff)>>26];
     532             : #else
     533   287590873 :   return tab[z>>26];
     534             : #endif
     535             : }
     536             : 
     537             : GEN
     538          21 : divsi(long x, GEN y)
     539             : {
     540          21 :   long p1, s = signe(y);
     541             :   LOCAL_HIREMAINDER;
     542             : 
     543          21 :   if (!s) pari_err_INV("divsi",gen_0);
     544          21 :   if (!x || lgefint(y)>3 || ((long)y[2])<0) return gen_0;
     545          21 :   hiremainder=0; p1=divll(labs(x),y[2]);
     546          21 :   if (x<0) { hiremainder = -((long)hiremainder); p1 = -p1; }
     547          21 :   if (s<0) p1 = -p1;
     548          21 :   return stoi(p1);
     549             : }
     550             : 
     551             : GEN
     552     2496317 : divir(GEN x, GEN y)
     553             : {
     554             :   GEN z;
     555     2496317 :   long ly = lg(y), lx = lgefint(x);
     556             :   pari_sp av;
     557             : 
     558     2496317 :   if (ly == 2) pari_err_INV("divir",y);
     559     2496317 :   if (lx == 2) return div0r(y);
     560     2432709 :   if (lx == 3) {
     561     1266285 :     z = divur(x[2], y);
     562     1266285 :     if (signe(x) < 0) togglesign(z);
     563     1266285 :     return z;
     564             :   }
     565     1166424 :   z = cgetr(ly); av = avma;
     566     1166424 :   affrr(divrr(itor(x, ly+1), y), z);
     567     1166424 :   avma = av; return z;
     568             : }
     569             : 
     570             : GEN
     571     1296446 : divur(ulong x, GEN y)
     572             : {
     573             :   pari_sp av;
     574     1296446 :   long ly = lg(y);
     575             :   GEN z;
     576             : 
     577     1296446 :   if (ly == 2) pari_err_INV("divur",y);
     578     1296446 :   if (!x) return div0r(y);
     579     1296446 :   if (ly > INVNEWTON_LIMIT) {
     580         571 :     av = avma; z = invr(y);
     581         571 :     if (x == 1) return z;
     582         571 :     return gerepileuptoleaf(av, mulur(x, z));
     583             :   }
     584     1295875 :   z = cgetr(ly); av = avma;
     585     1295875 :   affrr(divrr(utor(x,ly+1), y), z);
     586     1295875 :   avma = av; return z;
     587             : }
     588             : 
     589             : GEN
     590        7324 : divsr(long x, GEN y)
     591             : {
     592             :   pari_sp av;
     593        7324 :   long ly = lg(y);
     594             :   GEN z;
     595             : 
     596        7324 :   if (ly == 2) pari_err_INV("divsr",y);
     597        7324 :   if (!x) return div0r(y);
     598        7324 :   if (ly > INVNEWTON_LIMIT) {
     599           0 :     av = avma; z = invr(y);
     600           0 :     if (x == 1) return z;
     601           0 :     if (x ==-1) { togglesign(z); return z; }
     602           0 :     return gerepileuptoleaf(av, mulsr(x, z));
     603             :   }
     604        7324 :   z = cgetr(ly); av = avma;
     605        7324 :   affrr(divrr(stor(x,ly+1), y), z);
     606        7324 :   avma = av; return z;
     607             : }
     608             : 
     609             : /* returns 1/y, assume y != 0 */
     610             : static GEN
     611    11302358 : invr_basecase(GEN y)
     612             : {
     613    11302358 :   long ly = lg(y);
     614    11302358 :   GEN z = cgetr(ly);
     615    11302358 :   pari_sp av = avma;
     616    11302358 :   affrr(divrr(real_1(ly+1), y), z);
     617    11302358 :   avma = av; return z;
     618             : }
     619             : /* returns 1/b, Newton iteration */
     620             : GEN
     621    11302358 : invr(GEN b)
     622             : {
     623    11302358 :   const long s = 6;
     624    11302358 :   long i, p, l = lg(b);
     625             :   GEN x, a;
     626             :   ulong mask;
     627             : 
     628    11302358 :   if (l <= maxss(INVNEWTON_LIMIT, (1L<<s) + 2)) {
     629    11299136 :     if (l == 2) pari_err_INV("invr",b);
     630    11299136 :     return invr_basecase(b);
     631             :   }
     632        3222 :   mask = quadratic_prec_mask(l-2);
     633        3222 :   for(i=0, p=1; i<s; i++) { p <<= 1; if (mask & 1) p--; mask >>= 1; }
     634        3222 :   x = cgetr(l);
     635        3222 :   a = rcopy(b); a[1] = _evalexpo(0) | evalsigne(1);
     636        3222 :   affrr(invr_basecase(rtor(a, p+2)), x);
     637       11419 :   while (mask > 1)
     638             :   {
     639        4975 :     p <<= 1; if (mask & 1) p--;
     640        4975 :     mask >>= 1;
     641        4975 :     setlg(a, p + 2);
     642        4975 :     setlg(x, p + 2);
     643             :     /* TODO: mulrr(a,x) should be a half product (the higher half is known).
     644             :      * mulrr(x, ) already is */
     645        4975 :     affrr(addrr(x, mulrr(x, subsr(1, mulrr(a,x)))), x);
     646        4975 :     avma = (pari_sp)a;
     647             :   }
     648        3222 :   x[1] = (b[1] & SIGNBITS) | evalexpo(expo(x)-expo(b));
     649        3222 :   avma = (pari_sp)x; return x;
     650             : }
     651             : 
     652             : GEN
     653  1283369400 : modii(GEN x, GEN y)
     654             : {
     655  1283369400 :   switch(signe(x))
     656             :   {
     657   164936271 :     case 0: return gen_0;
     658   758610117 :     case 1: return remii(x,y);
     659             :     default:
     660             :     {
     661   359823012 :       pari_sp av = avma;
     662   359823012 :       (void)new_chunk(lgefint(y));
     663   359820108 :       x = remii(x,y); avma=av;
     664   359825010 :       if (x==gen_0) return x;
     665   340515008 :       return subiispec(y+2,x+2,lgefint(y)-2,lgefint(x)-2);
     666             :     }
     667             :   }
     668             : }
     669             : 
     670             : void
     671      229653 : modiiz(GEN x, GEN y, GEN z)
     672             : {
     673      229653 :   const pari_sp av = avma;
     674      229653 :   affii(modii(x,y),z); avma=av;
     675      229653 : }
     676             : 
     677             : GEN
     678     3491659 : divrs(GEN x, long y)
     679             : {
     680             :   GEN z;
     681     3491659 :   if (y < 0)
     682             :   {
     683      469789 :     z = divru(x, (ulong)-y);
     684      469789 :     togglesign(z);
     685             :   }
     686             :   else
     687     3021870 :     z = divru(x, (ulong)y);
     688     3491659 :   return z;
     689             : }
     690             : 
     691             : GEN
     692   499225575 : divru(GEN x, ulong y)
     693             : {
     694   499225575 :   long i, lx, sh, e, s = signe(x);
     695             :   ulong garde;
     696             :   GEN z;
     697             :   LOCAL_HIREMAINDER;
     698             : 
     699   499225575 :   if (!y) pari_err_INV("divru",gen_0);
     700   499225575 :   if (!s) return real_0_bit(expo(x) - expu(y));
     701   499161963 :   if (!(y & (y-1))) /* power of 2 */
     702             :   {
     703    34966927 :     if (y == 1) return rcopy(x);
     704    33131688 :     return shiftr(x, -expu(y));
     705             :   }
     706   464195036 :   e = expo(x);
     707   464195036 :   lx = lg(x);
     708   464195036 :   z = cgetr(lx);
     709   464195036 :   if (lx == 3)
     710             :   {
     711   281474085 :     if (y <= uel(x,2))
     712             :     {
     713   281474025 :       hiremainder = 0;
     714   281474025 :       z[2] = divll(x[2],y);
     715             :       /* we may have hiremainder != 0 ==> garde */
     716   281474025 :       garde = divll(0,y);
     717             :     }
     718             :     else
     719             :     {
     720          60 :       hiremainder = x[2];
     721          60 :       z[2] = divll(0,y);
     722          60 :       garde = hiremainder;
     723          60 :       e -= BITS_IN_LONG;
     724             :     }
     725             :   }
     726             :   else
     727             :   {
     728   182720951 :     ulong yp = get_Fl_red(y);
     729   182720951 :     if (y <= uel(x,2))
     730             :     {
     731   182718142 :       hiremainder = 0;
     732   182718142 :       for (i=2; i<lx; i++) z[i] = divll_pre(x[i],y,yp);
     733             :       /* we may have hiremainder != 0 ==> garde */
     734   182718142 :       garde = divll_pre(0,y,yp);
     735             :     }
     736             :     else
     737             :     {
     738        2809 :       long l = lx-1;
     739        2809 :       hiremainder = x[2];
     740        2809 :       for (i=2; i<l; i++) z[i] = divll_pre(x[i+1],y,yp);
     741        2809 :       z[i] = divll_pre(0,y,yp);
     742        2809 :       garde = hiremainder;
     743        2809 :       e -= BITS_IN_LONG;
     744             :     }
     745             :   }
     746   464195036 :   sh=bfffo(z[2]); /* z[2] != 0 */
     747   464195036 :   if (sh) shift_left(z,z, 2,lx-1, garde,sh);
     748   464195036 :   z[1] = evalsigne(s) | evalexpo(e-sh);
     749   464195036 :   if ((garde << sh) & HIGHBIT) roundr_up_ip(z, lx);
     750   464195036 :   return z;
     751             : }
     752             : 
     753             : GEN
     754    38712593 : truedvmdii(GEN x, GEN y, GEN *z)
     755             : {
     756             :   pari_sp av;
     757             :   GEN r, q, *gptr[2];
     758    38712593 :   if (!is_bigint(y)) return truedvmdis(x, itos(y), z);
     759      706194 :   if (z == ONLY_REM) return modii(x,y);
     760             : 
     761      706194 :   av = avma;
     762      706194 :   q = dvmdii(x,y,&r); /* assume that r is last on stack */
     763      706194 :   switch(signe(r))
     764             :   {
     765             :     case 0:
     766       74686 :       if (z) *z = gen_0;
     767       74686 :       return q;
     768             :     case 1:
     769      506487 :       if (z) *z = r; else cgiv(r);
     770      506487 :       return q;
     771      125021 :     case -1: break;
     772             :   }
     773      125021 :   q = addis(q, -signe(y));
     774      125021 :   if (!z) return gerepileuptoint(av, q);
     775             : 
     776       19556 :   *z = subiispec(y+2,r+2, lgefint(y)-2,lgefint(r)-2);
     777       19556 :   gptr[0]=&q; gptr[1]=z; gerepilemanysp(av,(pari_sp)r,gptr,2);
     778       19556 :   return q;
     779             : }
     780             : GEN
     781    38023790 : truedvmdis(GEN x, long y, GEN *z)
     782             : {
     783    38023790 :   pari_sp av = avma;
     784             :   long r;
     785             :   GEN q;
     786             : 
     787    38023790 :   if (z == ONLY_REM) return modis(x, y);
     788    38023790 :   q = divis_rem(x,y,&r);
     789             : 
     790    38023790 :   if (r >= 0)
     791             :   {
     792    33994697 :     if (z) *z = utoi(r);
     793    33994697 :     return q;
     794             :   }
     795     4029093 :   q = gerepileuptoint(av, addis(q, (y < 0)? 1: -1));
     796     4029093 :   if (z) *z = utoi(r + labs(y));
     797     4029093 :   return q;
     798             : }
     799             : GEN
     800     6084588 : truedvmdsi(long x, GEN y, GEN *z)
     801             : {
     802             :   long q, r;
     803     6084588 :   if (z == ONLY_REM) return modsi(x, y);
     804     6084588 :   q = sdivsi_rem(x,y,&r);
     805     6084588 :   if (r >= 0) {
     806     6084560 :     if (z) *z = utoi(r);
     807     6084560 :     return stoi(q);
     808             :   }
     809          28 :   q = q - signe(y);
     810          28 :   if (!z) return stoi(q);
     811             : 
     812           0 :   *z = subiuspec(y+2,(ulong)-r, lgefint(y)-2);
     813           0 :   return stoi(q);
     814             : }
     815             : 
     816             : /* 2^n = shifti(gen_1, n) */
     817             : GEN
     818    70100413 : int2n(long n) {
     819             :   long i, m, l;
     820             :   GEN z;
     821    70100413 :   if (n < 0) return gen_0;
     822    70099631 :   if (n == 0) return gen_1;
     823             : 
     824    69961324 :   l = dvmdsBIL(n, &m) + 3;
     825    69961029 :   z = cgetipos(l);
     826    69960255 :   for (i = 2; i < l; i++) z[i] = 0;
     827    69960255 :   *int_MSW(z) = 1UL << m; return z;
     828             : }
     829             : /* To avoid problems when 2^(BIL-1) < n. Overflow cleanly, where int2n
     830             :  * returns gen_0 */
     831             : GEN
     832     9637355 : int2u(ulong n) {
     833             :   ulong i, m, l;
     834             :   GEN z;
     835     9637355 :   if (n == 0) return gen_1;
     836             : 
     837     9637355 :   l = dvmduBIL(n, &m) + 3;
     838     9637352 :   z = cgetipos(l);
     839     9637339 :   for (i = 2; i < l; i++) z[i] = 0;
     840     9637339 :   *int_MSW(z) = 1UL << m; return z;
     841             : }
     842             : /* 2^n - 1 */
     843             : GEN
     844         476 : int2um1(ulong n) {
     845             :   ulong i, m, l;
     846             :   GEN z;
     847         476 :   if (n == 0) return gen_0;
     848             : 
     849         476 :   l = dvmduBIL(n, &m);
     850         476 :   l += m? 3: 2;
     851         476 :   z = cgetipos(l);
     852         476 :   for (i = 2; i < l; i++) z[i] = ~0UL;
     853         476 :   if (m) *int_MSW(z) = (1UL << m) - 1;
     854         476 :   return z;
     855             : }
     856             : 
     857             : GEN
     858   760692551 : shifti(GEN x, long n)
     859             : {
     860   760692551 :   long s = signe(x);
     861             :   GEN y;
     862             : 
     863   760692551 :   if(s == 0) return gen_0;
     864   688593818 :   y = shiftispec(x + 2, lgefint(x) - 2, n);
     865   688540584 :   if (signe(y)) setsigne(y, s);
     866   688540584 :   return y;
     867             : }
     868             : 
     869             : /* actual operations will take place on a+2 and b+2: we strip the codewords */
     870             : GEN
     871  8146104892 : mulii(GEN a,GEN b)
     872             : {
     873             :   long sa,sb;
     874             :   GEN z;
     875             : 
     876  8146104892 :   sa=signe(a); if (!sa) return gen_0;
     877  5770813487 :   sb=signe(b); if (!sb) return gen_0;
     878  3897825929 :   if (sb<0) sa = -sa;
     879  3897825929 :   z = muliispec(a+2,b+2, lgefint(a)-2,lgefint(b)-2);
     880  3898468972 :   setsigne(z,sa); return z;
     881             : }
     882             : 
     883             : GEN
     884  1246503319 : sqri(GEN a) { return sqrispec(a+2, lgefint(a)-2); }
     885             : 
     886             : /* sqrt()'s result may be off by 1 when a is not representable exactly as a
     887             :  * double [64bit machine] */
     888             : ulong
     889    13670691 : usqrt(ulong a)
     890             : {
     891    13670691 :   ulong x = (ulong)sqrt((double)a);
     892             : #ifdef LONG_IS_64BIT
     893    11687242 :   if (x > LOWMASK || x*x > a) x--;
     894             : #endif
     895    13670691 :   return x;
     896             : }
     897             : 
     898             : /********************************************************************/
     899             : /**                                                                **/
     900             : /**              EXPONENT / CONVERSION t_REAL --> double           **/
     901             : /**                                                                **/
     902             : /********************************************************************/
     903             : 
     904             : #ifdef LONG_IS_64BIT
     905             : long
     906           0 : dblexpo(double x)
     907             : {
     908             :   union { double f; ulong i; } fi;
     909           0 :   const int mant_len = 52;  /* mantissa bits (excl. hidden bit) */
     910           0 :   const int exp_mid = 0x3ff;/* exponent bias */
     911             : 
     912           0 :   if (x==0.) return -exp_mid;
     913           0 :   fi.f = x;
     914           0 :   return ((fi.i & (HIGHBIT-1)) >> mant_len) - exp_mid;
     915             : }
     916             : 
     917             : ulong
     918           0 : dblmantissa(double x)
     919             : {
     920             :   union { double f; ulong i; } fi;
     921           0 :   const int expo_len = 11; /* number of bits of exponent */
     922             : 
     923           0 :   if (x==0.) return 0;
     924           0 :   fi.f = x;
     925           0 :   return (fi.i << expo_len) | HIGHBIT;
     926             : }
     927             : 
     928             : GEN
     929     5404040 : dbltor(double x)
     930             : {
     931             :   GEN z;
     932             :   long e;
     933             :   union { double f; ulong i; } fi;
     934     5404040 :   const int mant_len = 52;  /* mantissa bits (excl. hidden bit) */
     935     5404040 :   const int exp_mid = 0x3ff;/* exponent bias */
     936     5404040 :   const int expo_len = 11; /* number of bits of exponent */
     937             : 
     938     5404040 :   if (x==0.) return real_0_bit(-exp_mid);
     939     5392406 :   fi.f = x; z = cgetr(DEFAULTPREC);
     940             :   {
     941     5392406 :     const ulong a = fi.i;
     942             :     ulong A;
     943     5392406 :     e = ((a & (HIGHBIT-1)) >> mant_len) - exp_mid;
     944     5392406 :     if (e == exp_mid+1) pari_err_OVERFLOW("dbltor [NaN or Infinity]");
     945     5392406 :     A = a << expo_len;
     946     5392406 :     if (e == -exp_mid)
     947             :     { /* unnormalized values */
     948           0 :       int sh = bfffo(A);
     949           0 :       e -= sh-1;
     950           0 :       z[2] = A << sh;
     951             :     }
     952             :     else
     953     5392406 :       z[2] = HIGHBIT | A;
     954     5392406 :     z[1] = _evalexpo(e) | evalsigne(x<0? -1: 1);
     955             :   }
     956     5392406 :   return z;
     957             : }
     958             : 
     959             : double
     960    25293436 : rtodbl(GEN x)
     961             : {
     962    25293436 :   long ex,s=signe(x);
     963             :   ulong a;
     964             :   union { double f; ulong i; } fi;
     965    25293436 :   const int mant_len = 52;  /* mantissa bits (excl. hidden bit) */
     966    25293436 :   const int exp_mid = 0x3ff;/* exponent bias */
     967    25293436 :   const int expo_len = 11; /* number of bits of exponent */
     968             : 
     969    25293436 :   if (!s || (ex=expo(x)) < - exp_mid) return 0.0;
     970             : 
     971             :   /* start by rounding to closest */
     972    24814001 :   a = (x[2] & (HIGHBIT-1)) + 0x400;
     973    24814001 :   if (a & HIGHBIT) { ex++; a=0; }
     974    24814001 :   if (ex >= exp_mid) pari_err_OVERFLOW("t_REAL->double conversion");
     975    24814001 :   fi.i = ((ex + exp_mid) << mant_len) | (a >> expo_len);
     976    24814001 :   if (s<0) fi.i |= HIGHBIT;
     977    24814001 :   return fi.f;
     978             : }
     979             : 
     980             : #else /* LONG_IS_64BIT */
     981             : 
     982             : #if   PARI_DOUBLE_FORMAT == 1
     983             : #  define INDEX0 1
     984             : #  define INDEX1 0
     985             : #elif PARI_DOUBLE_FORMAT == 0
     986             : #  define INDEX0 0
     987             : #  define INDEX1 1
     988             : #endif
     989             : 
     990             : long
     991           0 : dblexpo(double x)
     992             : {
     993             :   union { double f; ulong i[2]; } fi;
     994           0 :   const int mant_len = 52;  /* mantissa bits (excl. hidden bit) */
     995           0 :   const int exp_mid = 0x3ff;/* exponent bias */
     996           0 :   const int shift = mant_len-32;
     997             : 
     998           0 :   if (x==0.) return -exp_mid;
     999           0 :   fi.f = x;
    1000             :   {
    1001           0 :     const ulong a = fi.i[INDEX0];
    1002           0 :     return ((a & (HIGHBIT-1)) >> shift) - exp_mid;
    1003             :   }
    1004             : }
    1005             : 
    1006             : ulong
    1007           0 : dblmantissa(double x)
    1008             : {
    1009             :   union { double f; ulong i[2]; } fi;
    1010           0 :   const int expo_len = 11; /* number of bits of exponent */
    1011             : 
    1012           0 :   if (x==0.) return 0;
    1013           0 :   fi.f = x;
    1014             :   {
    1015           0 :     const ulong a = fi.i[INDEX0];
    1016           0 :     const ulong b = fi.i[INDEX1];
    1017           0 :     return HIGHBIT | b >> (BITS_IN_LONG-expo_len) | (a << expo_len);
    1018             :   }
    1019             : }
    1020             : 
    1021             : GEN
    1022      901106 : dbltor(double x)
    1023             : {
    1024             :   GEN z;
    1025             :   long e;
    1026             :   union { double f; ulong i[2]; } fi;
    1027      901106 :   const int mant_len = 52;  /* mantissa bits (excl. hidden bit) */
    1028      901106 :   const int exp_mid = 0x3ff;/* exponent bias */
    1029      901106 :   const int expo_len = 11; /* number of bits of exponent */
    1030      901106 :   const int shift = mant_len-32;
    1031             : 
    1032      901106 :   if (x==0.) return real_0_bit(-exp_mid);
    1033      899787 :   fi.f = x; z = cgetr(DEFAULTPREC);
    1034             :   {
    1035      899787 :     const ulong a = fi.i[INDEX0];
    1036      899787 :     const ulong b = fi.i[INDEX1];
    1037             :     ulong A, B;
    1038      899787 :     e = ((a & (HIGHBIT-1)) >> shift) - exp_mid;
    1039      899787 :     if (e == exp_mid+1) pari_err_OVERFLOW("dbltor [NaN or Infinity]");
    1040      899787 :     A = b >> (BITS_IN_LONG-expo_len) | (a << expo_len);
    1041      899787 :     B = b << expo_len;
    1042      899787 :     if (e == -exp_mid)
    1043             :     { /* unnormalized values */
    1044             :       int sh;
    1045           0 :       if (A)
    1046             :       {
    1047           0 :         sh = bfffo(A);
    1048           0 :         e -= sh-1;
    1049           0 :         z[2] = (A << sh) | (B >> (32-sh));
    1050           0 :         z[3] = B << sh;
    1051             :       }
    1052             :       else
    1053             :       {
    1054           0 :         sh = bfffo(B); /* B != 0 */
    1055           0 :         e -= sh-1 + 32;
    1056           0 :         z[2] = B << sh;
    1057           0 :         z[3] = 0;
    1058             :       }
    1059             :     }
    1060             :     else
    1061             :     {
    1062      899787 :       z[3] = B;
    1063      899787 :       z[2] = HIGHBIT | A;
    1064             :     }
    1065      899787 :     z[1] = _evalexpo(e) | evalsigne(x<0? -1: 1);
    1066             :   }
    1067      899787 :   return z;
    1068             : }
    1069             : 
    1070             : double
    1071     4120900 : rtodbl(GEN x)
    1072             : {
    1073     4120900 :   long ex,s=signe(x),lx=lg(x);
    1074             :   ulong a,b,k;
    1075             :   union { double f; ulong i[2]; } fi;
    1076     4120900 :   const int mant_len = 52;  /* mantissa bits (excl. hidden bit) */
    1077     4120900 :   const int exp_mid = 0x3ff;/* exponent bias */
    1078     4120900 :   const int expo_len = 11; /* number of bits of exponent */
    1079     4120900 :   const int shift = mant_len-32;
    1080             : 
    1081     4120900 :   if (!s || (ex=expo(x)) < - exp_mid) return 0.0;
    1082             : 
    1083             :   /* start by rounding to closest */
    1084     4041044 :   a = x[2] & (HIGHBIT-1);
    1085     4041044 :   if (lx > 3)
    1086             :   {
    1087     3816852 :     b = x[3] + 0x400UL; if (b < 0x400UL) a++;
    1088     3816852 :     if (a & HIGHBIT) { ex++; a=0; }
    1089             :   }
    1090      224192 :   else b = 0;
    1091     4041044 :   if (ex >= exp_mid) pari_err_OVERFLOW("t_REAL->double conversion");
    1092     4041044 :   ex += exp_mid;
    1093     4041044 :   k = (a >> expo_len) | (ex << shift);
    1094     4041044 :   if (s<0) k |= HIGHBIT;
    1095     4041044 :   fi.i[INDEX0] = k;
    1096     4041044 :   fi.i[INDEX1] = (a << (BITS_IN_LONG-expo_len)) | (b >> expo_len);
    1097     4041044 :   return fi.f;
    1098             : }
    1099             : #endif /* LONG_IS_64BIT */
    1100             : 

Generated by: LCOV version 1.11