29#define SQRT_MAGIC_D 0x5f3759df
30#define SQRT_MAGIC_F 0x5f375a86
44 inline long int round(
const double& x) {
45 if (x>=0.)
return static_cast<long int>( x+.5 );
46 else return static_cast<long int>( x-.5 );
57 inline long int floor(
const double& x) {
58 const long int xi =
static_cast<long int>(x);
59 if (x >= 0 ||
static_cast<double>(xi) == x)
return xi ;
71 inline long int ceil(
const double& x) {
72 const long int xi =
static_cast<long int>(x);
73 if (x <= 0 ||
static_cast<double>(xi) == x)
return xi ;
85 return modf(x, &intpart);
89 #pragma warning( push )
90 #pragma warning(disable:4244)
95 const float xhalf = 0.5f*x;
103 return u.x*(1.5f - xhalf*u.x*u.x);
107 #pragma clang diagnostic push
108 #pragma clang diagnostic ignored "-Wdouble-promotion"
111 const double xhalf = 0.5f*x;
117 u.x =
static_cast<float>(x);
119 return u.x*(1.5f - xhalf*u.x*u.x);
122 #pragma clang diagnostic pop
126 #pragma warning( pop )
137 inline double pow2(
const double& val) {
return (val*val);}
138 inline double pow3(
const double& val) {
return (val*val*val);}
139 inline double pow4(
const double& val) {
return (val*val*val*val);}
150 u.x[1] = (int)((b - e) * (u.x[1] - 1072632447) + 1072632447);
189 #pragma clang diagnostic push
190 #pragma clang diagnostic ignored "-Wundefined-reinterpret-cast"
194 const bool sgn = (x<0.f)?
true :
false;
196 static const int ebits = 8;
197 static const int fbits = 23;
199 const int bias = (1 << (ebits-1))-1;
200 int& i =
reinterpret_cast<int&
>(x);
201 i = (i - (bias << fbits)) / n + (bias << fbits);
208 const bool sgn = (x<0.)?
true :
false;
210 static const int ebits = 11;
211 static const int fbits = 52;
213 const int64_t bias = (1 << (ebits-1))-1;
214 int64_t& i =
reinterpret_cast<int64_t&
>(x);
215 i = (i - (bias << fbits)) / n + (bias << fbits);
221 #pragma clang diagnostic pop
237 const double a = nth_rootd<3>(x);
238 const double a3 = a*a*a;
239 const double b = a * ( (a3 + x) + x) / ( a3 + (a3 + x) );
254 static const double a1 = 1.1499196;
255 static const double a2 = 0.6774323;
256 static const double a3 = 0.2080030;
257 static const double a4 = 0.1268089;
259 const double x2 = x*x;
260 const double tmp = 1. + a1*x + a2*x*x + a3*x*x2 + a4*x2*x2;
264 template <
typename T> T
fastPow(T p,
unsigned q) {
290 static const double a1 = 0.9974442;
291 static const double a2 = -.4712839;
292 static const double a3 = 0.2256685;
293 static const double a4 = -.0587527;
295 const double x2 = x*x;
296 return a1*x + a2*x2 + a3*x*x2 + a4*x2*x2;
#define SQRT_MAGIC_D
Definition MathOptim.h:29
#define SQRT_MAGIC_F
Definition MathOptim.h:30
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:71
double nth_rootd(double x)
Definition MathOptim.h:207
float fastSqrt_Q3(const float x)
Definition MathOptim.h:129
double pow4(const double &val)
Definition MathOptim.h:139
unsigned long int powerOfTwo(const unsigned int &n)
Definition MathOptim.h:299
double pow2(const double &val)
Definition MathOptim.h:137
double intPart(const double &x)
Definition MathOptim.h:77
double pow3(const double &val)
Definition MathOptim.h:138
double fastPowInternal(double a, double b)
Definition MathOptim.h:142
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:44
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:289
double fracPart(const double &x)
Definition MathOptim.h:83
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:57
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:179
float invSqrt(const float x)
Definition MathOptim.h:94
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:253
float nth_rootf(float x)
Definition MathOptim.h:193
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:236