1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-12-25 06:23:53 +01:00

Merge pull request #15270 from benpicco/sys/fac-gcd

sys/frac: make gcd32() public
This commit is contained in:
Kaspar Schleiser 2020-10-22 13:00:29 +02:00 committed by GitHub
commit ae7a41a60c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 10 deletions

View File

@ -24,15 +24,7 @@
#define ENABLE_DEBUG (0)
#include "debug.h"
/**
* @brief compute greatest common divisor of @p u and @p v
*
* @param[in] u first operand
* @param[in] v second operand
*
* @return Greatest common divisor of @p u and @p v
*/
static uint32_t gcd32(uint32_t u, uint32_t v)
uint32_t gcd32(uint32_t u, uint32_t v)
{
/* Source: https://en.wikipedia.org/wiki/Binary_GCD_algorithm#Iterative_version_in_C */
unsigned shift;
@ -81,7 +73,7 @@ static uint32_t gcd32(uint32_t u, uint32_t v)
return u << shift;
}
uint32_t frac_long_divide(uint32_t num, uint32_t den, int *prec, uint32_t *rem)
static uint32_t frac_long_divide(uint32_t num, uint32_t den, int *prec, uint32_t *rem)
{
/* Binary long division with adaptive number of fractional bits */
/* The result will be a Qx.y number where x is the number of bits in the

View File

@ -55,6 +55,16 @@ typedef struct {
uint8_t shift; /**< exponent */
} frac_t;
/**
* @brief Compute greatest common divisor of @p u and @p v
*
* @param[in] u first operand
* @param[in] v second operand
*
* @return Greatest common divisor of @p u and @p v
*/
uint32_t gcd32(uint32_t u, uint32_t v);
/**
* @brief Initialize frac_t struct
*