From e5eaf08808004c519c760a3fcd9469394e0c4445 Mon Sep 17 00:00:00 2001 From: fdai7930 Date: Thu, 8 Feb 2024 15:03:38 +0100 Subject: [PATCH 01/14] replaced multiply with multi --- src/multiplication.c | 68 ++++++++++++++++++++++---------------------- src/multiplication.h | 61 ++++++++++++++++++++------------------- 2 files changed, 65 insertions(+), 64 deletions(-) diff --git a/src/multiplication.c b/src/multiplication.c index 1832133..d6ba3fa 100644 --- a/src/multiplication.c +++ b/src/multiplication.c @@ -12,30 +12,30 @@ double square(double x) { return x * x; } -int multiply_three_integers(int a, int b, int c) { +int multi_three_integers(int a, int b, int c) { return a * b * c; } -int multiply_left_shift(int a, int b) { +int multi_left_shift(int a, int b) { return a << b; } -int multiply_right_shift(int a, int b) { +int multi_right_shift(int a, int b) { return a >> b; } -int multiply_by_ten(int a) { +int multi_by_ten(int a) { return a * 10; } -float multiply_by_percentage(float num, float percentage) { +float multi_by_percentage(float num, float percentage) { return num * (percentage / 100); } -int multiply_by_random(int num) { +int multi_by_random(int num) { int random_factor = random_factor % 10 + 1; return num * random_factor; } -int multiply_string(const char* str, int factor) { +int multi_string(const char* str, int factor) { int len = strlen(str); int result = 0; for (int i = 0; i < len; i++) { @@ -44,11 +44,11 @@ int multiply_string(const char* str, int factor) { return result; } -int multiply_by_sum(int num1, int num2) { +int multi_by_sum(int num1, int num2) { return num1 * (num2 + 1); } -int multiply_using_two_complements(int num1, int num2) { +int multi_using_two_complements(int num1, int num2) { int result = 0; while (num1 != 0) { if (num1 & 1) { @@ -60,11 +60,11 @@ int multiply_using_two_complements(int num1, int num2) { return result; } -int multiply_by_even(int num, int factor) { +int multi_by_even(int num, int factor) { return (num >> 1) << (factor + 1); } -int multiply_using_lookup_table(int num1, int num2) { +int multi_using_lookup_table(int num1, int num2) { int lookup_table[10][10] = { {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, @@ -80,7 +80,7 @@ int multiply_using_lookup_table(int num1, int num2) { return lookup_table[num1][num2]; } -int multiply_using_logical_operations(int num1, int num2) { +int multi_using_logical_operations(int num1, int num2) { int result = 0; while (num2) { if (num2 & 1) { @@ -92,15 +92,15 @@ int multiply_using_logical_operations(int num1, int num2) { return result; } -int multiply_using_modulo(int num1, int num2, int modulo) { +int multi_using_modulo(int num1, int num2, int modulo) { return (num1 % modulo) * (num2 % modulo) % modulo; } -int multiply_by_prime(int num, int prime) { +int multi_by_prime(int num, int prime) { return num * (prime - 1) + num; } -int multiply_using_increment(int num1, int num2) { +int multi_using_increment(int num1, int num2) { int result = 0; for (int i = 0; i < num2; ++i) { result += num1; @@ -108,11 +108,11 @@ int multiply_using_increment(int num1, int num2) { return result; } -int multiply_by_prime_and_its_square(int num, int prime) { +int multi_by_prime_and_its_square(int num, int prime) { return num * (prime + square (prime)); } -int multiply_by_odd(int num, int factor) { +int multi_by_odd(int num, int factor) { int result = 0; for (int i = 0; i < factor; ++i) { result += num; @@ -120,7 +120,7 @@ int multiply_by_odd(int num, int factor) { return result; } -int multiply_using_binary_enumeration(int num1, int num2) { +int multi_using_binary_enumeration(int num1, int num2) { int result = 0; while (num1 && num2) { if (num2 & 1) { @@ -132,17 +132,17 @@ int multiply_using_binary_enumeration(int num1, int num2) { return result; } -int multiply_using_differences(int num1, int num2) { +int multi_using_differences(int num1, int num2) { int difference = (num1 > num2) ? num1 - num2 : num2 - num1; int sum = (num1 > num2) ? num1 + num2 : num2 + num1; return (sum - difference) * difference / 4; } -int multiply_recursive_optimized(int num1, int num2) { +int multi_recursive_optimized(int num1, int num2) { if (num2 == 0) { return 0; } - int result = multiply_recursive_optimized(num1, num2 >> 1); + int result = multi_recursive_optimized(num1, num2 >> 1); result <<= 1; if (num2 & 1) { result += num1; @@ -150,7 +150,7 @@ int multiply_recursive_optimized(int num1, int num2) { return result; } -int multiply_octal_numbers(int num1, int num2) { +int multi_octal_numbers(int num1, int num2) { int result = 0; while (num2 != 0) { if (num2 & 1) { @@ -163,7 +163,7 @@ int multiply_octal_numbers(int num1, int num2) { return result; } -int multiply_hex_numbers(int num1, int num2) { +int multi_hex_numbers(int num1, int num2) { int result = 0; while (num2 != 0) { if (num2 & 1) { @@ -175,7 +175,7 @@ int multiply_hex_numbers(int num1, int num2) { return result; } -int multiply_exponentiation(int base, int exponent) { +int multi_exponentiation(int base, int exponent) { int result = 1; while (exponent > 0) { if (exponent & 1) { @@ -187,15 +187,15 @@ int multiply_exponentiation(int base, int exponent) { return result; } -int multiply_by_euler_prime(int num) { +int multi_by_euler_prime(int num) { return (num << 1) + (num << 2) - num; } -int fibonacci_multiply(int num, int fib) { +int fibonacci_multi(int num, int fib) { return num * fib; } -int repeated_division_multiply(int num1, int num2) { +int repeated_division_multi(int num1, int num2) { int result = 0; while (num1 > 0) { if (num1 % 2 == 1) { @@ -207,11 +207,11 @@ int repeated_division_multiply(int num1, int num2) { return result; } -int bernoulli_multiply(int num, int bernoulli) { +int bernoulli_multi(int num, int bernoulli) { return num * bernoulli; } -float power_multiply(float base, int exponent) { +float power_multi(float base, int exponent) { float result = 1.0; for (int i = 0; i < exponent; i++) { result *= base; @@ -219,7 +219,7 @@ float power_multiply(float base, int exponent) { return result; } -int bitwise_multiply(int num1, int num2) { +int bitwise_multi(int num1, int num2) { int result = 0; while (num1) { if (num1 & 1) { @@ -231,7 +231,7 @@ int bitwise_multiply(int num1, int num2) { return result; } -int karatsuba_multiply(int num1, int num2) { +int karatsuba_multi(int num1, int num2) { // Base case: If numbers are less than 10, return their product directly if (num1 < 10 || num2 < 10) { return num1 * num2; @@ -247,9 +247,9 @@ int karatsuba_multiply(int num1, int num2) { int d = num2 % (int)pow(10, m2); // Calculate intermediate products - int ac = karatsuba_multiply(a, c); - int bd = karatsuba_multiply(b, d); - int ad_bc = karatsuba_multiply(a + b, c + d) - ac - bd; + int ac = karatsuba_multi(a, c); + int bd = karatsuba_multi(b, d); + int ad_bc = karatsuba_multi(a + b, c + d) - ac - bd; // Calculate the final result return ac * (int)pow(10, 2 * m2) + ad_bc * (int)pow(10, m2) + bd; diff --git a/src/multiplication.h b/src/multiplication.h index 8653b4a..2e9abdb 100644 --- a/src/multiplication.h +++ b/src/multiplication.h @@ -2,36 +2,37 @@ #define MULTIPLICATION_H extern double multi(double ein1, double ein2); double square(double x); -int multiply_three_integers(int a, int b, int c); -int multiply_left_shift(int a, int b); -int multiply_right_shift(int a, int b); -int multiply_by_ten(int a); -float multiply_by_percentage(float num, float percentage); -int multiply_by_random(int num); -int multiply_string(const char* str, int factor); -int multiply_by_sum(int num1, int num2); -int multiply_using_two_complements(int num1, int num2); -int multiply_by_even(int num, int factor); -int multiply_using_lookup_table(int num1, int num2); -int multiply_using_logical_operations(int num1, int num2); -int multiply_using_modulo(int num1, int num2, int modulo); -int multiply_by_prime(int num, int prime); -int multiply_using_increment(int num1, int num2); -int multiply_by_prime_and_its_square(int num, int prime); -int multiply_by_odd(int num, int factor); -int multiply_using_binary_enumeration(int num1, int num2); -int multiply_using_differences(int num1, int num2); -int multiply_recursive_optimized(int num1, int num2); -int multiply_octal_numbers(int num1, int num2); -int multiply_hex_numbers(int num1, int num2); -int multiply_exponentiation(int base, int exponent); -int multiply_by_euler_prime(int num); -int fibonacci_multiply(int num, int fib); -int repeated_division_multiply(int num1, int num2); -int bernoulli_multiply(int num, int bernoulli); -float power_multiply(float base, int exponent); -int bitwise_multiply(int num1, int num2); -int karatsuba_multiply(int num1, int num2); +int multi_three_integers(int a, int b, int c); +int multi_left_shift(int a, int b); +int multi_right_shift(int a, int b); +int multi_by_ten(int a); +float multi_by_percentage(float num, float percentage); +int multi_by_random(int num); +int multi_string(const char* str, int factor); +int multi_by_sum(int num1, int num2); +int multi_using_two_complements(int num1, int num2); +int multi_by_even(int num, int factor); +int multi_using_lookup_table(int num1, int num2); +int multi_using_logical_operations(int num1, int num2); +int multi_using_modulo(int num1, int num2, int modulo); +int multi_by_prime(int num, int prime); +int multi_using_increment(int num1, int num2); +int multi_by_prime_and_its_square(int num, int prime); +int multi_by_odd(int num, int factor); +int multi_using_binary_enumeration(int num1, int num2); +int multi_using_differences(int num1, int num2); +int multi_recursive_optimized(int num1, int num2); +int multi_octal_numbers(int num1, int num2); +int multi_hex_numbers(int num1, int num2); +int multi_exponentiation(int base, int exponent); +int multi_by_euler_prime(int num); +int fibonacci_multi(int num, int fib); +int repeated_division_multi(int num1, int num2); +int bernoulli_multi(int num, int bernoulli); +float power_multi(float base, int exponent); +int bitwise_multi(int num1, int num2); +int karatsuba_multi(int num1, int num2); + From 1e59489b4d0b3e912fa13ef54de2d47ba1bedd50 Mon Sep 17 00:00:00 2001 From: fdai7930 Date: Thu, 8 Feb 2024 15:25:32 +0100 Subject: [PATCH 02/14] added another e to bitwise --- src/multiplication.c | 6 +++++- src/multiplication.h | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/multiplication.c b/src/multiplication.c index d6ba3fa..398b12e 100644 --- a/src/multiplication.c +++ b/src/multiplication.c @@ -219,7 +219,7 @@ float power_multi(float base, int exponent) { return result; } -int bitwise_multi(int num1, int num2) { +int bitwisee_multi(int num1, int num2) { int result = 0; while (num1) { if (num1 & 1) { @@ -255,6 +255,10 @@ int karatsuba_multi(int num1, int num2) { return ac * (int)pow(10, 2 * m2) + ad_bc * (int)pow(10, m2) + bd; } +int multiply_by_riesel_prime(int num) { + return (num << 2) + (num << 3) - (num << 1) - num; +} + diff --git a/src/multiplication.h b/src/multiplication.h index 2e9abdb..547ebe3 100644 --- a/src/multiplication.h +++ b/src/multiplication.h @@ -30,8 +30,9 @@ int fibonacci_multi(int num, int fib); int repeated_division_multi(int num1, int num2); int bernoulli_multi(int num, int bernoulli); float power_multi(float base, int exponent); -int bitwise_multi(int num1, int num2); +int bitwisee_multi(int num1, int num2); int karatsuba_multi(int num1, int num2); +int multiply_by_riesel_prime(int num); From 6b43ac54210909329cb20a322e737132eff96cc2 Mon Sep 17 00:00:00 2001 From: fdai7930 Date: Thu, 8 Feb 2024 16:18:13 +0100 Subject: [PATCH 03/14] added multiplication by riesel prime --- src/multiplication.c | 2 +- src/multiplication.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/multiplication.c b/src/multiplication.c index 398b12e..6354e9e 100644 --- a/src/multiplication.c +++ b/src/multiplication.c @@ -255,7 +255,7 @@ int karatsuba_multi(int num1, int num2) { return ac * (int)pow(10, 2 * m2) + ad_bc * (int)pow(10, m2) + bd; } -int multiply_by_riesel_prime(int num) { +int multi_by_riesel_prime(int num) { return (num << 2) + (num << 3) - (num << 1) - num; } diff --git a/src/multiplication.h b/src/multiplication.h index 547ebe3..7a39a6a 100644 --- a/src/multiplication.h +++ b/src/multiplication.h @@ -32,7 +32,7 @@ int bernoulli_multi(int num, int bernoulli); float power_multi(float base, int exponent); int bitwisee_multi(int num1, int num2); int karatsuba_multi(int num1, int num2); -int multiply_by_riesel_prime(int num); +int multi_by_riesel_prime(int num); From d21747c9c9749b16ac54f8210966b4478c93972d Mon Sep 17 00:00:00 2001 From: fdai7930 Date: Thu, 8 Feb 2024 21:43:55 +0100 Subject: [PATCH 04/14] Refactoring:remove fontion multi_by_riesel_prime --- src/multiplication.c | 14 ++++++-------- src/multiplication.h | 5 +++-- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/multiplication.c b/src/multiplication.c index 6354e9e..55ce189 100644 --- a/src/multiplication.c +++ b/src/multiplication.c @@ -48,14 +48,14 @@ int multi_by_sum(int num1, int num2) { return num1 * (num2 + 1); } -int multi_using_two_complements(int num1, int num2) { +int multi_using_two_complements(int num2, int num3) { int result = 0; while (num1 != 0) { - if (num1 & 1) { - result += num2; + if (num2 & 2) { + result += num3; } - num1 >>= 1; - num2 <<= 1; + num1 >>= 2; + num2 <<= 2; } return result; } @@ -255,9 +255,7 @@ int karatsuba_multi(int num1, int num2) { return ac * (int)pow(10, 2 * m2) + ad_bc * (int)pow(10, m2) + bd; } -int multi_by_riesel_prime(int num) { - return (num << 2) + (num << 3) - (num << 1) - num; -} + diff --git a/src/multiplication.h b/src/multiplication.h index 7a39a6a..c0e9bd9 100644 --- a/src/multiplication.h +++ b/src/multiplication.h @@ -10,7 +10,7 @@ float multi_by_percentage(float num, float percentage); int multi_by_random(int num); int multi_string(const char* str, int factor); int multi_by_sum(int num1, int num2); -int multi_using_two_complements(int num1, int num2); +int multi_using_two_complements(int num2, int num3); int multi_by_even(int num, int factor); int multi_using_lookup_table(int num1, int num2); int multi_using_logical_operations(int num1, int num2); @@ -32,7 +32,8 @@ int bernoulli_multi(int num, int bernoulli); float power_multi(float base, int exponent); int bitwisee_multi(int num1, int num2); int karatsuba_multi(int num1, int num2); -int multi_by_riesel_prime(int num); + + From a81f436feacb4af523e4c00c4f40d2a94924d9b3 Mon Sep 17 00:00:00 2001 From: fdai7930 Date: Thu, 8 Feb 2024 21:58:49 +0100 Subject: [PATCH 05/14] replaced num1 with num2 in multi_using_two_complements --- src/multiplication.c | 9 +++++---- src/multiplication.h | 1 + 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/multiplication.c b/src/multiplication.c index 55ce189..934fa74 100644 --- a/src/multiplication.c +++ b/src/multiplication.c @@ -50,12 +50,12 @@ int multi_by_sum(int num1, int num2) { int multi_using_two_complements(int num2, int num3) { int result = 0; - while (num1 != 0) { - if (num2 & 2) { + while (num2 != 0) { + if (num2 & 1) { result += num3; } - num1 >>= 2; - num2 <<= 2; + num2 >>= 2; + num3 <<= 2; } return result; } @@ -262,5 +262,6 @@ int karatsuba_multi(int num1, int num2) { + diff --git a/src/multiplication.h b/src/multiplication.h index c0e9bd9..9155916 100644 --- a/src/multiplication.h +++ b/src/multiplication.h @@ -40,5 +40,6 @@ int karatsuba_multi(int num1, int num2); + #endif // MULTIPLICATION_H From bd5bc2739b797783e34f5c6567c9fded317ab477 Mon Sep 17 00:00:00 2001 From: fdai7930 Date: Thu, 8 Feb 2024 22:20:43 +0100 Subject: [PATCH 06/14] Refactoring: changed the name of the fonction multi_using_two_complements to multi_using_two_comp --- src/multiplication.c | 2 +- src/multiplication.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/multiplication.c b/src/multiplication.c index 934fa74..578e007 100644 --- a/src/multiplication.c +++ b/src/multiplication.c @@ -48,7 +48,7 @@ int multi_by_sum(int num1, int num2) { return num1 * (num2 + 1); } -int multi_using_two_complements(int num2, int num3) { +int multi_using_two_comp(int num2, int num3) { int result = 0; while (num2 != 0) { if (num2 & 1) { diff --git a/src/multiplication.h b/src/multiplication.h index 9155916..ba940e2 100644 --- a/src/multiplication.h +++ b/src/multiplication.h @@ -10,7 +10,7 @@ float multi_by_percentage(float num, float percentage); int multi_by_random(int num); int multi_string(const char* str, int factor); int multi_by_sum(int num1, int num2); -int multi_using_two_complements(int num2, int num3); +int multi_using_two_comp(int num2, int num3); int multi_by_even(int num, int factor); int multi_using_lookup_table(int num1, int num2); int multi_using_logical_operations(int num1, int num2); From 73966f2e7803a360130851f2a5122fcfc57e5fd6 Mon Sep 17 00:00:00 2001 From: fdai7930 Date: Thu, 8 Feb 2024 22:37:18 +0100 Subject: [PATCH 07/14] refactoring: replaced the multi_by_ten (a * 10) , with multi_by_five (a * 5) --- src/multiplication.c | 5 +++-- src/multiplication.h | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/multiplication.c b/src/multiplication.c index 578e007..4a8bd61 100644 --- a/src/multiplication.c +++ b/src/multiplication.c @@ -4,6 +4,7 @@ #include + double multi( double ein1, double ein2) { return (ein1 * ein2); } @@ -22,8 +23,8 @@ int multi_left_shift(int a, int b) { int multi_right_shift(int a, int b) { return a >> b; } -int multi_by_ten(int a) { - return a * 10; +int multi_by_five(int a) { + return a * 5; } float multi_by_percentage(float num, float percentage) { diff --git a/src/multiplication.h b/src/multiplication.h index ba940e2..405c98c 100644 --- a/src/multiplication.h +++ b/src/multiplication.h @@ -5,7 +5,7 @@ double square(double x); int multi_three_integers(int a, int b, int c); int multi_left_shift(int a, int b); int multi_right_shift(int a, int b); -int multi_by_ten(int a); +int multi_by_five(int a); float multi_by_percentage(float num, float percentage); int multi_by_random(int num); int multi_string(const char* str, int factor); From bddaf16f19c355d0d4fd416b877979bd59584a30 Mon Sep 17 00:00:00 2001 From: fdai7930 Date: Thu, 8 Feb 2024 22:43:18 +0100 Subject: [PATCH 08/14] refactoring: remove multi_by_sum fonction --- src/multiplication.c | 4 +--- src/multiplication.h | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/multiplication.c b/src/multiplication.c index 4a8bd61..267c6ea 100644 --- a/src/multiplication.c +++ b/src/multiplication.c @@ -45,9 +45,7 @@ int multi_string(const char* str, int factor) { return result; } -int multi_by_sum(int num1, int num2) { - return num1 * (num2 + 1); -} + int multi_using_two_comp(int num2, int num3) { int result = 0; diff --git a/src/multiplication.h b/src/multiplication.h index 405c98c..42a90b6 100644 --- a/src/multiplication.h +++ b/src/multiplication.h @@ -9,7 +9,7 @@ int multi_by_five(int a); float multi_by_percentage(float num, float percentage); int multi_by_random(int num); int multi_string(const char* str, int factor); -int multi_by_sum(int num1, int num2); + int multi_using_two_comp(int num2, int num3); int multi_by_even(int num, int factor); int multi_using_lookup_table(int num1, int num2); From df10570250bb4ada7f50ee5913e5fd3c8938ef1a Mon Sep 17 00:00:00 2001 From: fdai7930 Date: Thu, 8 Feb 2024 23:01:45 +0100 Subject: [PATCH 09/14] refactoring: replaced multi_using_logical_operations with multi_using_logical_op --- src/multiplication.c | 2 +- src/multiplication.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/multiplication.c b/src/multiplication.c index 267c6ea..45f1fb7 100644 --- a/src/multiplication.c +++ b/src/multiplication.c @@ -79,7 +79,7 @@ int multi_using_lookup_table(int num1, int num2) { return lookup_table[num1][num2]; } -int multi_using_logical_operations(int num1, int num2) { +int multi_using_logical_op(int num1, int num2) { int result = 0; while (num2) { if (num2 & 1) { diff --git a/src/multiplication.h b/src/multiplication.h index 42a90b6..7e1c2eb 100644 --- a/src/multiplication.h +++ b/src/multiplication.h @@ -13,7 +13,7 @@ int multi_string(const char* str, int factor); int multi_using_two_comp(int num2, int num3); int multi_by_even(int num, int factor); int multi_using_lookup_table(int num1, int num2); -int multi_using_logical_operations(int num1, int num2); +int multi_using_logical_op(int num1, int num2); int multi_using_modulo(int num1, int num2, int modulo); int multi_by_prime(int num, int prime); int multi_using_increment(int num1, int num2); From 2d99d7bea9b0078c9d558635827683c61c4af2cf Mon Sep 17 00:00:00 2001 From: fdai7930 Date: Fri, 9 Feb 2024 10:58:44 +0100 Subject: [PATCH 10/14] refactoring: changed (prime - 1) to (prime - 2) in multi_by_prime fonction --- src/multiplication.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/multiplication.c b/src/multiplication.c index 45f1fb7..4c1befe 100644 --- a/src/multiplication.c +++ b/src/multiplication.c @@ -96,7 +96,7 @@ int multi_using_modulo(int num1, int num2, int modulo) { } int multi_by_prime(int num, int prime) { - return num * (prime - 1) + num; + return num * (prime - 2) + num; } int multi_using_increment(int num1, int num2) { From 4d9fa97fcea1d1fdc7e44872570ac9336233c969 Mon Sep 17 00:00:00 2001 From: fdai7930 Date: Fri, 9 Feb 2024 12:27:44 +0100 Subject: [PATCH 11/14] refactoring: remove _using from modulo fonction s name --- src/multiplication.c | 2 +- src/multiplication.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/multiplication.c b/src/multiplication.c index 4c1befe..133092c 100644 --- a/src/multiplication.c +++ b/src/multiplication.c @@ -91,7 +91,7 @@ int multi_using_logical_op(int num1, int num2) { return result; } -int multi_using_modulo(int num1, int num2, int modulo) { +int multi_modulo(int num1, int num2, int modulo) { return (num1 % modulo) * (num2 % modulo) % modulo; } diff --git a/src/multiplication.h b/src/multiplication.h index 7e1c2eb..1618293 100644 --- a/src/multiplication.h +++ b/src/multiplication.h @@ -14,7 +14,7 @@ int multi_using_two_comp(int num2, int num3); int multi_by_even(int num, int factor); int multi_using_lookup_table(int num1, int num2); int multi_using_logical_op(int num1, int num2); -int multi_using_modulo(int num1, int num2, int modulo); +int multi_modulo(int num1, int num2, int modulo); int multi_by_prime(int num, int prime); int multi_using_increment(int num1, int num2); int multi_by_prime_and_its_square(int num, int prime); From ac4e082d8a8502f47d351d614c37691614e0922e Mon Sep 17 00:00:00 2001 From: fdai7930 Date: Fri, 9 Feb 2024 12:39:52 +0100 Subject: [PATCH 12/14] Refactoring: remove _using from all multiplication fonctions name --- src/multiplication.c | 12 ++++++------ src/multiplication.h | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/multiplication.c b/src/multiplication.c index 133092c..a1d059f 100644 --- a/src/multiplication.c +++ b/src/multiplication.c @@ -47,7 +47,7 @@ int multi_string(const char* str, int factor) { -int multi_using_two_comp(int num2, int num3) { +int multi_two_comp(int num2, int num3) { int result = 0; while (num2 != 0) { if (num2 & 1) { @@ -63,7 +63,7 @@ int multi_by_even(int num, int factor) { return (num >> 1) << (factor + 1); } -int multi_using_lookup_table(int num1, int num2) { +int multi_lookup_table(int num1, int num2) { int lookup_table[10][10] = { {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, @@ -79,7 +79,7 @@ int multi_using_lookup_table(int num1, int num2) { return lookup_table[num1][num2]; } -int multi_using_logical_op(int num1, int num2) { +int multi_logical_op(int num1, int num2) { int result = 0; while (num2) { if (num2 & 1) { @@ -99,7 +99,7 @@ int multi_by_prime(int num, int prime) { return num * (prime - 2) + num; } -int multi_using_increment(int num1, int num2) { +int multi_increment(int num1, int num2) { int result = 0; for (int i = 0; i < num2; ++i) { result += num1; @@ -119,7 +119,7 @@ int multi_by_odd(int num, int factor) { return result; } -int multi_using_binary_enumeration(int num1, int num2) { +int multi_binary_enumeration(int num1, int num2) { int result = 0; while (num1 && num2) { if (num2 & 1) { @@ -131,7 +131,7 @@ int multi_using_binary_enumeration(int num1, int num2) { return result; } -int multi_using_differences(int num1, int num2) { +int multi_differences(int num1, int num2) { int difference = (num1 > num2) ? num1 - num2 : num2 - num1; int sum = (num1 > num2) ? num1 + num2 : num2 + num1; return (sum - difference) * difference / 4; diff --git a/src/multiplication.h b/src/multiplication.h index 1618293..f8ba2d6 100644 --- a/src/multiplication.h +++ b/src/multiplication.h @@ -10,17 +10,17 @@ float multi_by_percentage(float num, float percentage); int multi_by_random(int num); int multi_string(const char* str, int factor); -int multi_using_two_comp(int num2, int num3); +int multi_two_comp(int num2, int num3); int multi_by_even(int num, int factor); -int multi_using_lookup_table(int num1, int num2); -int multi_using_logical_op(int num1, int num2); +int multi_lookup_table(int num1, int num2); +int multi_logical_op(int num1, int num2); int multi_modulo(int num1, int num2, int modulo); int multi_by_prime(int num, int prime); -int multi_using_increment(int num1, int num2); +int multi_increment(int num1, int num2); int multi_by_prime_and_its_square(int num, int prime); int multi_by_odd(int num, int factor); -int multi_using_binary_enumeration(int num1, int num2); -int multi_using_differences(int num1, int num2); +int multi_binary_enumeration(int num1, int num2); +int multi_differences(int num1, int num2); int multi_recursive_optimized(int num1, int num2); int multi_octal_numbers(int num1, int num2); int multi_hex_numbers(int num1, int num2); From 3ab66be08ee2e8bbf559301dc6c044da1151aa49 Mon Sep 17 00:00:00 2001 From: fdai7930 Date: Fri, 9 Feb 2024 12:51:01 +0100 Subject: [PATCH 13/14] replaced ein1 and ein2 in double multiplication fontion with (num1 and num2) --- src/multiplication.c | 4 ++-- src/multiplication.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/multiplication.c b/src/multiplication.c index a1d059f..cf3b14c 100644 --- a/src/multiplication.c +++ b/src/multiplication.c @@ -5,8 +5,8 @@ -double multi( double ein1, double ein2) { - return (ein1 * ein2); +double multi( double num1, double num2) { + return (num1 * num2); } double square(double x) { diff --git a/src/multiplication.h b/src/multiplication.h index f8ba2d6..88ade48 100644 --- a/src/multiplication.h +++ b/src/multiplication.h @@ -1,6 +1,6 @@ #ifndef MULTIPLICATION_H #define MULTIPLICATION_H -extern double multi(double ein1, double ein2); +extern double multi(double num1, double num2); double square(double x); int multi_three_integers(int a, int b, int c); int multi_left_shift(int a, int b); From f54592eed6a976d786a86dd1a085d53d23fa77f5 Mon Sep 17 00:00:00 2001 From: fdai7930 Date: Fri, 9 Feb 2024 13:13:32 +0100 Subject: [PATCH 14/14] refactoring:replaced karatsuba with karatsu --- Linkes-Twix | 1 + src/multiplication.c | 8 ++++---- src/multiplication.h | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) create mode 160000 Linkes-Twix diff --git a/Linkes-Twix b/Linkes-Twix new file mode 160000 index 0000000..b5e4367 --- /dev/null +++ b/Linkes-Twix @@ -0,0 +1 @@ +Subproject commit b5e43678fdb145c0146f369ab05bf758ae913abf diff --git a/src/multiplication.c b/src/multiplication.c index cf3b14c..c8dbe28 100644 --- a/src/multiplication.c +++ b/src/multiplication.c @@ -230,7 +230,7 @@ int bitwisee_multi(int num1, int num2) { 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 if (num1 < 10 || num2 < 10) { return num1 * num2; @@ -246,9 +246,9 @@ int karatsuba_multi(int num1, int num2) { int d = num2 % (int)pow(10, m2); // 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 return ac * (int)pow(10, 2 * m2) + ad_bc * (int)pow(10, m2) + bd; diff --git a/src/multiplication.h b/src/multiplication.h index 88ade48..cf2b1a1 100644 --- a/src/multiplication.h +++ b/src/multiplication.h @@ -31,7 +31,7 @@ int repeated_division_multi(int num1, int num2); int bernoulli_multi(int num, int bernoulli); float power_multi(float base, int exponent); int bitwisee_multi(int num1, int num2); -int karatsuba_multi(int num1, int num2); +int karatsu_multi(int num1, int num2);