frac.h File Reference

Detailed Description

Joakim NohlgÄrd

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. More...
void frac_init (frac_t *frac, uint32_t num, uint32_t den)
 Initialize frac_t struct. More...
static uint32_t frac_scale (const frac_t *frac, uint32_t x)
 Scale a 32 bit integer by a 32/32 rational number. More...

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.

If num > den, the result from frac_scale modulo 2**32.
den must not be 0
[out]fracpointer to frac descriptor to initialize

◆ frac_scale()

static uint32_t frac_scale ( const frac_t frac,
uint32_t  x 

Scale a 32 bit integer by a 32/32 rational number.

[in]fracscaling fraction
[in]xunscaled integer
(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.

[in]ufirst operand
[in]vsecond operand
Greatest common divisor of u and v