30#define SQRT_MAGIC_D 0x5f3759df
31#define SQRT_MAGIC_F 0x5f375a86
45 inline long int round(
const double& x) {
46 if (x>=0.)
return static_cast<long int>( x+.5 );
47 else return static_cast<long int>( x-.5 );
58 inline long int floor(
const double& x) {
59 const long int xi =
static_cast<long int>(x);
60 if (x >= 0 ||
static_cast<double>(xi) == x)
return xi ;
72 inline long int ceil(
const double& x) {
73 const long int xi =
static_cast<long int>(x);
74 if (x <= 0 ||
static_cast<double>(xi) == x)
return xi ;
86 return modf(x, &intpart);
90 #pragma warning( push )
91 #pragma warning(disable:4244)
96 const float xhalf = 0.5f*x;
104 return u.x*(1.5f - xhalf*u.x*u.x);
108 #pragma clang diagnostic push
109 #pragma clang diagnostic ignored "-Wdouble-promotion"
112 const double xhalf = 0.5f*x;
118 u.x =
static_cast<float>(x);
120 return u.x*(1.5f - xhalf*u.x*u.x);
123 #pragma clang diagnostic pop
127 #pragma warning( pop )
138 inline double pow2(
const double& val) {
return (val*val);}
139 inline double pow3(
const double& val) {
return (val*val*val);}
140 inline double pow4(
const double& val) {
return (val*val*val*val);}
151 u.x[1] = (int)((b -
e) * (u.x[1] - 1072632447) + 1072632447);
190 #pragma clang diagnostic push
191 #pragma clang diagnostic ignored "-Wundefined-reinterpret-cast"
195 const bool sgn = (x<0.f)?
true :
false;
197 static const int ebits = 8;
198 static const int fbits = 23;
200 const int bias = (1 << (ebits-1))-1;
201 int& i =
reinterpret_cast<int&
>(x);
202 i = (i - (bias << fbits)) / n + (bias << fbits);
209 const bool sgn = (x<0.)?
true :
false;
211 static const int ebits = 11;
212 static const int fbits = 52;
214 const int64_t bias = (1 << (ebits-1))-1;
215 int64_t& i =
reinterpret_cast<int64_t&
>(x);
216 i = (i - (bias << fbits)) / n + (bias << fbits);
222 #pragma clang diagnostic pop
238 const double a = nth_rootd<3>(x);
239 const double a3 = a*a*a;
240 const double b = a * ( (a3 + x) + x) / ( a3 + (a3 + x) );
255 static const double a1 = 1.1499196;
256 static const double a2 = 0.6774323;
257 static const double a3 = 0.2080030;
258 static const double a4 = 0.1268089;
260 const double x2 = x*x;
261 const double tmp = 1. + a1*x + a2*x*x + a3*x*x2 + a4*x2*x2;
265 template <
typename T> T
fastPow(T p,
unsigned q) {
291 static const double a1 = 0.9974442;
292 static const double a2 = -.4712839;
293 static const double a3 = 0.2256685;
294 static const double a4 = -.0587527;
296 const double x2 = x*x;
297 return a1*x + a2*x2 + a3*x*x2 + a4*x2*x2;
#define SQRT_MAGIC_D
Definition: MathOptim.h:30
#define SQRT_MAGIC_F
Definition: MathOptim.h:31
static const double e
Definition: Meteoconst.h:68
long int ceil(const double &x)
Optimized version of c++ ceil() This version works with positive and negative numbers but does not co...
Definition: MathOptim.h:72
double nth_rootd(double x)
Definition: MathOptim.h:208
float fastSqrt_Q3(const float x)
Definition: MathOptim.h:130
double pow4(const double &val)
Definition: MathOptim.h:140
unsigned long int powerOfTwo(const unsigned int &n)
Definition: MathOptim.h:300
double pow2(const double &val)
Definition: MathOptim.h:138
double intPart(const double &x)
Definition: MathOptim.h:78
double pow3(const double &val)
Definition: MathOptim.h:139
double fastPowInternal(double a, double b)
Definition: MathOptim.h:143
long int round(const double &x)
Optimized version of c++ round() This version works with positive and negative numbers but does not c...
Definition: MathOptim.h:45
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 So...
Definition: MathOptim.h:290
double fracPart(const double &x)
Definition: MathOptim.h:84
long int floor(const double &x)
Optimized version of c++ floor() This version works with positive and negative numbers but does not c...
Definition: MathOptim.h:58
double fastPow(double a, double b)
Optimized version of c++ pow() This version works with positive and negative exponents and handles ex...
Definition: MathOptim.h:180
float invSqrt(const float x)
Definition: MathOptim.h:95
double pow10(double x)
Optimized version of 10^x This works for 0 <= x <= 1 and offers a theoritical precision of 5e-5 Sourc...
Definition: MathOptim.h:254
float nth_rootf(float x)
Definition: MathOptim.h:194
double cbrt(double x)
Optimized version of cubic root This version is based on a single iteration Halley's method (see http...
Definition: MathOptim.h:237