MeteoIODoc 2.11.0
mio::Optim Namespace Reference

Functions

long int round (const double &x)
 Optimized version of c++ round() This version works with positive and negative numbers but does not comply with IEEE handling of border cases (like infty, Nan, etc). Please benchmark your code before deciding to use this!! More...
 
long int floor (const double &x)
 Optimized version of c++ floor() This version works with positive and negative numbers but does not comply with IEEE handling of border cases (like infty, Nan, etc). Please benchmark your code before deciding to use this!! More...
 
long int ceil (const double &x)
 Optimized version of c++ ceil() This version works with positive and negative numbers but does not comply with IEEE handling of border cases (like infty, Nan, etc). Please benchmark your code before deciding to use this!! More...
 
double intPart (const double &x)
 
double fracPart (const double &x)
 
float invSqrt (const float x)
 
double invSqrt (const double x)
 
float fastSqrt_Q3 (const float x)
 
double fastSqrt_Q3 (const double x)
 
double pow2 (const double &val)
 
double pow3 (const double &val)
 
double pow4 (const double &val)
 
double fastPowInternal (double a, double b)
 
double fastPow (double a, double b)
 Optimized version of c++ pow() This version works with positive and negative exponents and handles exponents bigger than 1. The relative error remains less than 6% for the benchmarks that we ran (argument between 0 and 500 and exponent between -10 and +10). It is ~3.3 times faster than cmath's pow(). Source: http://martin.ankerl.com/2012/01/25/optimized-approximative-pow-in-c-and-cpp/. More...
 
template<int n>
float nth_rootf (float x)
 
template<int n>
double nth_rootd (double x)
 
double cbrt (double x)
 Optimized version of cubic root This version is based on a single iteration Halley's method (see https://en.wikipedia.org/wiki/Halley%27s_method) with a seed provided by a bit hack approximation. It should offer 15-16 bits precision and be three times faster than pow(x, 1/3). In some test, between -500 and +500, the largest relative error was 1.2e-4. Source: Otis E. Lancaster, Machine Method for the Extraction of Cube Root Journal of the American Statistical Association, Vol. 37, No. 217. (Mar., 1942), pp. 112-115. and http://metamerist.com/cbrt/cbrt.htm. More...
 
double pow10 (double x)
 Optimized version of 10^x This works for 0 <= x <= 1 and offers a theoritical precision of 5e-5 Source: Approximations for digital computers, Cecil Hastings, JR, Princeton University Press, 1955. More...
 
template<typename T >
fastPow (T p, unsigned q)
 
double ln_1plusX (double x)
 Optimized version of ln(1+x) This works for 0 <= x <= 1 and offers a theoritical precision of 5e-5 Source: Approximations for digital computers, Cecil Hastings, JR, Princeton University Press, 1955. More...
 
unsigned long int powerOfTwo (const unsigned int &n)
 

Function Documentation

◆ cbrt()

double mio::Optim::cbrt ( double  x)
inline

Optimized version of cubic root This version is based on a single iteration Halley's method (see https://en.wikipedia.org/wiki/Halley%27s_method) with a seed provided by a bit hack approximation. It should offer 15-16 bits precision and be three times faster than pow(x, 1/3). In some test, between -500 and +500, the largest relative error was 1.2e-4. Source: Otis E. Lancaster, Machine Method for the Extraction of Cube Root Journal of the American Statistical Association, Vol. 37, No. 217. (Mar., 1942), pp. 112-115. and http://metamerist.com/cbrt/cbrt.htm.

Please benchmark your code before deciding to use this!!

Parameters
xargument
Returns
x^(1/3)

◆ ceil()

long int mio::Optim::ceil ( const double &  x)
inline

Optimized version of c++ ceil() This version works with positive and negative numbers but does not comply with IEEE handling of border cases (like infty, Nan, etc). Please benchmark your code before deciding to use this!!

Parameters
xnumber to ceil
Returns
ceiled number cast as int

◆ fastPow() [1/2]

double mio::Optim::fastPow ( double  a,
double  b 
)
inline

Optimized version of c++ pow() This version works with positive and negative exponents and handles exponents bigger than 1. The relative error remains less than 6% for the benchmarks that we ran (argument between 0 and 500 and exponent between -10 and +10). It is ~3.3 times faster than cmath's pow(). Source: http://martin.ankerl.com/2012/01/25/optimized-approximative-pow-in-c-and-cpp/.

Please benchmark your code before deciding to use this!!

Parameters
aargument
bexponent
Returns
a^b

◆ fastPow() [2/2]

template<typename T >
T mio::Optim::fastPow ( p,
unsigned  q 
)

◆ fastPowInternal()

double mio::Optim::fastPowInternal ( double  a,
double  b 
)
inline

◆ fastSqrt_Q3() [1/2]

double mio::Optim::fastSqrt_Q3 ( const double  x)
inline

◆ fastSqrt_Q3() [2/2]

float mio::Optim::fastSqrt_Q3 ( const float  x)
inline

◆ floor()

long int mio::Optim::floor ( const double &  x)
inline

Optimized version of c++ floor() This version works with positive and negative numbers but does not comply with IEEE handling of border cases (like infty, Nan, etc). Please benchmark your code before deciding to use this!!

Parameters
xnumber to floor
Returns
floored number cast as int

◆ fracPart()

double mio::Optim::fracPart ( const double &  x)
inline

◆ intPart()

double mio::Optim::intPart ( const double &  x)
inline

◆ invSqrt() [1/2]

double mio::Optim::invSqrt ( const double  x)
inline

◆ invSqrt() [2/2]

float mio::Optim::invSqrt ( const float  x)
inline

◆ ln_1plusX()

double mio::Optim::ln_1plusX ( double  x)
inline

Optimized version of ln(1+x) This works for 0 <= x <= 1 and offers a theoritical precision of 5e-5 Source: Approximations for digital computers, Cecil Hastings, JR, Princeton University Press, 1955.

Tests have shown a maximum error of 2.5e-3 and a 1.7x speed up. Please benchmark your code before deciding to use this!!

Parameters
xargument
Returns
ln(1+x) with x in [0;1]

◆ nth_rootd()

template<int n>
double mio::Optim::nth_rootd ( double  x)
inline

◆ nth_rootf()

template<int n>
float mio::Optim::nth_rootf ( float  x)
inline

◆ pow10()

double mio::Optim::pow10 ( double  x)
inline

Optimized version of 10^x This works for 0 <= x <= 1 and offers a theoritical precision of 5e-5 Source: Approximations for digital computers, Cecil Hastings, JR, Princeton University Press, 1955.

Tests have shown a maximum error of 7e-5 and an almost 4x speed up. Please benchmark your code before deciding to use this!!

Parameters
xargument
Returns
10^x with x in [0;1]

◆ pow2()

double mio::Optim::pow2 ( const double &  val)
inline

◆ pow3()

double mio::Optim::pow3 ( const double &  val)
inline

◆ pow4()

double mio::Optim::pow4 ( const double &  val)
inline

◆ powerOfTwo()

unsigned long int mio::Optim::powerOfTwo ( const unsigned int &  n)
inline

◆ round()

long int mio::Optim::round ( const double &  x)
inline

Optimized version of c++ round() This version works with positive and negative numbers but does not comply with IEEE handling of border cases (like infty, Nan, etc). Please benchmark your code before deciding to use this!!

Parameters
xnumber to round
Returns
rounded number cast as int