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 19611-73a567d) Lines: 187 208 89.9 %
Date: 2016-09-27 05:54:40 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  1438131222 : icopy_sign(GEN x, long sx)
      17             : {
      18  1438131222 :   GEN y=icopy(x);
      19  1439090167 :   setsigne(y,sx);
      20  1439090167 :   return y;
      21             : }
      22             : 
      23             : GEN
      24    92332378 : addsi_sign(long x, GEN y, long sy)
      25             : {
      26             :   long sx,ly;
      27             :   GEN z;
      28             : 
      29    92332378 :   if (!x) return icopy_sign(y, sy);
      30    91454792 :   if (!sy) return stoi(x);
      31    87049234 :   if (x<0) { sx=-1; x=-x; } else sx=1;
      32    87049234 :   if (sx==sy)
      33             :   {
      34    59515751 :     z = adduispec(x,y+2, lgefint(y)-2);
      35    59515751 :     setsigne(z,sy); return z;
      36             :   }
      37    27533483 :   ly=lgefint(y);
      38    27533483 :   if (ly==3)
      39             :   {
      40     4149815 :     const long d = (long)(uel(y,2) - (ulong)x);
      41     4149815 :     if (!d) return gen_0;
      42     3754503 :     z=cgeti(3);
      43     3754501 :     if (y[2] < 0 || d > 0) {
      44     3294656 :       z[1] = evalsigne(sy) | evallgefint(3);
      45     3294656 :       z[2] = d;
      46             :     }
      47             :     else {
      48      459845 :       z[1] = evalsigne(-sy) | evallgefint(3);
      49      459845 :       z[2] =-d;
      50             :     }
      51     3754501 :     return z;
      52             :   }
      53    23383668 :   z = subiuspec(y+2,x, ly-2);
      54    23381989 :   setsigne(z,sy); return z;
      55             : }
      56             : GEN
      57    28236014 : addui_sign(ulong x, GEN y, long sy)
      58             : {
      59             :   long ly;
      60             :   GEN z;
      61             : 
      62    28236014 :   if (!x) return icopy_sign(y, sy);
      63    24656885 :   if (!sy) return utoipos(x);
      64    21348986 :   if (sy == 1) return adduispec(x,y+2, lgefint(y)-2);
      65     4896789 :   ly=lgefint(y);
      66     4896789 :   if (ly==3)
      67             :   {
      68     2991250 :     const ulong t = y[2];
      69     2991250 :     if (x == t) return gen_0;
      70     2052663 :     z=cgeti(3);
      71     2052663 :     if (x < t) {
      72     2051949 :       z[1] = evalsigne(-1) | evallgefint(3);
      73     2051949 :       z[2] = t - x;
      74             :     }
      75             :     else {
      76         714 :       z[1] = evalsigne(1) | evallgefint(3);
      77         714 :       z[2] = x - t;
      78             :     }
      79     2052663 :     return z;
      80             :   }
      81     1905539 :   z = subiuspec(y+2,x, ly-2);
      82     1905539 :   setsigne(z,-1); return z;
      83             : }
      84             : 
      85             : /* return gen_0 when the sign is 0 */
      86             : GEN
      87  7227305258 : addii_sign(GEN x, long sx, GEN y, long sy)
      88             : {
      89             :   long lx,ly;
      90             :   GEN z;
      91             : 
      92  7227305258 :   if (!sx) return sy? icopy_sign(y, sy): gen_0;
      93  6179698164 :   if (!sy) return icopy_sign(x, sx);
      94  5094704979 :   lx = lgefint(x);
      95  5094704979 :   ly = lgefint(y);
      96  5094704979 :   if (sx==sy)
      97  2713709697 :     z = addiispec(x+2,y+2,lx-2,ly-2);
      98             :   else
      99             :   { /* sx != sy */
     100  2380995282 :     long i = cmpiispec(x+2,y+2,lx-2,ly-2);
     101  2381885620 :     if (!i) return gen_0;
     102             :     /* we must ensure |x| > |y| for subiispec */
     103  2259728918 :     if (i < 0) {
     104   992129560 :       sx = sy;
     105   992129560 :       z = subiispec(y+2,x+2,ly-2,lx-2);
     106             :     }
     107             :     else
     108  1267599358 :       z = subiispec(x+2,y+2,lx-2,ly-2);
     109             :   }
     110  4969271367 :   setsigne(z,sx); return z;
     111             : }
     112             : 
     113             : INLINE GEN
     114    92918657 : rcopy_sign(GEN x, long sx) { GEN y = rcopy(x); setsigne(y,sx); return y; }
     115             : 
     116             : GEN
     117   194105091 : addir_sign(GEN x, long sx, GEN y, long sy)
     118             : {
     119             :   long e, l, ly;
     120             :   GEN z;
     121             : 
     122   194105091 :   if (!sx) return rcopy_sign(y, sy);
     123   115479847 :   e = expo(y) - expi(x);
     124   115479847 :   if (!sy)
     125             :   {
     126     5762123 :     if (e >= 0) return rcopy_sign(y, sy);
     127     5762033 :     z = itor(x, nbits2prec(-e));
     128     5762033 :     setsigne(z, sx); return z;
     129             :   }
     130             : 
     131   109717724 :   ly = lg(y);
     132   109717724 :   if (e > 0)
     133             :   {
     134    12290634 :     l = ly - divsBIL(e);
     135    12290634 :     if (l < 3) return rcopy_sign(y, sy);
     136             :   }
     137    97427090 :   else l = ly + nbits2extraprec(-e);
     138   109543476 :   z = (GEN)avma;
     139   109543476 :   y = addrr_sign(itor(x,l), sx, y, sy);
     140   109543476 :   ly = lg(y); while (ly--) *--z = y[ly];
     141   109543476 :   avma = (pari_sp)z; return z;
     142             : }
     143             : 
     144             : static GEN
     145   138369778 : addsr_sign(long x, GEN y, long sy)
     146             : {
     147             :   long e, l, ly, sx;
     148             :   GEN z;
     149             : 
     150   138369778 :   if (!x) return rcopy_sign(y, sy);
     151   138369589 :   if (x < 0) { sx = -1; x = -x; } else sx = 1;
     152   138369589 :   e = expo(y) - expu(x);
     153   138369589 :   if (!sy)
     154             :   {
     155      381801 :     if (e >= 0) return rcopy_sign(y, sy);
     156      381801 :     if (sx == -1) x = -x;
     157      381801 :     return stor(x, nbits2prec(-e));
     158             :   }
     159             : 
     160   137987788 :   ly = lg(y);
     161   137987788 :   if (e > 0)
     162             :   {
     163      682061 :     l = ly - divsBIL(e);
     164      682061 :     if (l < 3) return rcopy_sign(y, sy);
     165             :   }
     166   137305727 :   else l = ly + nbits2extraprec(-e);
     167   137944610 :   z = (GEN)avma;
     168   137944610 :   y = addrr_sign(stor(x,l), sx, y, sy);
     169   137944610 :   ly = lg(y); while (ly--) *--z = y[ly];
     170   137944610 :   avma = (pari_sp)z; return z;
     171             : }
     172             : 
     173             : GEN
     174   136323678 : addsr(long x, GEN y) { return addsr_sign(x, y, signe(y)); }
     175             : 
     176             : GEN
     177     2046100 : 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  1972364569 : addrr_sign(GEN x, long sx, GEN y, long sy)
     216             : {
     217  1972364569 :   long lx, ex = expo(x);
     218  1972364569 :   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  1972364569 :   if (!sy)
     225             :   {
     226    35012079 :     if (!sx)
     227             :     {
     228     9576900 :       if (e > 0) ex = ey;
     229     9576900 :       return real_0_bit(ex);
     230             :     }
     231    25435179 :     if (e >= 0) return real_0_bit(ey);
     232    25339221 :     lz = nbits2prec(-e);
     233    25339221 :     lx = lg(x); if (lz > lx) lz = lx;
     234    25339221 :     z = cgetr(lz); while(--lz) z[lz] = x[lz];
     235    25339221 :     setsigne(z,sx); return z;
     236             :   }
     237  1937352490 :   if (!sx)
     238             :   {
     239     6833996 :     if (e <= 0) return real_0_bit(ex);
     240     6620032 :     lz = nbits2prec(e);
     241     6620032 :     ly = lg(y); if (lz > ly) lz = ly;
     242     6620032 :     z = cgetr(lz); while (--lz) z[lz] = y[lz];
     243     6620032 :     setsigne(z,sy); return z;
     244             :   }
     245             : 
     246  1930518494 :   if (e < 0) { swap(x,y); lswap(sx,sy); ey=ex; e=-e; }
     247             :   /* now ey >= ex */
     248  1930518494 :   lx = lg(x);
     249  1930518494 :   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  1930518494 :   extend = 0;
     254  1930518494 :   if (e)
     255             :   {
     256  1710425385 :     long d = dvmdsBIL(e, &m), l = ly-d;
     257  1710425385 :     if (l <= 2) return rcopy_sign(y, sy);
     258  1696349677 :     if (l > lx) { lz = lx + d + 1; extend = 1; }
     259  1318248840 :     else        { lz = ly; lx = l; }
     260  1696349677 :     if (m)
     261             :     { /* shift x right m bits */
     262  1695171069 :       const pari_sp av = avma;
     263  1695171069 :       const ulong sh = BITS_IN_LONG-m;
     264  1695171069 :       GEN p1 = x; x = new_chunk(lx + lz + 1);
     265  1695171069 :       shift_right(x,p1,2,lx, 0,m);
     266  1695171069 :       if (extend) uel(x,lx) = uel(p1,lx-1) << sh;
     267  1695171069 :       avma = av; /* HACK: cgetr(lz) will not overwrite x */
     268             :     }
     269             :   }
     270             :   else
     271             :   { /* d = 0 */
     272   220093109 :     m = 0;
     273   220093109 :     if (lx > ly) lx = ly;
     274   220093109 :     lz = lx;
     275             :   }
     276             : 
     277  1916442786 :   if (sx == sy)
     278             :   { /* addition */
     279   886321685 :     i = lz-1;
     280   886321685 :     j = lx-1;
     281   886321685 :     if (extend) {
     282   222958297 :       ulong garde = addll(x[lx], y[i]);
     283   222958297 :       if (m < 4) /* don't extend for few correct bits */
     284    36453035 :         z = cgetr(--lz);
     285             :       else
     286             :       {
     287   186505262 :         z = cgetr(lz);
     288   186505262 :         z[i] = garde;
     289             :       }
     290             :     }
     291             :     else
     292             :     {
     293   663363388 :       z = cgetr(lz);
     294   663363388 :       z[i] = addll(x[j], y[i]); j--;
     295             :     }
     296   886321685 :     i--;
     297   886321685 :     for (; j>=2; i--,j--) z[i] = addllx(x[j],y[i]);
     298   886321685 :     if (overflow)
     299             :     {
     300   216567689 :       z[1] = 1; /* stops since z[1] != 0 */
     301   216900555 :       for (;;) { z[i] = uel(y,i)+1; if (z[i--]) break; }
     302   216567689 :       if (i <= 0)
     303             :       {
     304   215685774 :         shift_right(z,z, 2,lz, 1,1);
     305   215685774 :         z[1] = evalsigne(sx) | evalexpo(ey+1); return z;
     306             :       }
     307             :     }
     308   670635911 :     for (; i>=2; i--) z[i] = y[i];
     309   670635911 :     z[1] = evalsigne(sx) | evalexpo(ey); return z;
     310             :   }
     311             : 
     312             :   /* subtraction */
     313  1030121101 :   if (e) f2 = 1;
     314             :   else
     315             :   {
     316   134195386 :     i = 2; while (i < lx && x[i] == y[i]) i++;
     317   134195386 :     if (i==lx) return real_0_bit(ey+1 - prec2nbits(lx));
     318   130406423 :     f2 = (uel(y,i) > uel(x,i));
     319             :   }
     320             :   /* result is non-zero. f2 = (y > x) */
     321  1026332138 :   i = lz-1; z = cgetr(lz);
     322  1026332138 :   if (f2)
     323             :   {
     324   970601094 :     j = lx-1;
     325   970601094 :     if (extend) z[i] = subll(y[i], x[lx]);
     326   815458554 :     else        z[i] = subll(y[i], x[j--]);
     327   970601094 :     for (i--; j>=2; i--) z[i] = subllx(y[i], x[j--]);
     328   970601094 :     if (overflow) /* stops since y[1] != 0 */
     329     7000861 :       for (;;) { z[i] = uel(y,i)-1; if (y[i--]) break; }
     330   970601094 :     for (; i>=2; i--) z[i] = y[i];
     331   970601094 :     sx = sy;
     332             :   }
     333             :   else
     334             :   {
     335    55731044 :     if (extend) z[i] = subll(x[lx], y[i]);
     336    55731044 :     else        z[i] = subll(x[i],  y[i]);
     337    55731044 :     for (i--; i>=2; i--) z[i] = subllx(x[i], y[i]);
     338             :   }
     339             : 
     340  1026332138 :   x = z+2; i = 0; while (!x[i]) i++;
     341  1026332138 :   lz -= i; z += i;
     342  1026332138 :   j = bfffo(z[2]); /* need to shift left by j bits to normalize mantissa */
     343  1026332138 :   ez = ey - (j | (i * BITS_IN_LONG));
     344  1026332138 :   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   155142540 :     if (m - j < 5 && lz > 3)
     348    53215740 :     { /* shorten z */
     349    53215740 :       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    53215740 :       if (j == 0)
     354             :         /* stackdummy((pari_sp)(z + lz+1), (pari_sp)(z + lz)); */
     355    27699293 :         z[lz] = evaltyp(t_VECSMALL) | _evallg(1);
     356             :       else
     357             :       {
     358    25516447 :         GEN t = z;
     359    25516447 :         z++; shift_left(z,t,2,lz-1, last,j);
     360             :       }
     361    53215740 :       if ((last<<j) & HIGHBIT)
     362             :       { /* round up */
     363    23403111 :         i = lz-1;
     364    23403111 :         while (++((ulong*)z)[i] == 0 && i > 1) i--;
     365    23403111 :         if (i == 1) { ez++; z[2] = (long)HIGHBIT; }
     366             :       }
     367             :     }
     368   101926800 :     else if (j) shift_left(z,z,2,lz-1, 0,j);
     369             :   }
     370   871189598 :   else if (j) shift_left(z,z,2,lz-1, 0,j);
     371  1026332138 :   z[1] = evalsigne(sx) | evalexpo(ez);
     372  1026332138 :   z[0] = evaltyp(t_REAL) | evallg(lz);
     373  1026332138 :   avma = (pari_sp)z; return z;
     374             : }

Generated by: LCOV version 1.11