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 - add.c (source / functions) Hit Total Coverage
Test: PARI/GP v2.8.0 lcov report (development 19207-2ed2f69) Lines: 187 208 89.9 %
Date: 2016-07-25 07:10:32 Functions: 10 12 83.3 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : #line 2 "../src/kernel/none/add.c"
       2             : /* Copyright (C) 2002-2003  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             : INLINE GEN
      16  1419309225 : icopy_sign(GEN x, long sx)
      17             : {
      18  1419309225 :   GEN y=icopy(x);
      19  1420261600 :   setsigne(y,sx);
      20  1420261600 :   return y;
      21             : }
      22             : 
      23             : GEN
      24   101775633 : addsi_sign(long x, GEN y, long sy)
      25             : {
      26             :   long sx,ly;
      27             :   GEN z;
      28             : 
      29   101775633 :   if (!x) return icopy_sign(y, sy);
      30   100898311 :   if (!sy) return stoi(x);
      31    96665804 :   if (x<0) { sx=-1; x=-x; } else sx=1;
      32    96665804 :   if (sx==sy)
      33             :   {
      34    59450158 :     z = adduispec(x,y+2, lgefint(y)-2);
      35    59450158 :     setsigne(z,sy); return z;
      36             :   }
      37    37215646 :   ly=lgefint(y);
      38    37215646 :   if (ly==3)
      39             :   {
      40     4075897 :     const long d = (long)(uel(y,2) - (ulong)x);
      41     4075897 :     if (!d) return gen_0;
      42     3700113 :     z=cgeti(3);
      43     3700113 :     if (y[2] < 0 || d > 0) {
      44     3240474 :       z[1] = evalsigne(sy) | evallgefint(3);
      45     3240474 :       z[2] = d;
      46             :     }
      47             :     else {
      48      459639 :       z[1] = evalsigne(-sy) | evallgefint(3);
      49      459639 :       z[2] =-d;
      50             :     }
      51     3700113 :     return z;
      52             :   }
      53    33139749 :   z = subiuspec(y+2,x, ly-2);
      54    33138319 :   setsigne(z,sy); return z;
      55             : }
      56             : GEN
      57    29262734 : addui_sign(ulong x, GEN y, long sy)
      58             : {
      59             :   long ly;
      60             :   GEN z;
      61             : 
      62    29262734 :   if (!x) return icopy_sign(y, sy);
      63    25689198 :   if (!sy) return utoipos(x);
      64    22386774 :   if (sy == 1) return adduispec(x,y+2, lgefint(y)-2);
      65     4860218 :   ly=lgefint(y);
      66     4860218 :   if (ly==3)
      67             :   {
      68     2985070 :     const ulong t = y[2];
      69     2985070 :     if (x == t) return gen_0;
      70     2048197 :     z=cgeti(3);
      71     2048197 :     if (x < t) {
      72     2047504 :       z[1] = evalsigne(-1) | evallgefint(3);
      73     2047504 :       z[2] = t - x;
      74             :     }
      75             :     else {
      76         693 :       z[1] = evalsigne(1) | evallgefint(3);
      77         693 :       z[2] = x - t;
      78             :     }
      79     2048197 :     return z;
      80             :   }
      81     1875148 :   z = subiuspec(y+2,x, ly-2);
      82     1875148 :   setsigne(z,-1); return z;
      83             : }
      84             : 
      85             : /* return gen_0 when the sign is 0 */
      86             : GEN
      87  8163708069 : addii_sign(GEN x, long sx, GEN y, long sy)
      88             : {
      89             :   long lx,ly;
      90             :   GEN z;
      91             : 
      92  8163708069 :   if (!sx) return sy? icopy_sign(y, sy): gen_0;
      93  7090745700 :   if (!sy) return icopy_sign(x, sx);
      94  6018418225 :   lx = lgefint(x);
      95  6018418225 :   ly = lgefint(y);
      96  6018418225 :   if (sx==sy)
      97  3096817445 :     z = addiispec(x+2,y+2,lx-2,ly-2);
      98             :   else
      99             :   { /* sx != sy */
     100  2921600780 :     long i = cmpiispec(x+2,y+2,lx-2,ly-2);
     101  2922558231 :     if (!i) return gen_0;
     102             :     /* we must ensure |x| > |y| for subiispec */
     103  2809758015 :     if (i < 0) {
     104  1130890973 :       sx = sy;
     105  1130890973 :       z = subiispec(y+2,x+2,ly-2,lx-2);
     106             :     }
     107             :     else
     108  1678867042 :       z = subiispec(x+2,y+2,lx-2,ly-2);
     109             :   }
     110  5902475486 :   setsigne(z,sx); return z;
     111             : }
     112             : 
     113             : INLINE GEN
     114    80545519 : rcopy_sign(GEN x, long sx) { GEN y = rcopy(x); setsigne(y,sx); return y; }
     115             : 
     116             : GEN
     117   205016924 : addir_sign(GEN x, long sx, GEN y, long sy)
     118             : {
     119             :   long e, l, ly;
     120             :   GEN z;
     121             : 
     122   205016924 :   if (!sx) return rcopy_sign(y, sy);
     123   138642817 :   e = expo(y) - expi(x);
     124   138642817 :   if (!sy)
     125             :   {
     126     5598661 :     if (e >= 0) return rcopy_sign(y, sy);
     127     5598571 :     z = itor(x, nbits2prec(-e));
     128     5598571 :     setsigne(z, sx); return z;
     129             :   }
     130             : 
     131   133044156 :   ly = lg(y);
     132   133044156 :   if (e > 0)
     133             :   {
     134    15040279 :     l = ly - divsBIL(e);
     135    15040279 :     if (l < 3) return rcopy_sign(y, sy);
     136             :   }
     137   118003877 :   else l = ly + nbits2extraprec(-e);
     138   132870399 :   z = (GEN)avma;
     139   132870399 :   y = addrr_sign(itor(x,l), sx, y, sy);
     140   132870399 :   ly = lg(y); while (ly--) *--z = y[ly];
     141   132870399 :   avma = (pari_sp)z; return z;
     142             : }
     143             : 
     144             : static GEN
     145   136810264 : addsr_sign(long x, GEN y, long sy)
     146             : {
     147             :   long e, l, ly, sx;
     148             :   GEN z;
     149             : 
     150   136810264 :   if (!x) return rcopy_sign(y, sy);
     151   136810075 :   if (x < 0) { sx = -1; x = -x; } else sx = 1;
     152   136810075 :   e = expo(y) - expu(x);
     153   136810075 :   if (!sy)
     154             :   {
     155      371376 :     if (e >= 0) return rcopy_sign(y, sy);
     156      371376 :     if (sx == -1) x = -x;
     157      371376 :     return stor(x, nbits2prec(-e));
     158             :   }
     159             : 
     160   136438699 :   ly = lg(y);
     161   136438699 :   if (e > 0)
     162             :   {
     163      676627 :     l = ly - divsBIL(e);
     164      676627 :     if (l < 3) return rcopy_sign(y, sy);
     165             :   }
     166   135762072 :   else l = ly + nbits2extraprec(-e);
     167   136395505 :   z = (GEN)avma;
     168   136395505 :   y = addrr_sign(stor(x,l), sx, y, sy);
     169   136395505 :   ly = lg(y); while (ly--) *--z = y[ly];
     170   136395505 :   avma = (pari_sp)z; return z;
     171             : }
     172             : 
     173             : GEN
     174   134772643 : addsr(long x, GEN y) { return addsr_sign(x, y, signe(y)); }
     175             : 
     176             : GEN
     177     2037621 : subsr(long x, GEN y) { return addsr_sign(x, y, -signe(y)); }
     178             : 
     179             : /* return x + 1, assuming x > 0 is a normalized t_REAL of exponent 0 */
     180             : GEN
     181           0 : addrex01(GEN x)
     182             : {
     183           0 :   long l = lg(x);
     184           0 :   GEN y = cgetr(l);
     185           0 :   y[1] = evalsigne(1) | _evalexpo(1);
     186           0 :   y[2] = HIGHBIT | ((uel(x,2) & ~HIGHBIT) >> 1);
     187           0 :   shift_right(y, x, 3,l, x[2], 1);
     188           0 :   return y;
     189             : }
     190             : /* return subrs(x,1) to the min of (prec(x), prec(x-1) + 1),
     191             :  * assuming x > 1 is a normalized t_REAL of exponent 0
     192             :  * [ goal: avoid the loss of significant bits form subrs ]*/
     193             : GEN
     194           0 : subrex01(GEN x)
     195             : {
     196           0 :   long i, sh, k, ly, lx = lg(x);
     197             :   ulong u;
     198             :   GEN y;
     199           0 :   k = 2;
     200           0 :   u = uel(x,2) & (~HIGHBIT);
     201           0 :   while (!u) u = x[++k]; /* terminates: x not a power of 2 */
     202           0 :   ly = (k == 2)? lx: lx - k+3; /* NB: +3, not +2: 1 extra word */
     203           0 :   y = cgetr(ly);
     204           0 :   sh = bfffo(u);
     205           0 :   if (sh)
     206           0 :     shift_left(y+2, x+k, 0, lx-k-1, 0, sh);
     207             :   else
     208           0 :   { for (i = 2; i < lx-k+2; i++) y[i] = x[k-2 + i]; }
     209           0 :   for (i = lx-k+2; i < ly; i++) y[i] = 0;
     210           0 :   y[1] = evalsigne(1) | evalexpo(- (prec2nbits(k) + sh));
     211           0 :   return y;
     212             : }
     213             : 
     214             : GEN
     215  2619987807 : addrr_sign(GEN x, long sx, GEN y, long sy)
     216             : {
     217  2619987807 :   long lx, ex = expo(x);
     218  2619987807 :   long ly, ey = expo(y), e = ey - ex;
     219             :   long i, j, lz, ez, m;
     220             :   int extend, f2;
     221             :   GEN z;
     222             :   LOCAL_OVERFLOW;
     223             : 
     224  2619987807 :   if (!sy)
     225             :   {
     226    35815454 :     if (!sx)
     227             :     {
     228     9910982 :       if (e > 0) ex = ey;
     229     9910982 :       return real_0_bit(ex);
     230             :     }
     231    25904472 :     if (e >= 0) return real_0_bit(ey);
     232    25811949 :     lz = nbits2prec(-e);
     233    25811949 :     lx = lg(x); if (lz > lx) lz = lx;
     234    25811949 :     z = cgetr(lz); while(--lz) z[lz] = x[lz];
     235    25811949 :     setsigne(z,sx); return z;
     236             :   }
     237  2584172353 :   if (!sx)
     238             :   {
     239     6777124 :     if (e <= 0) return real_0_bit(ex);
     240     6574163 :     lz = nbits2prec(e);
     241     6574163 :     ly = lg(y); if (lz > ly) lz = ly;
     242     6574163 :     z = cgetr(lz); while (--lz) z[lz] = y[lz];
     243     6574163 :     setsigne(z,sy); return z;
     244             :   }
     245             : 
     246  2577395229 :   if (e < 0) { swap(x,y); lswap(sx,sy); ey=ex; e=-e; }
     247             :   /* now ey >= ex */
     248  2577395229 :   lx = lg(x);
     249  2577395229 :   ly = lg(y);
     250             :   /* If exponents differ, need to shift one argument, here x. If
     251             :    * extend = 1: extension of x,z by m < BIL bits (round to 1 word) */
     252             :   /* in this case, lz = lx + d + 1, otherwise lx + d */
     253  2577395229 :   extend = 0;
     254  2577395229 :   if (e)
     255             :   {
     256  2276333903 :     long d = dvmdsBIL(e, &m), l = ly-d;
     257  2276333903 :     if (l <= 2) return rcopy_sign(y, sy);
     258  2262379721 :     if (l > lx) { lz = lx + d + 1; extend = 1; }
     259  1868010283 :     else        { lz = ly; lx = l; }
     260  2262379721 :     if (m)
     261             :     { /* shift x right m bits */
     262  2261231213 :       const pari_sp av = avma;
     263  2261231213 :       const ulong sh = BITS_IN_LONG-m;
     264  2261231213 :       GEN p1 = x; x = new_chunk(lx + lz + 1);
     265  2261231213 :       shift_right(x,p1,2,lx, 0,m);
     266  2261231213 :       if (extend) uel(x,lx) = uel(p1,lx-1) << sh;
     267  2261231213 :       avma = av; /* HACK: cgetr(lz) will not overwrite x */
     268             :     }
     269             :   }
     270             :   else
     271             :   { /* d = 0 */
     272   301061326 :     m = 0;
     273   301061326 :     if (lx > ly) lx = ly;
     274   301061326 :     lz = lx;
     275             :   }
     276             : 
     277  2563441047 :   if (sx == sy)
     278             :   { /* addition */
     279  1140110376 :     i = lz-1;
     280  1140110376 :     j = lx-1;
     281  1140110376 :     if (extend) {
     282   228229201 :       ulong garde = addll(x[lx], y[i]);
     283   228229201 :       if (m < 4) /* don't extend for few correct bits */
     284    41681522 :         z = cgetr(--lz);
     285             :       else
     286             :       {
     287   186547679 :         z = cgetr(lz);
     288   186547679 :         z[i] = garde;
     289             :       }
     290             :     }
     291             :     else
     292             :     {
     293   911881175 :       z = cgetr(lz);
     294   911881175 :       z[i] = addll(x[j], y[i]); j--;
     295             :     }
     296  1140110376 :     i--;
     297  1140110376 :     for (; j>=2; i--,j--) z[i] = addllx(x[j],y[i]);
     298  1140110376 :     if (overflow)
     299             :     {
     300   317732118 :       z[1] = 1; /* stops since z[1] != 0 */
     301   318055166 :       for (;;) { z[i] = uel(y,i)+1; if (z[i--]) break; }
     302   317732118 :       if (i <= 0)
     303             :       {
     304   316859386 :         shift_right(z,z, 2,lz, 1,1);
     305   316859386 :         z[1] = evalsigne(sx) | evalexpo(ey+1); return z;
     306             :       }
     307             :     }
     308   823250990 :     for (; i>=2; i--) z[i] = y[i];
     309   823250990 :     z[1] = evalsigne(sx) | evalexpo(ey); return z;
     310             :   }
     311             : 
     312             :   /* subtraction */
     313  1423330671 :   if (e) f2 = 1;
     314             :   else
     315             :   {
     316   181197371 :     i = 2; while (i < lx && x[i] == y[i]) i++;
     317   181197371 :     if (i==lx) return real_0_bit(ey+1 - prec2nbits(lx));
     318   177574360 :     f2 = (uel(y,i) > uel(x,i));
     319             :   }
     320             :   /* result is non-zero. f2 = (y > x) */
     321  1419707660 :   i = lz-1; z = cgetr(lz);
     322  1419707660 :   if (f2)
     323             :   {
     324  1336249505 :     j = lx-1;
     325  1336249505 :     if (extend) z[i] = subll(y[i], x[lx]);
     326  1170109268 :     else        z[i] = subll(y[i], x[j--]);
     327  1336249505 :     for (i--; j>=2; i--) z[i] = subllx(y[i], x[j--]);
     328  1336249505 :     if (overflow) /* stops since y[1] != 0 */
     329     5923679 :       for (;;) { z[i] = uel(y,i)-1; if (y[i--]) break; }
     330  1336249505 :     for (; i>=2; i--) z[i] = y[i];
     331  1336249505 :     sx = sy;
     332             :   }
     333             :   else
     334             :   {
     335    83458155 :     if (extend) z[i] = subll(x[lx], y[i]);
     336    83458155 :     else        z[i] = subll(x[i],  y[i]);
     337    83458155 :     for (i--; i>=2; i--) z[i] = subllx(x[i], y[i]);
     338             :   }
     339             : 
     340  1419707660 :   x = z+2; i = 0; while (!x[i]) i++;
     341  1419707660 :   lz -= i; z += i;
     342  1419707660 :   j = bfffo(z[2]); /* need to shift left by j bits to normalize mantissa */
     343  1419707660 :   ez = ey - (j | (i * BITS_IN_LONG));
     344  1419707660 :   if (extend)
     345             :   { /* z was extended by d+1 words [should be e bits = d words + m bits] */
     346             :     /* not worth keeping extra word if less than 5 significant bits in there */
     347   166140237 :     if (m - j < 5 && lz > 3)
     348    65272633 :     { /* shorten z */
     349    65272633 :       ulong last = (ulong)z[--lz]; /* cancelled word */
     350             : 
     351             :       /* if we need to shift anyway, shorten from left
     352             :        * If not, shorten from right, neutralizing last word of z */
     353    65272633 :       if (j == 0)
     354             :         /* stackdummy((pari_sp)(z + lz+1), (pari_sp)(z + lz)); */
     355    34350430 :         z[lz] = evaltyp(t_VECSMALL) | _evallg(1);
     356             :       else
     357             :       {
     358    30922203 :         GEN t = z;
     359    30922203 :         z++; shift_left(z,t,2,lz-1, last,j);
     360             :       }
     361    65272633 :       if ((last<<j) & HIGHBIT)
     362             :       { /* round up */
     363    28951445 :         i = lz-1;
     364    28951445 :         while (++((ulong*)z)[i] == 0 && i > 1) i--;
     365    28951445 :         if (i == 1) { ez++; z[2] = (long)HIGHBIT; }
     366             :       }
     367             :     }
     368   100867604 :     else if (j) shift_left(z,z,2,lz-1, 0,j);
     369             :   }
     370  1253567423 :   else if (j) shift_left(z,z,2,lz-1, 0,j);
     371  1419707660 :   z[1] = evalsigne(sx) | evalexpo(ez);
     372  1419707660 :   z[0] = evaltyp(t_REAL) | evallg(lz);
     373  1419707660 :   avma = (pari_sp)z; return z;
     374             : }

Generated by: LCOV version 1.11