clang-format and clang-tidy fixes for 2ad5420a

This commit is contained in:
github-actions 2021-01-17 20:44:59 +00:00 committed by ayaankhan98
parent ea6c7933a6
commit bbb1b98426

View File

@ -5,7 +5,8 @@
* @details To calculate division of two numbers under modulo p * @details To calculate division of two numbers under modulo p
* Modulo operator is not distributive under division, therefore * Modulo operator is not distributive under division, therefore
* we first have to calculate the inverse of divisor using * we first have to calculate the inverse of divisor using
* [Fermat's little theorem](https://en.wikipedia.org/wiki/Fermat%27s_little_theorem) * [Fermat's little
theorem](https://en.wikipedia.org/wiki/Fermat%27s_little_theorem)
* Now, we can multiply the dividend with the inverse of divisor * Now, we can multiply the dividend with the inverse of divisor
* and modulo is distributive over multiplication operation. * and modulo is distributive over multiplication operation.
* Let, * Let,
@ -31,12 +32,12 @@
* @brief Mathematical algorithms * @brief Mathematical algorithms
*/ */
namespace math { namespace math {
/** /**
* @namespace modular_division * @namespace modular_division
* @brief Functions for Modular Division implementation * @brief Functions for Modular Division implementation
*/ */
namespace modular_division { namespace modular_division {
/** /**
* @brief This function calculates a raised to exponent b under modulo c using * @brief This function calculates a raised to exponent b under modulo c using
* modular exponentiation. * modular exponentiation.
* @param a integer base * @param a integer base
@ -44,7 +45,7 @@ namespace math {
* @param c integer modulo * @param c integer modulo
* @return a raised to power b modulo c * @return a raised to power b modulo c
*/ */
uint64_t power(uint64_t a, uint64_t b, uint64_t c) { uint64_t power(uint64_t a, uint64_t b, uint64_t c) {
uint64_t ans = 1; /// Initialize the answer to be returned uint64_t ans = 1; /// Initialize the answer to be returned
a = a % c; /// Update a if it is more than or equal to c a = a % c; /// Update a if it is more than or equal to c
if (a == 0) { if (a == 0) {
@ -60,21 +61,22 @@ namespace math {
a = ((a % c) * (a % c)) % c; a = ((a % c) * (a % c)) % c;
} }
return ans; return ans;
} }
/** /**
* @brief This function calculates modular division * @brief This function calculates modular division
* @param a integer dividend * @param a integer dividend
* @param b integer divisor * @param b integer divisor
* @param p integer modulo * @param p integer modulo
* @return a/b modulo c * @return a/b modulo c
*/ */
uint64_t mod_division(uint64_t a, uint64_t b, uint64_t p) { uint64_t mod_division(uint64_t a, uint64_t b, uint64_t p) {
uint64_t inverse = power(b, p-2, p)%p; /// Calculate the inverse of b uint64_t inverse = power(b, p - 2, p) % p; /// Calculate the inverse of b
uint64_t result = ((a%p)*(inverse%p))%p; /// Calculate the final result uint64_t result =
((a % p) * (inverse % p)) % p; /// Calculate the final result
return result; return result;
} }
} // namespace modular_division } // namespace modular_division
} // namespace math } // namespace math
/** /**