utils_math.h File Reference

Useful math equations in CCGL. More...

#include <cmath>
#include "basic.h"
#include "utils_array.h"

Go to the source code of this file.

Namespaces

namespace  ccgl
 Common Cross-platform Geographic Library (CCGL)
 
namespace  ccgl::utils_math
 Basic mathematics related functions.
 

Macros

#define M_E   2.7182818284590452354 /* e */
 
#define M_LOG2E   1.4426950408889634074 /* log 2e */
 
#define M_LOG10E   0.43429448190325182765 /* log 10e */
 
#define M_LN2   0.69314718055994530942 /* log e2 */
 
#define M_LN10   2.30258509299404568402 /* log e10 */
 
#define M_PI   3.14159265358979323846 /* pi */
 
#define M_PI_2   1.57079632679489661923 /* pi/2 */
 
#define M_PI_4   0.78539816339744830962 /* pi/4 */
 
#define M_1_PI   0.31830988618379067154 /* 1/pi */
 
#define M_2_PI   0.63661977236758134308 /* 2/pi */
 
#define M_2_SQRTPI   1.12837916709551257390 /* 2/sqrt(pi) */
 
#define M_SQRT2   1.41421356237309504880 /* sqrt(2) */
 
#define M_SQRT1_2   0.70710678118654752440 /* 1/sqrt(2) */
 
#define M_2POW23   8388608.0f /* pow(2, 23) */
 
#define HUGE   ((float)3.40282347e+38) /*maximum value of float*/
 
#define MAXFLOAT   ((float)3.40282347e+38) /*maximum value of float*/
 
#define MINFLOAT   ((float)1.175494351e-38) /*minimum value of float*/
 
#define M_SQRT3   1.732051f /* sqrt(3) */
 
#define M_TC   0.63212055882855767840f /* 1 - 1/e */
 
#define M_PI2   6.283185f /* pi*2 */
 
#define M_GOLDEN   1.618034f /* golden ratio */
 
#define M_1_PI2   0.15915494309189534561f /* 1/(pi*2) */
 
#define M_DIV3   0.3333333333333333333f /* 1/3 */
 
#define M_DIV4   0.25f /* 1/4 */
 
#define M_DIV5   0.2f /* 1/5 */
 
#define M_DIV6   0.1666666666666666666f /* 1/6 */
 
#define M_DIV7   0.142857143f /* 1/7 */
 
#define M_DIV8   0.125f /* 1/8 */
 
#define M_DIV9   0.1111111111111111111f /* 1/9 */
 
#define M_DIV10   0.1f /* 1/10 */
 
#define M_DIV11   0.090909091f /* 1/11 */
 
#define M_DIV12   0.0833333333333333333f /* 1/12 */
 
#define M_DIV13   0.076923077f /* 1/13 */
 
#define M_DIV14   0.071428571f /* 1/14 */
 
#define M_DIV15   0.0666666666666666666f /* 1/15 */
 
#define M_DIV16   0.0625f /* 1/16 */
 
#define M_DIV_LN10   0.43429448190325182765f /* 1 / ln(10) */
 
#define PH_C   ((float)299792458) /*speed of light (m/s)*/
 
#define PH_M0   ((float)1.2566370614359172950) /*mag permeability (mH/m)*/
 
#define PH_H   ((float)6.62606957e-34) /*planck constant (J/Hz)*/
 
#define PH_HBAR   ((float)1.05457172e-34) /*diract constant* (J.s/rad)*/
 
#define PH_K   ((float)1.3806488e-23) /*boltzmann constant (J/K)*/
 
#define PH_ME   ((float)9.10938291e-31) /*mass of electron (kg)*/
 
#define PH_MP   ((float)1.672614e-27) /*mass of proton (kg)*/
 
#define PH_MN   ((float)1.674920e-27) /*mass of neutron (kg)*/
 
#define PH_EC   ((float)1.6021917e-19) /*charge of electron (C)*/
 
#define PH_F   ((float)9.648670e4) /*faraday constant (C/mol)*/
 
#define PH_G   ((float)6.6732e-11) /*gravitational constant (N*m^2/kg^2)*/
 
#define PH_AVO   ((float)6.022169e23) /*avogadro constant*/
 
#define Max(a, b)   ((a) >= (b) ? (a) : (b))
 Return maximum value.
 
#define Min(a, b)   ((a) >= (b) ? (b) : (a))
 Return minimum value.
 
#define Abs(x)   ((x) >= 0 ? (x) : -(x))
 Return absolute value.
 

Functions

template<typename T1 , typename T2 >
bool ccgl::utils_math::FloatEqual (T1 v1, T2 v2)
 Whether v1 is equal to v2. More...
 
float ccgl::utils_math::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 ccgl::utils_math::Power (float a, float n)
 deal with positive and negative float numbers
 
template<typename T >
ccgl::utils_math::MaxInArray (const T *a, int n)
 Get maximum value in a numeric array with size n. More...
 
template<typename T >
ccgl::utils_math::MinInArray (const T *a, int n)
 Get minimum value in a numeric array with size n. More...
 
template<typename 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. More...
 
template<typename 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. More...
 
template<typename T >
void ccgl::utils_math::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 ccgl::utils_math::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...
 
float ccgl::utils_math::ApprSqrt (float z)
 approximate sqrt More...
 
double ccgl::utils_math::ApprSqrt (const double z)
 
template<typename T >
ccgl::utils_math::CalSqrt (T val)
 
template<typename T >
ccgl::utils_math::CalExp (T val)
 
float ccgl::utils_math::ApprLn (float z)
 Approximates the natural logarithm, (where the base is 'e'=2.71828)
 
double ccgl::utils_math::ApprLn (const double z)
 
template<typename T >
ccgl::utils_math::CalLn (T val)
 
float ccgl::utils_math::pow_lookup (const float exp, const float log_base)
 lookup for pow(a, b) function More...
 
float ccgl::utils_math::ApprPow (float a, float b)
 Approximates pow(a, b) based on the work of Harrison Ainsworth. More...
 
template<typename T1 , typename T2 >
double ccgl::utils_math::CalPow (T1 a, T2 b)
 

Detailed Description

Useful math equations in CCGL.

Remarks
  • 1. 2018-05-02 - lj - Make part of CCGL.
  • 2. 2021-07-15 - lj - Integrate pal.math for fast pow, exp, and ln
Author
Liangjun Zhu, zlj(a)lreis.ac.cn
Version
1.1