git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@9405 f3b2605a-c512-4ea7-a41b-209d697bcdaa
This commit is contained in:
@ -19,25 +19,45 @@
|
||||
namespace LAMMPS_NS {
|
||||
|
||||
namespace MathSpecial {
|
||||
// x**2;
|
||||
|
||||
// x**2, use instead of pow(x,2.0)
|
||||
|
||||
static inline double square(const double &x) { return x*x; }
|
||||
|
||||
// optimized version of (sin(x)/x)**n with n being a positive integer
|
||||
static inline double powsinxx(const double x, int n) {
|
||||
double xx,yy,ww;
|
||||
// x**3, use instead of pow(x,3.0)
|
||||
static inline double cube(const double &x) { return x*x*x; }
|
||||
|
||||
if ((x == 0.0) || (n == 0)) return 1.0;
|
||||
// return -1.0 for odd n, 1.0 for even n, like pow(-1.0,n)
|
||||
static inline double powsign(const int n) { return (n & 1) ? -1.0 : 1.0; }
|
||||
|
||||
xx = sin(x)/x;
|
||||
yy = (n & 1) ? xx : 1.0;
|
||||
ww = xx;
|
||||
n >>= 1;
|
||||
// optimized version of pow(x,n) with n being integer
|
||||
// up to 10x faster than pow(x,y)
|
||||
|
||||
while (n) {
|
||||
ww *= ww;
|
||||
static inline double powint(const double &x, const int n) {
|
||||
double yy,ww;
|
||||
|
||||
if (x == 0.0) return 0.0;
|
||||
int nn = (n > 0) ? n : -n;
|
||||
ww = x;
|
||||
|
||||
for (yy = 1.0; nn != 0; nn >>= 1, ww *=ww)
|
||||
if (nn & 1) yy *= ww;
|
||||
|
||||
return (n > 0) ? yy : 1.0/yy;
|
||||
}
|
||||
|
||||
// optimized version of (sin(x)/x)**n with n being a _positive_ integer
|
||||
|
||||
static inline double powsinxx(const double &x, int n) {
|
||||
double yy,ww;
|
||||
|
||||
if (x == 0.0) return 1.0;
|
||||
|
||||
ww = sin(x)/x;
|
||||
|
||||
for (yy = 1.0; n != 0; n >>= 1, ww *=ww)
|
||||
if (n & 1) yy *= ww;
|
||||
n >>=1;
|
||||
}
|
||||
|
||||
return yy;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user