ccgl::utils_math Namespace Reference

Basic mathematics related functions. More...

Functions

float Expo (float xx, float upper=20.f, float lower=-20.f)
 Check the argument against upper and lower boundary values prior to doing Exponential function.
 
float Power (float a, float n)
 deal with positive and negative float numbers
 
float ApprSqrt (float z)
 approximate sqrt More...
 
double ApprSqrt (const double z)
 
float ApprLn (float z)
 Approximates the natural logarithm, (where the base is 'e'=2.71828)
 
double ApprLn (const double z)
 
float pow_lookup (const float exp, const float log_base)
 lookup for pow(a, b) function More...
 
template<typename T1 , typename T2 >
bool FloatEqual (T1 v1, T2 v2)
 Whether v1 is equal to v2. More...
 
template<typename T >
MaxInArray (const T *a, int n)
 Get maximum value in a numeric array with size n. More...
 
template<typename T >
MinInArray (const T *a, int n)
 Get minimum value in a numeric array with size n. More...
 
template<typename T >
Sum (int row, const T *data)
 Sum of a numeric array Get sum value of a double array with size row. More...
 
template<typename T >
Sum (int row, int *&idx, const T *data)
 Sum of a numeric array Get sum value of a double array with size row and real index idx. More...
 
template<typename T >
void BasicStatistics (const T *values, int num, double **derivedvalues, T exclude=static_cast< T >(NODATA_VALUE))
 calculate basic statistics at one time_funcs More...
 
template<typename T >
void BasicStatistics (const T *const *values, int num, int lyrs, double ***derivedvalues, T exclude=static_cast< T >(NODATA_VALUE))
 calculate basic statistics at one time_funcs for 2D raster data More...
 
template<typename T >
CalSqrt (T val)
 
template<typename T >
CalExp (T val)
 
template<typename T >
CalLn (T val)
 
float ApprPow (float a, float b)
 Approximates pow(a, b) based on the work of Harrison Ainsworth. More...
 
template<typename T1 , typename T2 >
double CalPow (T1 a, T2 b)
 

Variables

const vuint32_t pow_mantissa_table_shift = 11
 
vuint32_t const pow_mantissa_table []
 

Detailed Description

Basic mathematics related functions.

Function Documentation

◆ ApprPow()

float ccgl::utils_math::ApprPow ( float  a,
float  b 
)
inline

Approximates pow(a, b) based on the work of Harrison Ainsworth.

Refers to http://www.hxa.name/articles/content/fast-pow-adjustable_hxa7241_2007.html Copyright (c) 2007, Harrison Ainsworth / HXA7241.

◆ ApprSqrt()

float ccgl::utils_math::ApprSqrt ( float  z)

approximate sqrt

This uses a method to approximate sqrt which only applies to IEEE 754 floating point numbers, described in [1]. The optimized magic constant is from Chris Lomont[2]

References: 1: http://en.wikipedia.org/wiki/Fast_inverse_square_root 2: http://www.lomont.org/Math/Papers/2003/InvSqrt.pdf

Parameters
[in]zfloat or double value
Returns
approximation of sqrt

◆ BasicStatistics() [1/2]

template<typename T >
void ccgl::utils_math::BasicStatistics ( const T *const *  values,
int  num,
int  lyrs,
double ***  derivedvalues,
exclude = static_cast<T>(NODATA_VALUE) 
)

calculate basic statistics at one time_funcs for 2D raster data

Parameters
[in]valuesdata array
[in]numdata length
[in]lyrslayer number
[out]derivedvaluesdouble array, value number, mean, max, min, std, range
[in]excludeoptional, excluded value, e.g. NoDATA, the default is -9999

valid number

mean

maximum

minimum

std

range

valid number

mean

maximum

minimum

std

range

◆ BasicStatistics() [2/2]

template<typename T >
void ccgl::utils_math::BasicStatistics ( const T *  values,
int  num,
double **  derivedvalues,
exclude = static_cast<T>(NODATA_VALUE) 
)

calculate basic statistics at one time_funcs

Parameters
[in]valuesdata array
[in]numdata length
[out]derivedvaluesdouble array, value number, mean, max, min, std, range
[in]excludeoptional, excluded value, e.g. NoDATA, the default is -9999

◆ FloatEqual()

template<typename T1 , typename T2 >
bool ccgl::utils_math::FloatEqual ( T1  v1,
T2  v2 
)

Whether v1 is equal to v2.

Parameters
[in]v1Numeric value of data type 1
[in]v2Numeric value of data type 2
Returns
true or false

◆ MaxInArray()

template<typename T >
T ccgl::utils_math::MaxInArray ( const T *  a,
int  n 
)

Get maximum value in a numeric array with size n.

Parameters
[in]a,n
Returns
max value

◆ MinInArray()

template<typename T >
T ccgl::utils_math::MinInArray ( const T *  a,
int  n 
)

Get minimum value in a numeric array with size n.

Parameters
[in]a,n
Returns
min value

◆ pow_lookup()

float ccgl::utils_math::pow_lookup ( const float  exp,
const float  log_base 
)

lookup for pow(a, b) function

Parameters
[in]exppower to raise radix to (exponent), i.e., b in pow(a, b)
[in]log_baseone over log, to required radix, of two (ln(base))

◆ Sum() [1/2]

template<typename T >
T ccgl::utils_math::Sum ( int  row,
const T *  data 
)

Sum of a numeric array Get sum value of a double array with size row.

Parameters
[in]row
[in]data
Returns
sum

◆ Sum() [2/2]

template<typename T >
T ccgl::utils_math::Sum ( int  row,
int *&  idx,
const T *  data 
)

Sum of a numeric array Get sum value of a double array with size row and real index idx.

Parameters
[in]row
[in]idx
[in]data
Returns
sum