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) Coverage Total Hit
Test: PARI/GP v2.19.0 lcov report (development 31092-e6893b0017) Lines: 100.0 % 187 187
Test Date: 2026-10-28 17:03:18 Functions: 100.0 % 10 10
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; either version 2 of the License, or (at your option) any later
       9              : version. It is distributed in the hope that it will be useful, but WITHOUT
      10              : ANY WARRANTY WHATSOEVER.
      11              : 
      12              : Check the License for details. You should have received a copy of it, along
      13              : with the package; see the file 'COPYING'. If not, write to the Free Software
      14              : Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
      15              : 
      16              : INLINE GEN
      17   4164158107 : icopy_sign(GEN x, long sx)
      18              : {
      19   4164158107 :   GEN y=icopy(x);
      20   4164158107 :   setsigne(y,sx);
      21   4164158107 :   return y;
      22              : }
      23              : 
      24              : GEN
      25    327906056 : addsi_sign(long x, GEN y, long sy)
      26              : {
      27              :   long sx,ly;
      28              :   GEN z;
      29              : 
      30    327906056 :   if (!x) return icopy_sign(y, sy);
      31    311440154 :   if (!sy) return stoi(x);
      32    181155571 :   if (x<0) { sx=-1; x=-x; } else sx=1;
      33    181155571 :   if (sx==sy)
      34              :   {
      35     51115343 :     z = adduispec(x,y+2, lgefint(y)-2);
      36     51115343 :     setsigne(z,sy); return z;
      37              :   }
      38    130040228 :   ly=lgefint(y);
      39    130040228 :   if (ly==3)
      40              :   {
      41     18137417 :     const long d = (long)(uel(y,2) - (ulong)x);
      42     18137417 :     if (!d) return gen_0;
      43     17115235 :     z=cgeti(3);
      44     17115235 :     if (y[2] < 0 || d > 0) {
      45     14640060 :       z[1] = evalsigne(sy) | evallgefint(3);
      46     14640060 :       z[2] = d;
      47              :     }
      48              :     else {
      49      2475175 :       z[1] = evalsigne(-sy) | evallgefint(3);
      50      2475175 :       z[2] =-d;
      51              :     }
      52     17115235 :     return z;
      53              :   }
      54    111902811 :   z = subiuspec(y+2,x, ly-2);
      55    111902811 :   setsigne(z,sy); return z;
      56              : }
      57              : GEN
      58    245517424 : addui_sign(ulong x, GEN y, long sy)
      59              : {
      60              :   long ly;
      61              :   GEN z;
      62              : 
      63    245517424 :   if (!x) return icopy_sign(y, sy);
      64    242564063 :   if (!sy) return utoipos(x);
      65    233915163 :   if (sy == 1) return adduispec(x,y+2, lgefint(y)-2);
      66    116233686 :   ly=lgefint(y);
      67    116233686 :   if (ly==3)
      68              :   {
      69     29274389 :     const ulong t = y[2];
      70     29274389 :     if (x == t) return gen_0;
      71     26841283 :     z=cgeti(3);
      72     26841283 :     if (x < t) {
      73     25109632 :       z[1] = evalsigne(-1) | evallgefint(3);
      74     25109632 :       z[2] = t - x;
      75              :     }
      76              :     else {
      77      1731651 :       z[1] = evalsigne(1) | evallgefint(3);
      78      1731651 :       z[2] = x - t;
      79              :     }
      80     26841283 :     return z;
      81              :   }
      82     86959297 :   z = subiuspec(y+2,x, ly-2);
      83     86959297 :   setsigne(z,-1); return z;
      84              : }
      85              : 
      86              : /* return gen_0 when the sign is 0 */
      87              : GEN
      88  19766445414 : addii_sign(GEN x, long sx, GEN y, long sy)
      89              : {
      90              :   long lx,ly;
      91              :   GEN z;
      92              : 
      93  19766445414 :   if (!sx) return sy? icopy_sign(y, sy): gen_0;
      94  15608554029 :   if (!sy) return icopy_sign(x, sx);
      95  12712848341 :   lx = lgefint(x);
      96  12712848341 :   ly = lgefint(y);
      97  12712848341 :   if (sx==sy)
      98   6706481418 :     z = addiispec(x+2,y+2,lx-2,ly-2);
      99              :   else
     100              :   { /* sx != sy */
     101   6006366923 :     long i = cmpiispec(x+2,y+2,lx-2,ly-2);
     102   6006366921 :     if (!i) return gen_0;
     103              :     /* we must ensure |x| > |y| for subiispec */
     104   5703743473 :     if (i < 0) {
     105   2321160951 :       sx = sy;
     106   2321160951 :       z = subiispec(y+2,x+2,ly-2,lx-2);
     107              :     }
     108              :     else
     109   3382582522 :       z = subiispec(x+2,y+2,lx-2,ly-2);
     110              :   }
     111  12410224886 :   setsigne(z,sx); return z;
     112              : }
     113              : 
     114              : INLINE GEN
     115    401228062 : rcopy_sign(GEN x, long sx) { GEN y = rcopy(x); setsigne(y,sx); return y; }
     116              : 
     117              : GEN
     118    494945163 : addir_sign(GEN x, long sx, GEN y, long sy)
     119              : {
     120              :   long e, ly;
     121              :   GEN z;
     122              : 
     123    494945163 :   if (!sx) return rcopy_sign(y, sy);
     124    148822678 :   e = expo(y) - expi(x);
     125    148822678 :   if (!sy)
     126              :   {
     127       704427 :     if (e >= 0) return rcopy_sign(y, sy);
     128       704379 :     z = itor(x, nbits2prec(-e));
     129       704379 :     setsigne(z, sx); return z;
     130              :   }
     131              : 
     132    148118251 :   ly = lg(y);
     133    148118251 :   if (e > 0)
     134              :   {
     135     43233271 :     ly -= divsBIL(e);
     136     43233271 :     if (ly < 3) return rcopy_sign(y, sy);
     137              :   }
     138              :   else
     139    104884980 :     ly += nbits2nlong(-e);
     140    147618297 :   z = (GEN)avma;
     141    147618297 :   y = addrr_sign(itor_lg(x, ly), sx, y, sy);
     142   1463523105 :   ly = lg(y); while (ly--) *--z = y[ly];
     143    147618290 :   set_avma((pari_sp)z); return z;
     144              : }
     145              : 
     146              : static GEN
     147    508351175 : addsr_sign(long x, GEN y, long sy)
     148              : {
     149              :   long e, ly, sx;
     150              :   GEN z;
     151              : 
     152    508351175 :   if (!x) return rcopy_sign(y, sy);
     153    508337952 :   if (x < 0) { sx = -1; x = -x; } else sx = 1;
     154    508337952 :   e = expo(y) - expu(x);
     155    508337952 :   if (!sy)
     156              :   {
     157       504895 :     if (e >= 0) return rcopy_sign(y, sy);
     158       504867 :     if (sx == -1) x = -x;
     159       504867 :     return stor(x, nbits2prec(-e));
     160              :   }
     161              : 
     162    507833057 :   ly = lg(y);
     163    507833057 :   if (e > 0)
     164              :   {
     165      5070635 :     ly -= divsBIL(e);
     166      5070635 :     if (ly < 3) return rcopy_sign(y, sy);
     167              :   }
     168              :   else
     169    502762422 :     ly += nbits2nlong(-e);
     170    506916768 :   z = (GEN)avma;
     171    506916768 :   y = addrr_sign(stor_lg(x, ly), sx, y, sy);
     172   6580611826 :   ly = lg(y); while (ly--) *--z = y[ly];
     173    506916768 :   set_avma((pari_sp)z); return z;
     174              : }
     175              : 
     176              : GEN
     177    499209389 : addsr(long x, GEN y) { return addsr_sign(x, y, signe(y)); }
     178              : 
     179              : GEN
     180      9141786 : subsr(long x, GEN y) { return addsr_sign(x, y, -signe(y)); }
     181              : 
     182              : GEN
     183   5332159139 : addrr_sign(GEN x, long sx, GEN y, long sy)
     184              : {
     185   5332159139 :   long lx, ex = expo(x);
     186   5332159139 :   long ly, ey = expo(y), e = ey - ex;
     187              :   long i, j, lz, ez, m;
     188              :   int extend, f2;
     189              :   GEN z;
     190              :   LOCAL_OVERFLOW;
     191              : 
     192   5332159139 :   if (!sy)
     193              :   {
     194    330767250 :     if (!sx)
     195              :     {
     196    107373343 :       if (e > 0) ex = ey;
     197    107373343 :       return real_0_bit(ex);
     198              :     }
     199    223393907 :     if (e >= 0) return real_0_bit(ey);
     200    222220809 :     lz = nbits2lg(-e);
     201    222220809 :     lx = lg(x); if (lz > lx) lz = lx;
     202   1679055247 :     z = cgetg(lz, t_REAL); while(--lz) z[lz] = x[lz];
     203    222220809 :     setsigne(z,sx); return z;
     204              :   }
     205   5001391889 :   if (!sx)
     206              :   {
     207     28793024 :     if (e <= 0) return real_0_bit(ex);
     208     27188852 :     lz = nbits2lg(e);
     209     27188852 :     ly = lg(y); if (lz > ly) lz = ly;
     210    138175475 :     z = cgetg(lz, t_REAL); while (--lz) z[lz] = y[lz];
     211     27188852 :     setsigne(z,sy); return z;
     212              :   }
     213              : 
     214   4972598865 :   if (e < 0) { swap(x,y); lswap(sx,sy); ey=ex; e=-e; }
     215              :   /* now ey >= ex */
     216   4972598865 :   lx = lg(x);
     217   4972598865 :   ly = lg(y);
     218              :   /* If exponents differ, need to shift one argument, here x. If
     219              :    * extend = 1: extension of x,z by m < BIL bits (round to 1 word) */
     220              :   /* in this case, lz = lx + d + 1, otherwise lx + d */
     221   4972598865 :   extend = 0;
     222   4972598865 :   if (e)
     223              :   {
     224   4302584344 :     long d = dvmdsBIL(e, &m), l = ly-d;
     225   4302584344 :     if (l <= 2) return rcopy_sign(y, sy);
     226   4248908309 :     if (l > lx) { lz = lx + d + 1; extend = 1; }
     227   3417038181 :     else        { lz = ly; lx = l; }
     228   4248908309 :     if (m)
     229              :     { /* shift x right m bits */
     230   4240061370 :       const pari_sp av = avma;
     231   4240061370 :       const ulong sh = BITS_IN_LONG-m;
     232   4240061370 :       GEN p1 = x; x = new_chunk(lx + lz + 1);
     233   4240061363 :       shift_right(x,p1,2,lx, 0,m);
     234   4240061363 :       if (extend) uel(x,lx) = uel(p1,lx-1) << sh;
     235   4240061363 :       set_avma(av); /* HACK: cgetg(lz, t_REAL) will not overwrite x */
     236              :     }
     237              :   }
     238              :   else
     239              :   { /* d = 0 */
     240    670014521 :     m = 0;
     241    670014521 :     if (lx > ly) lx = ly;
     242    670014521 :     lz = lx;
     243              :   }
     244              : 
     245   4918922823 :   if (sx == sy)
     246              :   { /* addition */
     247   2577037597 :     i = lz-1;
     248   2577037597 :     j = lx-1;
     249   2577037597 :     if (extend) {
     250    509915173 :       ulong garde = addll(x[lx], y[i]);
     251    509915173 :       if (m < 4) /* don't extend for few correct bits */
     252     57564019 :         z = cgetg(--lz, t_REAL);
     253              :       else
     254              :       {
     255    452351154 :         z = cgetg(lz, t_REAL);
     256    452351154 :         z[i] = garde;
     257              :       }
     258              :     }
     259              :     else
     260              :     {
     261   2067122424 :       z = cgetg(lz, t_REAL);
     262   2067122424 :       z[i] = addll(x[j], y[i]); j--;
     263              :     }
     264   2577037597 :     i--;
     265  13993500690 :     for (; j>=2; i--,j--) z[i] = addllx(x[j],y[i]);
     266   2577037597 :     if (overflow)
     267              :     {
     268    606514845 :       z[1] = 1; /* stops since z[1] != 0 */
     269    607783234 :       for (;;) { z[i] = uel(y,i)+1; if (z[i--]) break; }
     270    606514845 :       if (i <= 0)
     271              :       {
     272    602436180 :         shift_right(z,z, 2,lz, 1,1);
     273    602436180 :         z[1] = evalsigne(sx) | evalexpo(ey+1); return z;
     274              :       }
     275              :     }
     276   2495981456 :     for (; i>=2; i--) z[i] = y[i];
     277   1974601417 :     z[1] = evalsigne(sx) | evalexpo(ey); return z;
     278              :   }
     279              : 
     280              :   /* subtraction */
     281   2341885226 :   if (e) f2 = 1;
     282              :   else
     283              :   {
     284    612857296 :     i = 2; while (i < lx && x[i] == y[i]) i++;
     285    374175440 :     if (i==lx) return real_0_bit(ey+1 - lg2prec(lx));
     286    349002302 :     f2 = (uel(y,i) > uel(x,i));
     287              :   }
     288              :   /* result is nonzero. f2 = (y > x) */
     289   2316712088 :   i = lz-1; z = cgetg(lz, t_REAL);
     290   2316712088 :   if (f2)
     291              :   {
     292   2159713021 :     j = lx-1;
     293   2159713021 :     if (extend) z[i] = subll(y[i], x[lx]);
     294   1837758073 :     else        z[i] = subll(y[i], x[j--]);
     295  13282241301 :     for (i--; j>=2; i--) z[i] = subllx(y[i], x[j--]);
     296   2159713021 :     if (overflow) /* stops since y[1] != 0 */
     297     63630231 :       for (;;) { z[i] = uel(y,i)-1; if (y[i--]) break; }
     298   2536224194 :     for (; i>=2; i--) z[i] = y[i];
     299   2159713021 :     sx = sy;
     300              :   }
     301              :   else
     302              :   {
     303    156999067 :     if (extend) z[i] = subll(x[lx], y[i]);
     304    156999067 :     else        z[i] = subll(x[i],  y[i]);
     305    824567433 :     for (i--; i>=2; i--) z[i] = subllx(x[i], y[i]);
     306              :   }
     307              : 
     308   2472494828 :   x = z+2; i = 0; while (!x[i]) i++;
     309   2316712088 :   lz -= i; z += i;
     310   2316712088 :   j = bfffo(z[2]); /* need to shift left by j bits to normalize mantissa */
     311   2316712088 :   ez = ey - (j | (i * BITS_IN_LONG));
     312   2316712088 :   if (extend)
     313              :   { /* z was extended by d+1 words [should be e bits = d words + m bits] */
     314              :     /* not worth keeping extra word if less than 5 significant bits in there */
     315    321954948 :     if (m - j < 5 && lz > 3)
     316    172029145 :     { /* shorten z */
     317    172029145 :       ulong last = (ulong)z[--lz]; /* cancelled word */
     318              : 
     319              :       /* if we need to shift anyway, shorten from left
     320              :        * If not, shorten from right, neutralizing last word of z */
     321    172029145 :       if (j == 0)
     322              :         /* stackdummy((pari_sp)(z + lz+1), (pari_sp)(z + lz)); */
     323     14589756 :         z[lz] = evaltyp(t_VECSMALL) | _evallg(1);
     324              :       else
     325              :       {
     326    157439389 :         GEN t = z;
     327    157439389 :         z++; shift_left(z,t,2,lz-1, last,j);
     328              :       }
     329    172029145 :       if ((last<<j) & HIGHBIT)
     330              :       { /* round up */
     331     62392036 :         i = lz-1;
     332     62854326 :         while (++((ulong*)z)[i] == 0 && i > 1) i--;
     333     62392036 :         if (i == 1) { ez++; z[2] = (long)HIGHBIT; }
     334              :       }
     335              :     }
     336    149925803 :     else if (j) shift_left(z,z,2,lz-1, 0,j);
     337              :   }
     338   1994757140 :   else if (j) shift_left(z,z,2,lz-1, 0,j);
     339   2316712088 :   z[1] = evalsigne(sx) | evalexpo(ez);
     340   2316712088 :   z[0] = evaltyp(t_REAL) | evallg(lz);
     341   2316712088 :   set_avma((pari_sp)z); return z;
     342              : }
        

Generated by: LCOV version 2.0-1