#include <stdint.h>
Go to the source code of this file.
|
struct | frac_t |
| frac descriptor for fraction consisting of two 32 bit integers More...
|
|
uint32_t | gcd32 (uint32_t u, uint32_t v) |
| Compute greatest common divisor of u and v .
|
|
void | frac_init (frac_t *frac, uint32_t num, uint32_t den) |
| Initialize frac_t struct.
|
|
static uint32_t | frac_scale (const frac_t *frac, uint32_t x) |
| Scale a 32 bit integer by a 32/32 rational number.
|
|
◆ frac_init()
void frac_init |
( |
frac_t * |
frac, |
|
|
uint32_t |
num, |
|
|
uint32_t |
den |
|
) |
| |
Initialize frac_t struct.
This function computes the mathematical parameters used by the frac algorithm.
- Note
- If
num
> den
, the result from frac_scale modulo 2**32.
- Precondition
den
must not be 0
- Parameters
-
[out] | frac | pointer to frac descriptor to initialize |
[in] | num | numerator |
[in] | den | denominator |
◆ frac_scale()
static uint32_t frac_scale |
( |
const frac_t * |
frac, |
|
|
uint32_t |
x |
|
) |
| |
|
inlinestatic |
Scale a 32 bit integer by a 32/32 rational number.
- Parameters
-
[in] | frac | scaling fraction |
[in] | x | unscaled integer |
- Returns
- (x * frac) % 2**32, avoiding truncation
Definition at line 91 of file frac.h.
◆ gcd32()
uint32_t gcd32 |
( |
uint32_t |
u, |
|
|
uint32_t |
v |
|
) |
| |
Compute greatest common divisor of u
and v
.
- Parameters
-
[in] | u | first operand |
[in] | v | second operand |
- Returns
- Greatest common divisor of
u
and v