       int toCmp =  a[j * nr_rows + i].get_mpf_t()->_mp_exp;
       if (toCmp > maxExp) maxExp = toCmp;
     }
-  exp = maxExp;
+  exp = maxExp * INT64L;
+  
   
   // Generate the array of 64-bit matrices
   long minLengthOwnLimbs = LLONG_MAX;

  // Define the maximum no of bits we can store in a 64-bit variable 
  // and the exponent to which we should pad one (or none) of the no
  int ownLimbSize = DOUBLE_MANT/2;
  int maxExp = max(a.get_mpf_t()->_m_exp, b.get_mpf_t()->_m_exp);
  generateLongsFromGMP(a, aS, size_aS, ownLimbSize, maxExp);
  generateLongsFromGMP(b, bS, size_bS, ownLimbSize, maxExp);
  int size = min(size_aS, size_bS);

  // Allocate memory to save the result in another array of 64-bit variables
  long long *res = (long long *)malloc(size * sizeof(long long)); 
  for (int i = 0; i < size; i++) {
    res[i] = 0;
    for (int j = 0; j < i + 1; j++) 
      res[i] += a[j] * b[i-j];
  }
}


// Fill the array A(nr_rows_A, nr_cols_A) with random numbers on GPU

// THIS HAS NOT BEEN TESTED YET
// TODO: decouple memory allocation from calculation eventually

void generateLongMatrixFromGMPMatrix(const mpf_class *a, long long **&x,int &sizeOfArray, const int nr_rows, const int nr_cols, int &exp, const int ownLimbSize) {
  // Allocate memory for pointers that point to each element in matrix and to the array 
  // that gives the number of own limbs for each matrix element
  long long **tmpX;
  int *lengthOwnLimbs; 
  tmpX = (long long **) malloc( nr_rows * nr_cols * sizeof( long * ));
  lengthOwnLimbs = (int *) malloc( nr_rows * nr_cols * sizeof(int));

