MeteoIODoc 2.11.0
MathOptim.h File Reference
#include <stdint.h>
#include <cmath>
#include <string.h>

Go to the source code of this file.

Namespaces

namespace  mio
 
namespace  mio::Optim
 

Macros

#define SQRT_MAGIC_D   0x5f3759df
 
#define SQRT_MAGIC_F   0x5f375a86
 

Functions

long int mio::Optim::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 mio::Optim::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 mio::Optim::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 mio::Optim::intPart (const double &x)
 
double mio::Optim::fracPart (const double &x)
 
float mio::Optim::invSqrt (const float x)
 
double mio::Optim::invSqrt (const double x)
 
float mio::Optim::fastSqrt_Q3 (const float x)
 
double mio::Optim::fastSqrt_Q3 (const double x)
 
double mio::Optim::pow2 (const double &val)
 
double mio::Optim::pow3 (const double &val)
 
double mio::Optim::pow4 (const double &val)
 
double mio::Optim::fastPowInternal (double a, double b)
 
double mio::Optim::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 mio::Optim::nth_rootf (float x)
 
template<int n>
double mio::Optim::nth_rootd (double x)
 
double mio::Optim::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 mio::Optim::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 >
mio::Optim::fastPow (T p, unsigned q)
 
double mio::Optim::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 mio::Optim::powerOfTwo (const unsigned int &n)
 

Macro Definition Documentation

◆ SQRT_MAGIC_D

#define SQRT_MAGIC_D   0x5f3759df

◆ SQRT_MAGIC_F

#define SQRT_MAGIC_F   0x5f375a86