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 19350-bd5f220) Lines: 187 208 89.9 %
Date: 2016-08-24 06:11:24 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  1421141192 : icopy_sign(GEN x, long sx)
      17             : {
      18  1421141192 :   GEN y=icopy(x);
      19  1422172083 :   setsigne(y,sx);
      20  1422172083 :   return y;
      21             : }
      22             : 
      23             : GEN
      24   101873438 : addsi_sign(long x, GEN y, long sy)
      25             : {
      26             :   long sx,ly;
      27             :   GEN z;
      28             : 
      29   101873438 :   if (!x) return icopy_sign(y, sy);
      30   101009378 :   if (!sy) return stoi(x);
      31    96759765 :   if (x<0) { sx=-1; x=-x; } else sx=1;
      32    96759765 :   if (sx==sy)
      33             :   {
      34    59383456 :     z = adduispec(x,y+2, lgefint(y)-2);
      35    59383456 :     setsigne(z,sy); return z;
      36             :   }
      37    37376309 :   ly=lgefint(y);
      38    37376309 :   if (ly==3)
      39             :   {
      40     4055407 :     const long d = (long)(uel(y,2) - (ulong)x);
      41     4055407 :     if (!d) return gen_0;
      42     3679765 :     z=cgeti(3);
      43     3679762 :     if (y[2] < 0 || d > 0) {
      44     3220060 :       z[1] = evalsigne(sy) | evallgefint(3);
      45     3220060 :       z[2] = d;
      46             :     }
      47             :     else {
      48      459702 :       z[1] = evalsigne(-sy) | evallgefint(3);
      49      459702 :       z[2] =-d;
      50             :     }
      51     3679762 :     return z;
      52             :   }
      53    33320902 :   z = subiuspec(y+2,x, ly-2);
      54    33319779 :   setsigne(z,sy); return z;
      55             : }
      56             : GEN
      57    29284252 : addui_sign(ulong x, GEN y, long sy)
      58             : {
      59             :   long ly;
      60             :   GEN z;
      61             : 
      62    29284252 :   if (!x) return icopy_sign(y, sy);
      63    25708966 :   if (!sy) return utoipos(x);
      64    22404678 :   if (sy == 1) return adduispec(x,y+2, lgefint(y)-2);
      65     4842712 :   ly=lgefint(y);
      66     4842712 :   if (ly==3)
      67             :   {
      68     2967583 :     const ulong t = y[2];
      69     2967583 :     if (x == t) return gen_0;
      70     2030718 :     z=cgeti(3);
      71     2030718 :     if (x < t) {
      72     2030025 :       z[1] = evalsigne(-1) | evallgefint(3);
      73     2030025 :       z[2] = t - x;
      74             :     }
      75             :     else {
      76         693 :       z[1] = evalsigne(1) | evallgefint(3);
      77         693 :       z[2] = x - t;
      78             :     }
      79     2030718 :     return z;
      80             :   }
      81     1875129 :   z = subiuspec(y+2,x, ly-2);
      82     1875142 :   setsigne(z,-1); return z;
      83             : }
      84             : 
      85             : /* return gen_0 when the sign is 0 */
      86             : GEN
      87  8176958207 : addii_sign(GEN x, long sx, GEN y, long sy)
      88             : {
      89             :   long lx,ly;
      90             :   GEN z;
      91             : 
      92  8176958207 :   if (!sx) return sy? icopy_sign(y, sy): gen_0;
      93  7115579898 :   if (!sy) return icopy_sign(x, sx);
      94  6041572535 :   lx = lgefint(x);
      95  6041572535 :   ly = lgefint(y);
      96  6041572535 :   if (sx==sy)
      97  3105696894 :     z = addiispec(x+2,y+2,lx-2,ly-2);
      98             :   else
      99             :   { /* sx != sy */
     100  2935875641 :     long i = cmpiispec(x+2,y+2,lx-2,ly-2);
     101  2936797369 :     if (!i) return gen_0;
     102             :     /* we must ensure |x| > |y| for subiispec */
     103  2818768225 :     if (i < 0) {
     104  1142681333 :       sx = sy;
     105  1142681333 :       z = subiispec(y+2,x+2,ly-2,lx-2);
     106             :     }
     107             :     else
     108  1676086892 :       z = subiispec(x+2,y+2,lx-2,ly-2);
     109             :   }
     110  5920324286 :   setsigne(z,sx); return z;
     111             : }
     112             : 
     113             : INLINE GEN
     114    84931827 : rcopy_sign(GEN x, long sx) { GEN y = rcopy(x); setsigne(y,sx); return y; }
     115             : 
     116             : GEN
     117   212332774 : addir_sign(GEN x, long sx, GEN y, long sy)
     118             : {
     119             :   long e, l, ly;
     120             :   GEN z;
     121             : 
     122   212332774 :   if (!sx) return rcopy_sign(y, sy);
     123   141228536 :   e = expo(y) - expi(x);
     124   141228536 :   if (!sy)
     125             :   {
     126     5982730 :     if (e >= 0) return rcopy_sign(y, sy);
     127     5982640 :     z = itor(x, nbits2prec(-e));
     128     5982640 :     setsigne(z, sx); return z;
     129             :   }
     130             : 
     131   135245806 :   ly = lg(y);
     132   135245806 :   if (e > 0)
     133             :   {
     134    15334302 :     l = ly - divsBIL(e);
     135    15334302 :     if (l < 3) return rcopy_sign(y, sy);
     136             :   }
     137   119911504 :   else l = ly + nbits2extraprec(-e);
     138   135071964 :   z = (GEN)avma;
     139   135071964 :   y = addrr_sign(itor(x,l), sx, y, sy);
     140   135071964 :   ly = lg(y); while (ly--) *--z = y[ly];
     141   135071964 :   avma = (pari_sp)z; return z;
     142             : }
     143             : 
     144             : static GEN
     145   137640621 : addsr_sign(long x, GEN y, long sy)
     146             : {
     147             :   long e, l, ly, sx;
     148             :   GEN z;
     149             : 
     150   137640621 :   if (!x) return rcopy_sign(y, sy);
     151   137640432 :   if (x < 0) { sx = -1; x = -x; } else sx = 1;
     152   137640432 :   e = expo(y) - expu(x);
     153   137640432 :   if (!sy)
     154             :   {
     155      373698 :     if (e >= 0) return rcopy_sign(y, sy);
     156      373698 :     if (sx == -1) x = -x;
     157      373698 :     return stor(x, nbits2prec(-e));
     158             :   }
     159             : 
     160   137266734 :   ly = lg(y);
     161   137266734 :   if (e > 0)
     162             :   {
     163      675778 :     l = ly - divsBIL(e);
     164      675778 :     if (l < 3) return rcopy_sign(y, sy);
     165             :   }
     166   136590956 :   else l = ly + nbits2extraprec(-e);
     167   137224168 :   z = (GEN)avma;
     168   137224168 :   y = addrr_sign(stor(x,l), sx, y, sy);
     169   137224168 :   ly = lg(y); while (ly--) *--z = y[ly];
     170   137224168 :   avma = (pari_sp)z; return z;
     171             : }
     172             : 
     173             : GEN
     174   135596987 : addsr(long x, GEN y) { return addsr_sign(x, y, signe(y)); }
     175             : 
     176             : GEN
     177     2043634 : 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  2635132207 : addrr_sign(GEN x, long sx, GEN y, long sy)
     216             : {
     217  2635132207 :   long lx, ex = expo(x);
     218  2635132207 :   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  2635132207 :   if (!sy)
     225             :   {
     226    36637129 :     if (!sx)
     227             :     {
     228     9882593 :       if (e > 0) ex = ey;
     229     9882593 :       return real_0_bit(ex);
     230             :     }
     231    26754536 :     if (e >= 0) return real_0_bit(ey);
     232    26661556 :     lz = nbits2prec(-e);
     233    26661556 :     lx = lg(x); if (lz > lx) lz = lx;
     234    26661556 :     z = cgetr(lz); while(--lz) z[lz] = x[lz];
     235    26661556 :     setsigne(z,sx); return z;
     236             :   }
     237  2598495078 :   if (!sx)
     238             :   {
     239     6815066 :     if (e <= 0) return real_0_bit(ex);
     240     6609066 :     lz = nbits2prec(e);
     241     6609066 :     ly = lg(y); if (lz > ly) lz = ly;
     242     6609066 :     z = cgetr(lz); while (--lz) z[lz] = y[lz];
     243     6609066 :     setsigne(z,sy); return z;
     244             :   }
     245             : 
     246  2591680012 :   if (e < 0) { swap(x,y); lswap(sx,sy); ey=ex; e=-e; }
     247             :   /* now ey >= ex */
     248  2591680012 :   lx = lg(x);
     249  2591680012 :   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  2591680012 :   extend = 0;
     254  2591680012 :   if (e)
     255             :   {
     256  2288275241 :     long d = dvmdsBIL(e, &m), l = ly-d;
     257  2288275241 :     if (l <= 2) return rcopy_sign(y, sy);
     258  2274664339 :     if (l > lx) { lz = lx + d + 1; extend = 1; }
     259  1875979025 :     else        { lz = ly; lx = l; }
     260  2274664339 :     if (m)
     261             :     { /* shift x right m bits */
     262  2273532571 :       const pari_sp av = avma;
     263  2273532571 :       const ulong sh = BITS_IN_LONG-m;
     264  2273532571 :       GEN p1 = x; x = new_chunk(lx + lz + 1);
     265  2273532571 :       shift_right(x,p1,2,lx, 0,m);
     266  2273532571 :       if (extend) uel(x,lx) = uel(p1,lx-1) << sh;
     267  2273532571 :       avma = av; /* HACK: cgetr(lz) will not overwrite x */
     268             :     }
     269             :   }
     270             :   else
     271             :   { /* d = 0 */
     272   303404771 :     m = 0;
     273   303404771 :     if (lx > ly) lx = ly;
     274   303404771 :     lz = lx;
     275             :   }
     276             : 
     277  2578069110 :   if (sx == sy)
     278             :   { /* addition */
     279  1145615163 :     i = lz-1;
     280  1145615163 :     j = lx-1;
     281  1145615163 :     if (extend) {
     282   230092732 :       ulong garde = addll(x[lx], y[i]);
     283   230092732 :       if (m < 4) /* don't extend for few correct bits */
     284    42478517 :         z = cgetr(--lz);
     285             :       else
     286             :       {
     287   187614215 :         z = cgetr(lz);
     288   187614215 :         z[i] = garde;
     289             :       }
     290             :     }
     291             :     else
     292             :     {
     293   915522431 :       z = cgetr(lz);
     294   915522431 :       z[i] = addll(x[j], y[i]); j--;
     295             :     }
     296  1145615163 :     i--;
     297  1145615163 :     for (; j>=2; i--,j--) z[i] = addllx(x[j],y[i]);
     298  1145615163 :     if (overflow)
     299             :     {
     300   319432331 :       z[1] = 1; /* stops since z[1] != 0 */
     301   319755505 :       for (;;) { z[i] = uel(y,i)+1; if (z[i--]) break; }
     302   319432331 :       if (i <= 0)
     303             :       {
     304   318581461 :         shift_right(z,z, 2,lz, 1,1);
     305   318581461 :         z[1] = evalsigne(sx) | evalexpo(ey+1); return z;
     306             :       }
     307             :     }
     308   827033702 :     for (; i>=2; i--) z[i] = y[i];
     309   827033702 :     z[1] = evalsigne(sx) | evalexpo(ey); return z;
     310             :   }
     311             : 
     312             :   /* subtraction */
     313  1432453947 :   if (e) f2 = 1;
     314             :   else
     315             :   {
     316   182725295 :     i = 2; while (i < lx && x[i] == y[i]) i++;
     317   182725295 :     if (i==lx) return real_0_bit(ey+1 - prec2nbits(lx));
     318   179057704 :     f2 = (uel(y,i) > uel(x,i));
     319             :   }
     320             :   /* result is non-zero. f2 = (y > x) */
     321  1428786356 :   i = lz-1; z = cgetr(lz);
     322  1428786356 :   if (f2)
     323             :   {
     324  1344747657 :     j = lx-1;
     325  1344747657 :     if (extend) z[i] = subll(y[i], x[lx]);
     326  1176155075 :     else        z[i] = subll(y[i], x[j--]);
     327  1344747657 :     for (i--; j>=2; i--) z[i] = subllx(y[i], x[j--]);
     328  1344747657 :     if (overflow) /* stops since y[1] != 0 */
     329     6085542 :       for (;;) { z[i] = uel(y,i)-1; if (y[i--]) break; }
     330  1344747657 :     for (; i>=2; i--) z[i] = y[i];
     331  1344747657 :     sx = sy;
     332             :   }
     333             :   else
     334             :   {
     335    84038699 :     if (extend) z[i] = subll(x[lx], y[i]);
     336    84038699 :     else        z[i] = subll(x[i],  y[i]);
     337    84038699 :     for (i--; i>=2; i--) z[i] = subllx(x[i], y[i]);
     338             :   }
     339             : 
     340  1428786356 :   x = z+2; i = 0; while (!x[i]) i++;
     341  1428786356 :   lz -= i; z += i;
     342  1428786356 :   j = bfffo(z[2]); /* need to shift left by j bits to normalize mantissa */
     343  1428786356 :   ez = ey - (j | (i * BITS_IN_LONG));
     344  1428786356 :   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   168592582 :     if (m - j < 5 && lz > 3)
     348    66429520 :     { /* shorten z */
     349    66429520 :       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    66429520 :       if (j == 0)
     354             :         /* stackdummy((pari_sp)(z + lz+1), (pari_sp)(z + lz)); */
     355    34844553 :         z[lz] = evaltyp(t_VECSMALL) | _evallg(1);
     356             :       else
     357             :       {
     358    31584967 :         GEN t = z;
     359    31584967 :         z++; shift_left(z,t,2,lz-1, last,j);
     360             :       }
     361    66429520 :       if ((last<<j) & HIGHBIT)
     362             :       { /* round up */
     363    29253374 :         i = lz-1;
     364    29253374 :         while (++((ulong*)z)[i] == 0 && i > 1) i--;
     365    29253374 :         if (i == 1) { ez++; z[2] = (long)HIGHBIT; }
     366             :       }
     367             :     }
     368   102163062 :     else if (j) shift_left(z,z,2,lz-1, 0,j);
     369             :   }
     370  1260193774 :   else if (j) shift_left(z,z,2,lz-1, 0,j);
     371  1428786356 :   z[1] = evalsigne(sx) | evalexpo(ez);
     372  1428786356 :   z[0] = evaltyp(t_REAL) | evallg(lz);
     373  1428786356 :   avma = (pari_sp)z; return z;
     374             : }

Generated by: LCOV version 1.11