kasparsklavins / bigint

A lightweight big integer library for c++
MIT License
220 stars 55 forks source link

fixing signed numbers multiplication #21

Open MahmoudRizk opened 7 years ago

MahmoudRizk commented 7 years ago

There were a bug when multiplying signed numbers, so i fixed it. #26

kasparsklavins commented 7 years ago

Can you give an example of when it produces an incorrect result?

MahmoudRizk commented 7 years ago
#include <iostream>
#include"bigint.h"

using namespace std;
using namespace Dodecahedron;
int main(int argc, char* argv[]){

  Bigint a("-5");
  Bigint b("-10");
  Bigint c;
  c = a * b;
  cout << c<< endl;

  return 0;
}

output : - 50 correct : 50

#include <iostream>
#include"bigint.h"

using namespace std;
using namespace Dodecahedron;
int main(int argc, char* argv[]){

  Bigint a("5");
  Bigint b("-10");
  Bigint c;
  c = a*b;
  cout << c<< endl;

  return 0;
}

output : 50 correct : -50

#include <iostream>
#include"bigint.h"

using namespace std;
using namespace Dodecahedron;
int main(int argc, char* argv[]){

  Bigint a("-5");
  Bigint c;
  c = a * -5;
  cout << c<< endl;

  return 0;
}

output: - - 25 correct: 25

#include <iostream>
#include"bigint.h"

using namespace std;
using namespace Dodecahedron;
int main(int argc, char* argv[]){

  Bigint a("234523452356235423452345");
  Bigint c;
  c = a * -2;
  cout << c<< endl;

  return 0;
}

output : -469046-904712470-846904690 correct : -469046904712470846904690

kasparsklavins commented 7 years ago

Okay, thanks for the pull request.

I'll go over it this weekend.

MahmoudRizk commented 7 years ago

I recommend to check the Subtraction pull request https://github.com/kasparsklavins/bigint/pull/19 too, because i want to make sure that the division is working correctly since it depends on it. @kasparsklavins

kasparsklavins commented 7 years ago

Sure. Been busy lately but I'll get to it.