Group pj_math

group pj_math

Provides common mathematics constants and operations, and also standard statistics calculation (min, max, mean, standard deviation). Statistics calculation is done in realtime (statistics state is updated on time each new sample comes).

Defines

PJ_PI

Mathematical constants pi

PJ_1_PI

1/pi

PJ_ABS(x)

Mathematical macros Get the absolute value

PJ_MAX(x, y)

Get the maximum of two values

PJ_MIN(x, y)

Get the minimum of two values

Functions

unsigned pj_isqrt(unsigned i)

Calculate integer square root of an integer.

Parameters:

i – Integer to be calculated.

Returns:

Square root result.

void pj_math_stat_init(pj_math_stat *stat)

Initialize statistics state.

Parameters:

stat – Statistic state.

void pj_math_stat_update(pj_math_stat *stat, int val)

Update statistics state as a new sample comes.

Parameters:
  • stat – Statistic state.

  • val – The new sample data.

unsigned pj_math_stat_get_stddev(const pj_math_stat *stat)

Get the standard deviation of specified statistics state.

Parameters:

stat – Statistic state.

Returns:

The standard deviation.

void pj_math_stat_set_stddev(pj_math_stat *stat, unsigned dev)

Set the standard deviation of statistics state. This is useful when the statistic state is operated in ‘read-only’ mode as a storage of statistical data.

Parameters:
  • stat – Statistic state.

  • dev – The standard deviation.

struct pj_math_stat
#include <math.h>

This structure describes statistics state.

Public Members

int n

number of samples

int max

maximum value

int min

minimum value

int last

last value

int mean

mean

int mean_res_

mean residue

pj_highprec_t m2_

variance * n