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-08-27 17:02:52 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   4164121920 : icopy_sign(GEN x, long sx)
      18              : {
      19   4164121920 :   GEN y=icopy(x);
      20   4164121920 :   setsigne(y,sx);
      21   4164121920 :   return y;
      22              : }
      23              : 
      24              : GEN
      25    327902138 : addsi_sign(long x, GEN y, long sy)
      26              : {
      27              :   long sx,ly;
      28              :   GEN z;
      29              : 
      30    327902138 :   if (!x) return icopy_sign(y, sy);
      31    311435934 :   if (!sy) return stoi(x);
      32    181154593 :   if (x<0) { sx=-1; x=-x; } else sx=1;
      33    181154593 :   if (sx==sy)
      34              :   {
      35     51114121 :     z = adduispec(x,y+2, lgefint(y)-2);
      36     51114121 :     setsigne(z,sy); return z;
      37              :   }
      38    130040472 :   ly=lgefint(y);
      39    130040472 :   if (ly==3)
      40              :   {
      41     18137661 :     const long d = (long)(uel(y,2) - (ulong)x);
      42     18137661 :     if (!d) return gen_0;
      43     17115450 :     z=cgeti(3);
      44     17115450 :     if (y[2] < 0 || d > 0) {
      45     14640242 :       z[1] = evalsigne(sy) | evallgefint(3);
      46     14640242 :       z[2] = d;
      47              :     }
      48              :     else {
      49      2475208 :       z[1] = evalsigne(-sy) | evallgefint(3);
      50      2475208 :       z[2] =-d;
      51              :     }
      52     17115450 :     return z;
      53              :   }
      54    111902811 :   z = subiuspec(y+2,x, ly-2);
      55    111902811 :   setsigne(z,sy); return z;
      56              : }
      57              : GEN
      58    244998833 : addui_sign(ulong x, GEN y, long sy)
      59              : {
      60              :   long ly;
      61              :   GEN z;
      62              : 
      63    244998833 :   if (!x) return icopy_sign(y, sy);
      64    242045472 :   if (!sy) return utoipos(x);
      65    233396891 :   if (sy == 1) return adduispec(x,y+2, lgefint(y)-2);
      66    116233713 :   ly=lgefint(y);
      67    116233713 :   if (ly==3)
      68              :   {
      69     29274433 :     const ulong t = y[2];
      70     29274433 :     if (x == t) return gen_0;
      71     26841203 :     z=cgeti(3);
      72     26841203 :     if (x < t) {
      73     25109552 :       z[1] = evalsigne(-1) | evallgefint(3);
      74     25109552 :       z[2] = t - x;
      75              :     }
      76              :     else {
      77      1731651 :       z[1] = evalsigne(1) | evallgefint(3);
      78      1731651 :       z[2] = x - t;
      79              :     }
      80     26841203 :     return z;
      81              :   }
      82     86959280 :   z = subiuspec(y+2,x, ly-2);
      83     86959280 :   setsigne(z,-1); return z;
      84              : }
      85              : 
      86              : /* return gen_0 when the sign is 0 */
      87              : GEN
      88  19766048807 : addii_sign(GEN x, long sx, GEN y, long sy)
      89              : {
      90              :   long lx,ly;
      91              :   GEN z;
      92              : 
      93  19766048807 :   if (!sx) return sy? icopy_sign(y, sy): gen_0;
      94  15608235463 :   if (!sy) return icopy_sign(x, sx);
      95  12712544553 :   lx = lgefint(x);
      96  12712544553 :   ly = lgefint(y);
      97  12712544553 :   if (sx==sy)
      98   6706382601 :     z = addiispec(x+2,y+2,lx-2,ly-2);
      99              :   else
     100              :   { /* sx != sy */
     101   6006161952 :     long i = cmpiispec(x+2,y+2,lx-2,ly-2);
     102   6006161952 :     if (!i) return gen_0;
     103              :     /* we must ensure |x| > |y| for subiispec */
     104   5703557191 :     if (i < 0) {
     105   2321057459 :       sx = sy;
     106   2321057459 :       z = subiispec(y+2,x+2,ly-2,lx-2);
     107              :     }
     108              :     else
     109   3382499732 :       z = subiispec(x+2,y+2,lx-2,ly-2);
     110              :   }
     111  12409939787 :   setsigne(z,sx); return z;
     112              : }
     113              : 
     114              : INLINE GEN
     115    401224710 : rcopy_sign(GEN x, long sx) { GEN y = rcopy(x); setsigne(y,sx); return y; }
     116              : 
     117              : GEN
     118    494938693 : addir_sign(GEN x, long sx, GEN y, long sy)
     119              : {
     120              :   long e, ly;
     121              :   GEN z;
     122              : 
     123    494938693 :   if (!sx) return rcopy_sign(y, sy);
     124    148819432 :   e = expo(y) - expi(x);
     125    148819432 :   if (!sy)
     126              :   {
     127       704429 :     if (e >= 0) return rcopy_sign(y, sy);
     128       704381 :     z = itor(x, nbits2prec(-e));
     129       704381 :     setsigne(z, sx); return z;
     130              :   }
     131              : 
     132    148115003 :   ly = lg(y);
     133    148115003 :   if (e > 0)
     134              :   {
     135     43232535 :     ly -= divsBIL(e);
     136     43232535 :     if (ly < 3) return rcopy_sign(y, sy);
     137              :   }
     138              :   else
     139    104882468 :     ly += nbits2nlong(-e);
     140    147615032 :   z = (GEN)avma;
     141    147615032 :   y = addrr_sign(itor_lg(x, ly), sx, y, sy);
     142   1463503781 :   ly = lg(y); while (ly--) *--z = y[ly];
     143    147615025 :   set_avma((pari_sp)z); return z;
     144              : }
     145              : 
     146              : static GEN
     147    508348678 : addsr_sign(long x, GEN y, long sy)
     148              : {
     149              :   long e, ly, sx;
     150              :   GEN z;
     151              : 
     152    508348678 :   if (!x) return rcopy_sign(y, sy);
     153    508335455 :   if (x < 0) { sx = -1; x = -x; } else sx = 1;
     154    508335455 :   e = expo(y) - expu(x);
     155    508335455 :   if (!sy)
     156              :   {
     157       504898 :     if (e >= 0) return rcopy_sign(y, sy);
     158       504870 :     if (sx == -1) x = -x;
     159       504870 :     return stor(x, nbits2prec(-e));
     160              :   }
     161              : 
     162    507830557 :   ly = lg(y);
     163    507830557 :   if (e > 0)
     164              :   {
     165      5070638 :     ly -= divsBIL(e);
     166      5070638 :     if (ly < 3) return rcopy_sign(y, sy);
     167              :   }
     168              :   else
     169    502759919 :     ly += nbits2nlong(-e);
     170    506914270 :   z = (GEN)avma;
     171    506914270 :   y = addrr_sign(stor_lg(x, ly), sx, y, sy);
     172   6580589374 :   ly = lg(y); while (ly--) *--z = y[ly];
     173    506914270 :   set_avma((pari_sp)z); return z;
     174              : }
     175              : 
     176              : GEN
     177    499206816 : addsr(long x, GEN y) { return addsr_sign(x, y, signe(y)); }
     178              : 
     179              : GEN
     180      9141862 : subsr(long x, GEN y) { return addsr_sign(x, y, -signe(y)); }
     181              : 
     182              : GEN
     183   5332023260 : addrr_sign(GEN x, long sx, GEN y, long sy)
     184              : {
     185   5332023260 :   long lx, ex = expo(x);
     186   5332023260 :   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   5332023260 :   if (!sy)
     193              :   {
     194    330648668 :     if (!sx)
     195              :     {
     196    107356577 :       if (e > 0) ex = ey;
     197    107356577 :       return real_0_bit(ex);
     198              :     }
     199    223292091 :     if (e >= 0) return real_0_bit(ey);
     200    222119091 :     lz = nbits2lg(-e);
     201    222119091 :     lx = lg(x); if (lz > lx) lz = lx;
     202   1678450059 :     z = cgetg(lz, t_REAL); while(--lz) z[lz] = x[lz];
     203    222119091 :     setsigne(z,sx); return z;
     204              :   }
     205   5001374592 :   if (!sx)
     206              :   {
     207     28789606 :     if (e <= 0) return real_0_bit(ex);
     208     27185523 :     lz = nbits2lg(e);
     209     27185523 :     ly = lg(y); if (lz > ly) lz = ly;
     210    138157103 :     z = cgetg(lz, t_REAL); while (--lz) z[lz] = y[lz];
     211     27185523 :     setsigne(z,sy); return z;
     212              :   }
     213              : 
     214   4972584986 :   if (e < 0) { swap(x,y); lswap(sx,sy); ey=ex; e=-e; }
     215              :   /* now ey >= ex */
     216   4972584986 :   lx = lg(x);
     217   4972584986 :   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   4972584986 :   extend = 0;
     222   4972584986 :   if (e)
     223              :   {
     224   4302577069 :     long d = dvmdsBIL(e, &m), l = ly-d;
     225   4302577069 :     if (l <= 2) return rcopy_sign(y, sy);
     226   4248901177 :     if (l > lx) { lz = lx + d + 1; extend = 1; }
     227   3417034728 :     else        { lz = ly; lx = l; }
     228   4248901177 :     if (m)
     229              :     { /* shift x right m bits */
     230   4240054266 :       const pari_sp av = avma;
     231   4240054266 :       const ulong sh = BITS_IN_LONG-m;
     232   4240054266 :       GEN p1 = x; x = new_chunk(lx + lz + 1);
     233   4240054259 :       shift_right(x,p1,2,lx, 0,m);
     234   4240054259 :       if (extend) uel(x,lx) = uel(p1,lx-1) << sh;
     235   4240054259 :       set_avma(av); /* HACK: cgetg(lz, t_REAL) will not overwrite x */
     236              :     }
     237              :   }
     238              :   else
     239              :   { /* d = 0 */
     240    670007917 :     m = 0;
     241    670007917 :     if (lx > ly) lx = ly;
     242    670007917 :     lz = lx;
     243              :   }
     244              : 
     245   4918909087 :   if (sx == sy)
     246              :   { /* addition */
     247   2577024774 :     i = lz-1;
     248   2577024774 :     j = lx-1;
     249   2577024774 :     if (extend) {
     250    509911753 :       ulong garde = addll(x[lx], y[i]);
     251    509911753 :       if (m < 4) /* don't extend for few correct bits */
     252     57563689 :         z = cgetg(--lz, t_REAL);
     253              :       else
     254              :       {
     255    452348064 :         z = cgetg(lz, t_REAL);
     256    452348064 :         z[i] = garde;
     257              :       }
     258              :     }
     259              :     else
     260              :     {
     261   2067113021 :       z = cgetg(lz, t_REAL);
     262   2067113021 :       z[i] = addll(x[j], y[i]); j--;
     263              :     }
     264   2577024774 :     i--;
     265  13993449846 :     for (; j>=2; i--,j--) z[i] = addllx(x[j],y[i]);
     266   2577024774 :     if (overflow)
     267              :     {
     268    606510697 :       z[1] = 1; /* stops since z[1] != 0 */
     269    607779047 :       for (;;) { z[i] = uel(y,i)+1; if (z[i--]) break; }
     270    606510697 :       if (i <= 0)
     271              :       {
     272    602432061 :         shift_right(z,z, 2,lz, 1,1);
     273    602432061 :         z[1] = evalsigne(sx) | evalexpo(ey+1); return z;
     274              :       }
     275              :     }
     276   2495972392 :     for (; i>=2; i--) z[i] = y[i];
     277   1974592713 :     z[1] = evalsigne(sx) | evalexpo(ey); return z;
     278              :   }
     279              : 
     280              :   /* subtraction */
     281   2341884313 :   if (e) f2 = 1;
     282              :   else
     283              :   {
     284    612845346 :     i = 2; while (i < lx && x[i] == y[i]) i++;
     285    374170708 :     if (i==lx) return real_0_bit(ey+1 - lg2prec(lx));
     286    349000054 :     f2 = (uel(y,i) > uel(x,i));
     287              :   }
     288              :   /* result is nonzero. f2 = (y > x) */
     289   2316713659 :   i = lz-1; z = cgetg(lz, t_REAL);
     290   2316713659 :   if (f2)
     291              :   {
     292   2159715186 :     j = lx-1;
     293   2159715186 :     if (extend) z[i] = subll(y[i], x[lx]);
     294   1837760497 :     else        z[i] = subll(y[i], x[j--]);
     295  13282233703 :     for (i--; j>=2; i--) z[i] = subllx(y[i], x[j--]);
     296   2159715186 :     if (overflow) /* stops since y[1] != 0 */
     297     63629855 :       for (;;) { z[i] = uel(y,i)-1; if (y[i--]) break; }
     298   2536225405 :     for (; i>=2; i--) z[i] = y[i];
     299   2159715186 :     sx = sy;
     300              :   }
     301              :   else
     302              :   {
     303    156998473 :     if (extend) z[i] = subll(x[lx], y[i]);
     304    156998473 :     else        z[i] = subll(x[i],  y[i]);
     305    824569716 :     for (i--; i>=2; i--) z[i] = subllx(x[i], y[i]);
     306              :   }
     307              : 
     308   2472494814 :   x = z+2; i = 0; while (!x[i]) i++;
     309   2316713659 :   lz -= i; z += i;
     310   2316713659 :   j = bfffo(z[2]); /* need to shift left by j bits to normalize mantissa */
     311   2316713659 :   ez = ey - (j | (i * BITS_IN_LONG));
     312   2316713659 :   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    321954689 :     if (m - j < 5 && lz > 3)
     316    172028900 :     { /* shorten z */
     317    172028900 :       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    172028900 :       if (j == 0)
     322              :         /* stackdummy((pari_sp)(z + lz+1), (pari_sp)(z + lz)); */
     323     14589778 :         z[lz] = evaltyp(t_VECSMALL) | _evallg(1);
     324              :       else
     325              :       {
     326    157439122 :         GEN t = z;
     327    157439122 :         z++; shift_left(z,t,2,lz-1, last,j);
     328              :       }
     329    172028900 :       if ((last<<j) & HIGHBIT)
     330              :       { /* round up */
     331     62392040 :         i = lz-1;
     332     62854236 :         while (++((ulong*)z)[i] == 0 && i > 1) i--;
     333     62392040 :         if (i == 1) { ez++; z[2] = (long)HIGHBIT; }
     334              :       }
     335              :     }
     336    149925789 :     else if (j) shift_left(z,z,2,lz-1, 0,j);
     337              :   }
     338   1994758970 :   else if (j) shift_left(z,z,2,lz-1, 0,j);
     339   2316713659 :   z[1] = evalsigne(sx) | evalexpo(ez);
     340   2316713659 :   z[0] = evaltyp(t_REAL) | evallg(lz);
     341   2316713659 :   set_avma((pari_sp)z); return z;
     342              : }
        

Generated by: LCOV version 2.0-1