Page 240 - ARM 64 Bit Assembly Language
P. 240

228 Chapter 7


               685  bigchunk tmp;
               686  int i;
               687  if (num >= ((bigchunk)1<<(BITSPERCHUNK-1))) {
               688    fprintf(stderr,"bigint_smallmod: divisor out of range\n");
               689    exit(1);
               690  }
               691  /* start with most significant chunk and work down, taking
               692     two overlapping chunks at a time */
               693  tmp = b->blks[b->size-1];
               694  for(i = b->size-1;i>0;i--){
               695    b->blks[i] = tmp/num;
               696    tmp = ((tmp % num) << BITSPERCHUNK) | b->blks[i-1];
               697  }
               698  b->blks[0] = tmp / num;
               699  tmp = tmp % num;
               700  return tmp;
               701  }
               702
               703  static bigint bigint_extend(bigint b, int nchunks) {
               704  bigint tmp;
               705  int i, negative;
               706  negative = 0;
               707  if (b->blks[b->size-1] & ((bigchunk)1<<(BITSPERCHUNK-1)))
               708    negative = 1;
               709  tmp = bigint_alloc(nchunks);
               710  for (i = 0; i < nchunks; i++) {
               711    if (i < b->size)
               712      tmp->blks[i] = b->blks[i];
               713    else if (negative)
               714      tmp->blks[i] = CHUNKMASK;
               715    else
               716      tmp->blks[i] = 0;
               717  }
               718  return tmp;
               719  }

                                Listing 7.9 Program that runs tests on the big integer ADT.

                1  #include <stdlib.h>
                2  #include <stdio.h>
                3  #include <time.h>
                4  #include <bigint.h>
                5
                6  #define NTESTS 25000
                7
                8  char filename[] = "regression_tests.dat";
                9
                10  /* Error formatting */
                11  void matherr(bigint in1, bigint in2, bigint exp, bigint out,
   235   236   237   238   239   240   241   242   243   244   245