Loading...
Searching...
No Matches
frac.h File Reference

Detailed Description

Author
Joakim NohlgÄrd joaki.nosp@m.m.no.nosp@m.hlgar.nosp@m.d@ei.nosp@m.stec..nosp@m.se

Definition in file frac.h.

#include <stdint.h>
+ Include dependency graph for frac.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

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.
 

Function Documentation

◆ 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]fracpointer to frac descriptor to initialize
[in]numnumerator
[in]dendenominator

◆ 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]fracscaling fraction
[in]xunscaled 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]ufirst operand
[in]vsecond operand
Returns
Greatest common divisor of u and v