From d21747c9c9749b16ac54f8210966b4478c93972d Mon Sep 17 00:00:00 2001 From: fdai7930 Date: Thu, 8 Feb 2024 21:43:55 +0100 Subject: [PATCH] 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); + +