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 to exceed 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.12.1 lcov report (development 25819-e703fe1174) Lines: 187 187 100.0 %
Date: 2020-09-18 06:10:04 Functions: 10 10 100.0 %
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  1692224690 : icopy_sign(GEN x, long sx)
      17             : {
      18  1692224690 :   GEN y=icopy(x);
      19  1693482854 :   setsigne(y,sx);
      20  1693482854 :   return y;
      21             : }
      22             : 
      23             : GEN
      24    84585456 : addsi_sign(long x, GEN y, long sy)
      25             : {
      26             :   long sx,ly;
      27             :   GEN z;
      28             : 
      29    84585456 :   if (!x) return icopy_sign(y, sy);
      30    81941896 :   if (!sy) return stoi(x);
      31    71902870 :   if (x<0) { sx=-1; x=-x; } else sx=1;
      32    71902870 :   if (sx==sy)
      33             :   {
      34    26093733 :     z = adduispec(x,y+2, lgefint(y)-2);
      35    26093732 :     setsigne(z,sy); return z;
      36             :   }
      37    45809137 :   ly=lgefint(y);
      38    45809137 :   if (ly==3)
      39             :   {
      40     7187708 :     const long d = (long)(uel(y,2) - (ulong)x);
      41     7187708 :     if (!d) return gen_0;
      42     6621515 :     z=cgeti(3);
      43     6621515 :     if (y[2] < 0 || d > 0) {
      44     4233005 :       z[1] = evalsigne(sy) | evallgefint(3);
      45     4233005 :       z[2] = d;
      46             :     }
      47             :     else {
      48     2388510 :       z[1] = evalsigne(-sy) | evallgefint(3);
      49     2388510 :       z[2] =-d;
      50             :     }
      51     6621515 :     return z;
      52             :   }
      53    38621429 :   z = subiuspec(y+2,x, ly-2);
      54    38741826 :   setsigne(z,sy); return z;
      55             : }
      56             : GEN
      57   145066160 : addui_sign(ulong x, GEN y, long sy)
      58             : {
      59             :   long ly;
      60             :   GEN z;
      61             : 
      62   145066160 :   if (!x) return icopy_sign(y, sy);
      63   143029504 :   if (!sy) return utoipos(x);
      64   140934650 :   if (sy == 1) return adduispec(x,y+2, lgefint(y)-2);
      65    37122981 :   ly=lgefint(y);
      66    37122981 :   if (ly==3)
      67             :   {
      68    16501797 :     const ulong t = y[2];
      69    16501797 :     if (x == t) return gen_0;
      70    16063108 :     z=cgeti(3);
      71    16063041 :     if (x < t) {
      72    15832601 :       z[1] = evalsigne(-1) | evallgefint(3);
      73    15832601 :       z[2] = t - x;
      74             :     }
      75             :     else {
      76      230440 :       z[1] = evalsigne(1) | evallgefint(3);
      77      230440 :       z[2] = x - t;
      78             :     }
      79    16063041 :     return z;
      80             :   }
      81    20621184 :   z = subiuspec(y+2,x, ly-2);
      82    20618466 :   setsigne(z,-1); return z;
      83             : }
      84             : 
      85             : /* return gen_0 when the sign is 0 */
      86             : GEN
      87 10797302263 : addii_sign(GEN x, long sx, GEN y, long sy)
      88             : {
      89             :   long lx,ly;
      90             :   GEN z;
      91             : 
      92 10797302263 :   if (!sx) return sy? icopy_sign(y, sy): gen_0;
      93  9502759575 :   if (!sy) return icopy_sign(x, sx);
      94  8314077279 :   lx = lgefint(x);
      95  8314077279 :   ly = lgefint(y);
      96  8314077279 :   if (sx==sy)
      97  4256461185 :     z = addiispec(x+2,y+2,lx-2,ly-2);
      98             :   else
      99             :   { /* sx != sy */
     100  4057616094 :     long i = cmpiispec(x+2,y+2,lx-2,ly-2);
     101  4081708035 :     if (!i) return gen_0;
     102             :     /* we must ensure |x| > |y| for subiispec */
     103  3921863292 :     if (i < 0) {
     104  1590917594 :       sx = sy;
     105  1590917594 :       z = subiispec(y+2,x+2,ly-2,lx-2);
     106             :     }
     107             :     else
     108  2330945698 :       z = subiispec(x+2,y+2,lx-2,ly-2);
     109             :   }
     110  8154975824 :   setsigne(z,sx); return z;
     111             : }
     112             : 
     113             : INLINE GEN
     114   179898244 : rcopy_sign(GEN x, long sx) { GEN y = rcopy(x); setsigne(y,sx); return y; }
     115             : 
     116             : GEN
     117   372265342 : addir_sign(GEN x, long sx, GEN y, long sy)
     118             : {
     119             :   long e, l, ly;
     120             :   GEN z;
     121             : 
     122   372265342 :   if (!sx) return rcopy_sign(y, sy);
     123   239040129 :   e = expo(y) - expi(x);
     124   239040242 :   if (!sy)
     125             :   {
     126    15145332 :     if (e >= 0) return rcopy_sign(y, sy);
     127    15145277 :     z = itor(x, nbits2prec(-e));
     128    15145277 :     setsigne(z, sx); return z;
     129             :   }
     130             : 
     131   223894910 :   ly = lg(y);
     132   223894910 :   if (e > 0)
     133             :   {
     134    30396297 :     l = ly - divsBIL(e);
     135    30396122 :     if (l < 3) return rcopy_sign(y, sy);
     136             :   }
     137   193498613 :   else l = ly + nbits2extraprec(-e);
     138   223590285 :   z = (GEN)avma;
     139   223590285 :   y = addrr_sign(itor(x,l), sx, y, sy);
     140  1632065212 :   ly = lg(y); while (ly--) *--z = y[ly];
     141   223591461 :   set_avma((pari_sp)z); return z;
     142             : }
     143             : 
     144             : static GEN
     145   180493126 : addsr_sign(long x, GEN y, long sy)
     146             : {
     147             :   long e, l, ly, sx;
     148             :   GEN z;
     149             : 
     150   180493126 :   if (!x) return rcopy_sign(y, sy);
     151   180485937 :   if (x < 0) { sx = -1; x = -x; } else sx = 1;
     152   180485937 :   e = expo(y) - expu(x);
     153   180456008 :   if (!sy)
     154             :   {
     155       37604 :     if (e >= 0) return rcopy_sign(y, sy);
     156       37604 :     if (sx == -1) x = -x;
     157       37604 :     return stor(x, nbits2prec(-e));
     158             :   }
     159             : 
     160   180418404 :   ly = lg(y);
     161   180418404 :   if (e > 0)
     162             :   {
     163     2640631 :     l = ly - divsBIL(e);
     164     2640629 :     if (l < 3) return rcopy_sign(y, sy);
     165             :   }
     166   177777773 :   else l = ly + nbits2extraprec(-e);
     167   180225501 :   z = (GEN)avma;
     168   180225501 :   y = addrr_sign(stor(x,l), sx, y, sy);
     169  1574040582 :   ly = lg(y); while (ly--) *--z = y[ly];
     170   180184587 :   set_avma((pari_sp)z); return z;
     171             : }
     172             : 
     173             : GEN
     174   176158681 : addsr(long x, GEN y) { return addsr_sign(x, y, signe(y)); }
     175             : 
     176             : GEN
     177     4347794 : subsr(long x, GEN y) { return addsr_sign(x, y, -signe(y)); }
     178             : 
     179             : GEN
     180  3395764154 : addrr_sign(GEN x, long sx, GEN y, long sy)
     181             : {
     182  3395764154 :   long lx, ex = expo(x);
     183  3395764154 :   long ly, ey = expo(y), e = ey - ex;
     184             :   long i, j, lz, ez, m;
     185             :   int extend, f2;
     186             :   GEN z;
     187             :   LOCAL_OVERFLOW;
     188             : 
     189  3395764154 :   if (!sy)
     190             :   {
     191    76999886 :     if (!sx)
     192             :     {
     193    21733501 :       if (e > 0) ex = ey;
     194    21733501 :       return real_0_bit(ex);
     195             :     }
     196    55266385 :     if (e >= 0) return real_0_bit(ey);
     197    54387650 :     lz = nbits2prec(-e);
     198    54387664 :     lx = lg(x); if (lz > lx) lz = lx;
     199   271967710 :     z = cgetr(lz); while(--lz) z[lz] = x[lz];
     200    54387660 :     setsigne(z,sx); return z;
     201             :   }
     202  3318764268 :   if (!sx)
     203             :   {
     204    12737329 :     if (e <= 0) return real_0_bit(ex);
     205    11516592 :     lz = nbits2prec(e);
     206    11516592 :     ly = lg(y); if (lz > ly) lz = ly;
     207    63663441 :     z = cgetr(lz); while (--lz) z[lz] = y[lz];
     208    11516592 :     setsigne(z,sy); return z;
     209             :   }
     210             : 
     211  3306026939 :   if (e < 0) { swap(x,y); lswap(sx,sy); ey=ex; e=-e; }
     212             :   /* now ey >= ex */
     213  3306026939 :   lx = lg(x);
     214  3306026939 :   ly = lg(y);
     215             :   /* If exponents differ, need to shift one argument, here x. If
     216             :    * extend = 1: extension of x,z by m < BIL bits (round to 1 word) */
     217             :   /* in this case, lz = lx + d + 1, otherwise lx + d */
     218  3306026939 :   extend = 0;
     219  3306026939 :   if (e)
     220             :   {
     221  2915476652 :     long d = dvmdsBIL(e, &m), l = ly-d;
     222  2915325607 :     if (l <= 2) return rcopy_sign(y, sy);
     223  2870260340 :     if (l > lx) { lz = lx + d + 1; extend = 1; }
     224  2235659444 :     else        { lz = ly; lx = l; }
     225  2870260340 :     if (m)
     226             :     { /* shift x right m bits */
     227  2866141484 :       const pari_sp av = avma;
     228  2866141484 :       const ulong sh = BITS_IN_LONG-m;
     229  2866141484 :       GEN p1 = x; x = new_chunk(lx + lz + 1);
     230  2865374250 :       shift_right(x,p1,2,lx, 0,m);
     231  2865420404 :       if (extend) uel(x,lx) = uel(p1,lx-1) << sh;
     232  2865420404 :       set_avma(av); /* HACK: cgetr(lz) will not overwrite x */
     233             :     }
     234             :   }
     235             :   else
     236             :   { /* d = 0 */
     237   390550287 :     m = 0;
     238   390550287 :     if (lx > ly) lx = ly;
     239   390550287 :     lz = lx;
     240             :   }
     241             : 
     242  3258229938 :   if (sx == sy)
     243             :   { /* addition */
     244  1522361658 :     i = lz-1;
     245  1522361658 :     j = lx-1;
     246  1522361658 :     if (extend) {
     247   358223130 :       ulong garde = addll(x[lx], y[i]);
     248   358223130 :       if (m < 4) /* don't extend for few correct bits */
     249    65638750 :         z = cgetr(--lz);
     250             :       else
     251             :       {
     252   292584380 :         z = cgetr(lz);
     253   292522498 :         z[i] = garde;
     254             :       }
     255             :     }
     256             :     else
     257             :     {
     258  1164138528 :       z = cgetr(lz);
     259  1164953132 :       z[i] = addll(x[j], y[i]); j--;
     260             :     }
     261  1522981139 :     i--;
     262  6278815546 :     for (; j>=2; i--,j--) z[i] = addllx(x[j],y[i]);
     263  1522981139 :     if (overflow)
     264             :     {
     265   403654123 :       z[1] = 1; /* stops since z[1] != 0 */
     266   404542187 :       for (;;) { z[i] = uel(y,i)+1; if (z[i--]) break; }
     267   403654123 :       if (i <= 0)
     268             :       {
     269   401192806 :         shift_right(z,z, 2,lz, 1,1);
     270   401242213 :         z[1] = evalsigne(sx) | evalexpo(ey+1); return z;
     271             :       }
     272             :     }
     273  1407466620 :     for (; i>=2; i--) z[i] = y[i];
     274  1121788333 :     z[1] = evalsigne(sx) | evalexpo(ey); return z;
     275             :   }
     276             : 
     277             :   /* subtraction */
     278  1735868280 :   if (e) f2 = 1;
     279             :   else
     280             :   {
     281   332364499 :     i = 2; while (i < lx && x[i] == y[i]) i++;
     282   228359174 :     if (i==lx) return real_0_bit(ey+1 - prec2nbits(lx));
     283   220391902 :     f2 = (uel(y,i) > uel(x,i));
     284             :   }
     285             :   /* result is non-zero. f2 = (y > x) */
     286  1727901008 :   i = lz-1; z = cgetr(lz);
     287  1729404874 :   if (f2)
     288             :   {
     289  1625144153 :     j = lx-1;
     290  1625144153 :     if (extend) z[i] = subll(y[i], x[lx]);
     291  1348998249 :     else        z[i] = subll(y[i], x[j--]);
     292  5808703434 :     for (i--; j>=2; i--) z[i] = subllx(y[i], x[j--]);
     293  1625144153 :     if (overflow) /* stops since y[1] != 0 */
     294    16012565 :       for (;;) { z[i] = uel(y,i)-1; if (y[i--]) break; }
     295  1816218865 :     for (; i>=2; i--) z[i] = y[i];
     296  1625144153 :     sx = sy;
     297             :   }
     298             :   else
     299             :   {
     300   104260721 :     if (extend) z[i] = subll(x[lx], y[i]);
     301   104260721 :     else        z[i] = subll(x[i],  y[i]);
     302   418998034 :     for (i--; i>=2; i--) z[i] = subllx(x[i], y[i]);
     303             :   }
     304             : 
     305  1807468284 :   x = z+2; i = 0; while (!x[i]) i++;
     306  1729404874 :   lz -= i; z += i;
     307  1729404874 :   j = bfffo(z[2]); /* need to shift left by j bits to normalize mantissa */
     308  1729404874 :   ez = ey - (j | (i * BITS_IN_LONG));
     309  1729404874 :   if (extend)
     310             :   { /* z was extended by d+1 words [should be e bits = d words + m bits] */
     311             :     /* not worth keeping extra word if less than 5 significant bits in there */
     312   276161296 :     if (m - j < 5 && lz > 3)
     313   103079252 :     { /* shorten z */
     314   103079121 :       ulong last = (ulong)z[--lz]; /* cancelled word */
     315             : 
     316             :       /* if we need to shift anyway, shorten from left
     317             :        * If not, shorten from right, neutralizing last word of z */
     318   103079121 :       if (j == 0)
     319             :         /* stackdummy((pari_sp)(z + lz+1), (pari_sp)(z + lz)); */
     320    53716372 :         z[lz] = evaltyp(t_VECSMALL) | _evallg(1);
     321             :       else
     322             :       {
     323    49362749 :         GEN t = z;
     324    49362749 :         z++; shift_left(z,t,2,lz-1, last,j);
     325             :       }
     326   103079252 :       if ((last<<j) & HIGHBIT)
     327             :       { /* round up */
     328    45527917 :         i = lz-1;
     329    45641967 :         while (++((ulong*)z)[i] == 0 && i > 1) i--;
     330    45527917 :         if (i == 1) { ez++; z[2] = (long)HIGHBIT; }
     331             :       }
     332             :     }
     333   173082175 :     else if (j) shift_left(z,z,2,lz-1, 0,j);
     334             :   }
     335  1453243578 :   else if (j) shift_left(z,z,2,lz-1, 0,j);
     336  1729422580 :   z[1] = evalsigne(sx) | evalexpo(ez);
     337  1729519006 :   z[0] = evaltyp(t_REAL) | evallg(lz);
     338  1729456578 :   set_avma((pari_sp)z); return z;
     339             : }

Generated by: LCOV version 1.13