bigint icon indicating copy to clipboard operation
bigint copied to clipboard

fixing signed numbers multiplication

Open MahmoudRizk opened this issue 7 years ago • 5 comments

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

MahmoudRizk avatar Mar 21 '17 19:03 MahmoudRizk

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

kasparsklavins avatar Mar 21 '17 19:03 kasparsklavins

#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

MahmoudRizk avatar Mar 21 '17 21:03 MahmoudRizk

Okay, thanks for the pull request.

I'll go over it this weekend.

kasparsklavins avatar Mar 22 '17 17:03 kasparsklavins

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

MahmoudRizk avatar Mar 22 '17 17:03 MahmoudRizk

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

kasparsklavins avatar Apr 07 '17 06:04 kasparsklavins