PIP 5.6.1
Platform-Independent Primitives
Functions | Variables
pimathbase.h File Reference

Basic mathematical constants and helper algorithms. More...

#include "piinit.h"
#include "pipair.h"
#include "pivector.h"
#include <math.h>

Functions

int sign (const float &x)
 Returns the sign of a floating-point value.
 
int sign (const double &x)
 Returns the sign of a floating-point value.
 
int sign (const ldouble &x)
 Returns the sign of a floating-point value.
 
int pow2 (const int p)
 Returns 2 raised to integer power p.
 
float pow10 (const float &e)
 Returns 10 raised to the specified power.
 
double pow10 (const double &e)
 Returns 10 raised to the specified power.
 
ldouble pow10 (const ldouble &e)
 Returns 10 raised to the specified power.
 
double sinc (const double &v)
 Returns normalized sinc, sin(pi*x)/(pi*x).
 
constexpr float toRad (float deg)
 Converts degrees to radians.
 
constexpr double toRad (double deg)
 Converts degrees to radians.
 
constexpr ldouble toRad (ldouble deg)
 Converts degrees to radians.
 
constexpr float toDeg (float rad)
 Converts radians to degrees.
 
constexpr double toDeg (double rad)
 Converts radians to degrees.
 
constexpr ldouble toDeg (ldouble rad)
 Converts radians to degrees.
 
template<typename T >
constexpr T sqr (const T &v)
 Returns square of a value.
 
template<typename T >
constexpr T toDb (T val)
 Converts a power ratio to decibels.
 
template<typename T >
constexpr T fromDb (T val)
 Converts decibels to a linear power ratio.
 
double randomd ()
 Returns a pseudo-random value in the range [-1; 1].
 
double randomn (double dv=0., double sv=1.)
 Returns a normally distributed pseudo-random value with mean dv and deviation sv.
 
template<typename T >
PIVector< T > piAbs (const PIVector< T > &v)
 Returns vector with absolute values of each element.
 
template<typename T >
void normalizeAngleDeg360 (T &a)
 Normalizes an angle to the [0; 360] degree range in place.
 
template<typename T >
double normalizedAngleDeg360 (T a)
 Returns an angle normalized to the [0; 360] degree range.
 
template<typename T >
void normalizeAngleDeg180 (T &a)
 Normalizes an angle to the [-180; 180] degree range in place.
 
template<typename T >
double normalizedAngleDeg180 (T a)
 Returns an angle normalized to the [-180; 180] degree range.
 
template<typename T >
bool OLS_Linear (const PIVector< PIPair< T, T > > &input, T *out_a, T *out_b)
 Fits a linear model y = a*x + b with ordinary least squares. More...
 
template<typename T >
bool WLS_Linear (const PIVector< PIPair< T, T > > &input, const PIVector< T > &weights, T *out_a, T *out_b)
 Fits a weighted linear model y = a*x + b. More...
 

Variables

const double deg2rad = 1.74532925199432957692e-2
 Multiplicative factor for converting degrees to radians.
 
const double rad2deg = 57.2957795130823208768
 Multiplicative factor for converting radians to degrees.
 

Mathematical constants

Natural logarithm of 2

#define M_LN2   0.69314718055994530942
 
#define M_LN10   2.30258509299404568402
 Natural logarithm of 10.
 
#define M_SQRT2   1.41421356237309514547
 Square root of 2.
 
#define M_SQRT3   1.73205080756887719318
 Square root of 3.
 
#define M_1_SQRT2   0.70710678118654746172
 1 divided by square root of 2
 
#define M_1_SQRT3   0.57735026918962584208
 1 divided by square root of 3
 
#define M_PI   3.141592653589793238462643383280
 Pi constant.
 
#define M_2PI   6.283185307179586476925286766559
 2 times Pi
 
#define M_PI_3   1.04719755119659774615
 Pi divided by 3.
 
#define M_2PI_3   2.0943951023931954923
 2 times Pi divided by 3
 
#define M_180_PI   57.2957795130823208768
 180 divided by Pi (degrees to radians conversion factor)
 
#define M_PI_180   1.74532925199432957692e-2
 Pi divided by 180 (radians to degrees conversion factor)
 
#define M_SQRT_PI   1.772453850905516027298167483341
 Square root of Pi.
 
#define M_E   2.7182818284590452353602874713527
 Euler's number.
 
#define M_LIGHT_SPEED   2.99792458e+8
 Speed of light in vacuum.
 
#define M_RELATIVE_CONST   -4.442807633e-10;
 Relative gas constant.
 
#define M_GRAVITY_CONST   398600.4418e9;
 Gravitational constant.
 

Bessel functions

Bessel function of the first kind of order 0 Bessel function of the first kind J0(x), solution to Bessel's differential equation

See also
piJ1(), piJn()
double piJ0 (const double &v)
 
double piJ1 (const double &v)
 Bessel function of the first kind of order 1 Bessel function of the first kind J1(x), solution to Bessel's differential equation. More...
 
double piJn (int n, const double &v)
 Bessel function of the first kind of order n Bessel function of the first kind Jn(n, x), solution to Bessel's differential equation. More...
 
double piY0 (const double &v)
 Bessel function of the second kind of order 0 Bessel function of the second kind Y0(x), also known as Neumann function. More...
 
double piY1 (const double &v)
 Bessel function of the second kind of order 1 Bessel function of the second kind Y1(x), also known as Neumann function. More...
 
double piYn (int n, const double &v)
 Bessel function of the second kind of order n Bessel function of the second kind Yn(n, x), also known as Neumann function. More...
 

Detailed Description

Basic mathematical constants and helper algorithms.

Function Documentation

◆ piJ1()

double piJ1 ( const double &  v)

Bessel function of the first kind of order 1 Bessel function of the first kind J1(x), solution to Bessel's differential equation.

See also
piJ0(), piJn()

◆ piJn()

double piJn ( int  n,
const double &  v 
)

Bessel function of the first kind of order n Bessel function of the first kind Jn(n, x), solution to Bessel's differential equation.

See also
piJ0(), piJ1()

◆ piY0()

double piY0 ( const double &  v)

Bessel function of the second kind of order 0 Bessel function of the second kind Y0(x), also known as Neumann function.

See also
piY1(), piYn()

◆ piY1()

double piY1 ( const double &  v)

Bessel function of the second kind of order 1 Bessel function of the second kind Y1(x), also known as Neumann function.

See also
piY0(), piYn()

◆ piYn()

double piYn ( int  n,
const double &  v 
)

Bessel function of the second kind of order n Bessel function of the second kind Yn(n, x), also known as Neumann function.

See also
piY0(), piY1()

◆ OLS_Linear()

template<typename T >
bool OLS_Linear ( const PIVector< PIPair< T, T > > &  input,
T *  out_a,
T *  out_b 
)

Fits a linear model y = a*x + b with ordinary least squares.

Returns false when fewer than two sample pairs are provided.

◆ WLS_Linear()

template<typename T >
bool WLS_Linear ( const PIVector< PIPair< T, T > > &  input,
const PIVector< T > &  weights,
T *  out_a,
T *  out_b 
)

Fits a weighted linear model y = a*x + b.

Returns false when the sample is too small or the weights vector has a different size.