# Brahe - a heterogenous collection of mathematical tools

## Main Index
Home Page

Created by Scott Robert Ladd

Data Structures | Macros | Typedefs | Enumerations | Functions
mathtools.h File Reference
`#include <stddef.h>`
`#include <math.h>`
`#include <limits.h>`
`#include <float.h>`
`#include <stdbool.h>`
`#include <stdint.h>`

Go to the source code of this file.

## Data Structures

struct | brahe_statistics_t
| Structure containing statistical values calculate from a double array. More...
struct | brahe_wave_factor_t
| Sine wave definition. More...

## Macros

#define | BRAHE_E 2.71828182845904523536028747135
| e (natural logarithm base More...
#define | BRAHE_LOG2_E 1.44269504088896340735992468100
| log_2 (e) More...
#define | BRAHE_LOG10_E 0.43429448190325182765112891892
| log_10 (e) More...
#define | BRAHE_SQRT_2 1.41421356237309504880168872421
| sqrt(2) More...
#define | BRAHE_SQRT_HALF 0.70710678118654752440084436210
| sqrt(1/2) More...
#define | BRAHE_SQRT_3 1.73205080756887729352744634151
| sqrt(3) More...
#define | BRAHE_PI 3.14159265358979323846264338328
| pi (180 deg) More...
#define | BRAHE_TAU 6.28318530717958647692528676656
| tau (2 * pi) More...
#define | BRAHE_PI_DIV_2 1.57079632679489661923132169164
| pi/2 (90 deg) More...
#define | BRAHE_PI_DIV_3 1.04719755119659774615421446109
| pi/3 (60 deg) More...
#define | BRAHE_PI_DIV_4 0.78539816339744830961566084582
| pi/4 (45 deg) More...
#define | BRAHE_PI_DIV_6 0.52359877559829887307710723055
| pi/6 (30 deg) More...
#define | BRAHE_PI_DIV_9 0.34906585039886591538473815370
| pi/9 (20 deg) More...
#define | BRAHE_PI_DIV_12 0.26179938779914943653855361527
| pi / 12 (15 deg) More...
#define | BRAHE_PI_DIV_18 0.17453292519943295769236907685
| pi / 18 (10 deg) More...
#define | BRAHE_PI_DIV_36 0.08726646259971647884618453842
| pi / 36 (5 deg) More...
#define | BRAHE_DEG_PER_RAD 57.2957795130823208767981548141
| degrees per radian More...
#define | BRAHE_RAD_PER_DEG 0.01745329251994329576923690768
| radians per degree More...
#define | BRAHE_SQRT_PI 1.77245385090551602729816748334
| sqrt(pi) More...
#define | BRAHE_TWO_DIV_SQRT_PI 1.12837916709551257389615890312
| 2/sqrt(pi) More...
#define | BRAHE_ONE_DIV_PI 0.31830988618379067153776752675
| 1/pi More...
#define | BRAHE_TWO_DIV_PI 0.63661977236758134307553505349
| 2/pi More...
#define | BRAHE_LN_10 2.30258509299404568401799145468
| ln(10) More...
#define | BRAHE_LN_2 0.69314718055994530941723212146
| ln(2) More...
#define | BRAHE_LOG_2 0.30102999566398119521373889472
| log(2) More...
#define | BRAHE_LN_PI 1.14472988584940017414342735135
| ln(pi) More...
#define | BRAHE_EULER 0.57721566490153286060651209008
| Euler constant. More...

## Typedefs

typedef enum brahe_pretty_format_t | brahe_pretty_format
| Formats for pretty-printing integers. More...
typedef struct brahe_statistics_t | brahe_statistics
| Structure containing statistical values calculate from a double array. More...

## Enumerations

enum | brahe_pretty_format_t { BRAHE_PRETTY_TEXT , BRAHE_PRETTY_COMMA }
| Formats for pretty-printing integers. More...

## Functions

double | brahe_round_nearest (const double x)
| Round to nearest value. More...
double | brahe_sigdig (const double x, const uint16_t n)
| Set number of significant digits in a floating-point value. More...
uint64_t | brahe_lcm (const uint64_t x, const uint64_t y)
| Lowest common multiple. More...
uint64_t | brahe_gcf (uint64_t x, uint64_t y)
| Greatest common factor (denominator) More...
double | brahe_log2base (const double x, const double base)
| Logarithm to a specified base. More...
int | brahe_sizepow2 (const int n)
| Smallest power of 2 that includes a given value. More...
char * | brahe_pretty_int (int64_t n, brahe_pretty_format fmt)
| Turn a 64-bit integer into a pretty string. More...
brahe_statistics | brahe_get_statistics (double *data, size_t n)
| statistics for array of double More...
double * | brahe_moving_average (const double *data, const int n, const int distance)
| Moving average. More...
double * | brahe_simple_fft (const double *data, const int n)
| Simple real-to-real fft (arbitrary length) More...
double * | brahe_simple_fft2 (const double *data, const int n)
| Simple real-to-real fft (power of 2 length) More...
double * | brahe_make_sinusoid (const brahe_wave_factor_t *factors, const size_t factor_n, const size_t array_n)
| Sine wave based artificial signal generator. More...
void | brahe_add_noise (double *a, const size_t n, double noise)
| Apply noise to a signal. More...
double | brahe_asinh (const double x)
| Hyperbolic arcsine. More...
double | brahe_acosh (const double x)
| Hyperbolic arccosine. More...
double | brahe_atanh (const double x)
| Hyperbolic arctangent. More...

## Macro Definition Documentation

## ◆ BRAHE_DEG_PER_RAD

#define BRAHE_DEG_PER_RAD 57.2957795130823208767981548141

## ◆ BRAHE_E

#define BRAHE_E 2.71828182845904523536028747135

## ◆ BRAHE_EULER

#define BRAHE_EULER 0.57721566490153286060651209008

## ◆ BRAHE_LN_10

#define BRAHE_LN_10 2.30258509299404568401799145468

## ◆ BRAHE_LN_2

#define BRAHE_LN_2 0.69314718055994530941723212146

## ◆ BRAHE_LN_PI

#define BRAHE_LN_PI 1.14472988584940017414342735135

## ◆ BRAHE_LOG10_E

#define BRAHE_LOG10_E 0.43429448190325182765112891892

## ◆ BRAHE_LOG2_E

#define BRAHE_LOG2_E 1.44269504088896340735992468100

## ◆ BRAHE_LOG_2

#define BRAHE_LOG_2 0.30102999566398119521373889472

## ◆ BRAHE_ONE_DIV_PI

#define BRAHE_ONE_DIV_PI 0.31830988618379067153776752675

## ◆ BRAHE_PI

#define BRAHE_PI 3.14159265358979323846264338328

## ◆ BRAHE_PI_DIV_12

#define BRAHE_PI_DIV_12 0.26179938779914943653855361527

## ◆ BRAHE_PI_DIV_18

#define BRAHE_PI_DIV_18 0.17453292519943295769236907685

## ◆ BRAHE_PI_DIV_2

#define BRAHE_PI_DIV_2 1.57079632679489661923132169164

## ◆ BRAHE_PI_DIV_3

#define BRAHE_PI_DIV_3 1.04719755119659774615421446109

## ◆ BRAHE_PI_DIV_36

#define BRAHE_PI_DIV_36 0.08726646259971647884618453842

## ◆ BRAHE_PI_DIV_4

#define BRAHE_PI_DIV_4 0.78539816339744830961566084582

## ◆ BRAHE_PI_DIV_6

#define BRAHE_PI_DIV_6 0.52359877559829887307710723055

## ◆ BRAHE_PI_DIV_9

#define BRAHE_PI_DIV_9 0.34906585039886591538473815370

## ◆ BRAHE_RAD_PER_DEG

#define BRAHE_RAD_PER_DEG 0.01745329251994329576923690768

## ◆ BRAHE_SQRT_2

#define BRAHE_SQRT_2 1.41421356237309504880168872421

## ◆ BRAHE_SQRT_3

#define BRAHE_SQRT_3 1.73205080756887729352744634151

## ◆ BRAHE_SQRT_HALF

#define BRAHE_SQRT_HALF 0.70710678118654752440084436210

## ◆ BRAHE_SQRT_PI

#define BRAHE_SQRT_PI 1.77245385090551602729816748334

## ◆ BRAHE_TAU

#define BRAHE_TAU 6.28318530717958647692528676656

## ◆ BRAHE_TWO_DIV_PI

#define BRAHE_TWO_DIV_PI 0.63661977236758134307553505349

## ◆ BRAHE_TWO_DIV_SQRT_PI

#define BRAHE_TWO_DIV_SQRT_PI 1.12837916709551257389615890312

## Typedef Documentation

## ◆ brahe_pretty_format

typedef enum brahe_pretty_format_t brahe_pretty_format

## ◆ brahe_statistics

typedef struct brahe_statistics_t brahe_statistics

## Enumeration Type Documentation

## ◆ brahe_pretty_format_t

enum brahe_pretty_format_t

Enumerator
BRAHE_PRETTY_TEXT | english text (nine thousand, two hundred eleven)
BRAHE_PRETTY_COMMA | comma delimited, (1,234,567,890)

## Function Documentation

## ◆ brahe_acosh()

double brahe_acosh | ( | const double | x | ) |

Calculates cosh-1.

Parameters

  x | a value

Returns
  inverse hyperbolic cosine of x

## ◆ brahe_add_noise()

void brahe_add_noise | ( | double * | a,
|  | const size_t | n,
|  | double | noise
| ) |  |

Adds a percentage of noise to a signal. If "noise" is set to 0.1 (for example) each value will be adjust to between 90% and 110% of its original value. This function changes the existing values in the array.

Parameters

  a | array containing signal data
  n | number of samples in signal
  noise | percentage of noise

## ◆ brahe_asinh()

double brahe_asinh | ( | const double | x | ) |

Calculates sinh-1.

Parameters

  x | a value

Returns
  inverse hyperbolic sine of x

## ◆ brahe_atanh()

double brahe_atanh | ( | const double | x | ) |

Calculates tanh-1.

Parameters

  x | a value

Returns
  inverse hyperbolic tangent of x

## ◆ brahe_gcf()

uint64_t brahe_gcf | ( | uint64_t | x,
|  | uint64_t | y
| ) |  |

Calculates the greatest common factor for two values.

Parameters

  x | first value
  y | second value

Returns
  The greatest common factor for x and y

## ◆ brahe_get_statistics()

brahe_statistics brahe_get_statistics | ( | double * | data,
|  | size_t | n
| ) |  |

Calculate several common statistics for an array of doubles.

Parameters

  data | array of double values
  n | number of elements in data

Returns
  statistics for data

## ◆ brahe_lcm()

uint64_t brahe_lcm | ( | const uint64_t | x,
|  | const uint64_t | y
| ) |  |

Calculates the lowest common multiple for two values.

Parameters

  x | first value
  y | second value

Returns
  The lowest common multiple for x and y

## ◆ brahe_log2base()

double brahe_log2base | ( | const double | x,
|  | const double | base
| ) |  |

Calculates the base-n logarithm for a given value. If a range error occurs, the return value equals NaN.

Parameters

  x | value for which logarithm is required
  base | lagarithm base

Returns
  logarithm of x to base base; NAN on range error

## ◆ brahe_make_sinusoid()

double* brahe_make_sinusoid | ( | const brahe_wave_factor_t * | factors,
|  | const size_t | factor_n,
|  | const size_t | array_n
| ) |  |

Generates an array of doubles by combining sine waves. The primary purpose is to produce an artificial signal with known properties, for testing signal analysis applications. The caller is responsible for freeing the memory used by the array returned by this function.

Parameters

  factors | defines properties of the sine waves to be combined
  factor_n | number of elements in factors
  array_n | number of elements in the output array

Returns
  an allocated array containg values generated from the given factors

## ◆ brahe_moving_average()

double* brahe_moving_average | ( | const double * | data,
|  | const int | n,
|  | const int | distance
| ) |  |

Computes the moving average for an array. The returned buffer must be freed by the calling code.

Parameters

  data | array of double values to be averaged
  n | number of elements in data
  distance | number elements to average before and after an element in data

Returns
  an allocated n-length array containing the moving average of corresponding elements in data

## ◆ brahe_pretty_int()

char* brahe_pretty_int | ( | int64_t | n,
|  | brahe_pretty_format | fmt
| ) |  |

Returns a nicely formatted strong for a given 64-bit integer.

Parameters

  n | number to be formatted
  fmt | specifies format, as text or comma-delimited

Returns
  an allocated string containing the generated text

## ◆ brahe_round_nearest()

double brahe_round_nearest | ( | const double | x | ) |

Rounds a value to nearest integer, rounding to even for exact fractions of 0.5.

## ◆ brahe_sigdig()

double brahe_sigdig | ( | const double | x,
|  | const uint16_t | n
| ) |  |

Returns the given value rounded for the number of specified decimal digits of precision.

Parameters

  x | - Original value to be rounded
  n | - Number of significant digits

Returns
  The value x rounded to n digits of precision

## ◆ brahe_simple_fft()

double* brahe_simple_fft | ( | const double * | data,
|  | const int | n
| ) |  |

A simple real-to-real FFT for arbitrary-length data. This is not intended to replace dedicated libraries such as FFTW. The caller is responsible for freeing the memory used by the array returned by this function. /param data input array /param n length of data /return an allocated array containing the real FFT of data

## ◆ brahe_simple_fft2()

double* brahe_simple_fft2 | ( | const double * | data,
|  | const int | n
| ) |  |

A simple real-to-real FFT for power of 2-length data. This is not intended to replace dedicated libraries such as FFTW. The caller is responsible for freeing the memory used by the array returned by this function. /param data input array /param n length of data /return an allocated array containing the real FFT of data

## ◆ brahe_sizepow2()

int brahe_sizepow2 | ( | const int | n | ) |

Returns the smallest power of 2 that includes n in its range

Parameters

  n | number that must be less than the result

Returns
  the lowest power of 2 that is greater than n, or

© 2011 Scott Robert Ladd. All rights reserved.
HTML documentation generated by Dimitri van Heesch's excellent Doxygen tool.