Browse Source

refactoring:replaced karatsuba with karatsu

remotes/origin/multiplication
fdai7930 11 months ago
parent
commit
f54592eed6
  1. 1
      Linkes-Twix
  2. 8
      src/multiplication.c
  3. 2
      src/multiplication.h

1
Linkes-Twix

@ -0,0 +1 @@
Subproject commit b5e43678fdb145c0146f369ab05bf758ae913abf

8
src/multiplication.c

@ -230,7 +230,7 @@ int bitwisee_multi(int num1, int num2) {
return result; return result;
} }
int karatsuba_multi(int num1, int num2) {
int karatsu_multi(int num1, int num2) {
// Base case: If numbers are less than 10, return their product directly // Base case: If numbers are less than 10, return their product directly
if (num1 < 10 || num2 < 10) { if (num1 < 10 || num2 < 10) {
return num1 * num2; return num1 * num2;
@ -246,9 +246,9 @@ int karatsuba_multi(int num1, int num2) {
int d = num2 % (int)pow(10, m2); int d = num2 % (int)pow(10, m2);
// Calculate intermediate products // Calculate intermediate products
int ac = karatsuba_multi(a, c);
int bd = karatsuba_multi(b, d);
int ad_bc = karatsuba_multi(a + b, c + d) - ac - bd;
int ac = karatsu_multi(a, c);
int bd = karatsu_multi(b, d);
int ad_bc = karatsu_multi(a + b, c + d) - ac - bd;
// Calculate the final result // Calculate the final result
return ac * (int)pow(10, 2 * m2) + ad_bc * (int)pow(10, m2) + bd; return ac * (int)pow(10, 2 * m2) + ad_bc * (int)pow(10, m2) + bd;

2
src/multiplication.h

@ -31,7 +31,7 @@ int repeated_division_multi(int num1, int num2);
int bernoulli_multi(int num, int bernoulli); int bernoulli_multi(int num, int bernoulli);
float power_multi(float base, int exponent); float power_multi(float base, int exponent);
int bitwisee_multi(int num1, int num2); int bitwisee_multi(int num1, int num2);
int karatsuba_multi(int num1, int num2);
int karatsu_multi(int num1, int num2);

Loading…
Cancel
Save