Geant4 Cross Reference |
1 // Copyright (C) 2010, Guy Barrand. All rights 1 // Copyright (C) 2010, Guy Barrand. All rights reserved. 2 // See the file tools.license for terms. 2 // See the file tools.license for terms. 3 3 4 #ifndef tools_mathd 4 #ifndef tools_mathd 5 #define tools_mathd 5 #define tools_mathd 6 6 7 namespace tools { 7 namespace tools { 8 8 9 //have : static const pi = 3.14159265358979311 9 //have : static const pi = 3.1415926535897931160E0; ??? 10 10 11 //HEALPix lsconstants.h. Quite not the same as 11 //HEALPix lsconstants.h. Quite not the same as us. 12 //const double pi=3.14159265358979323846264338 12 //const double pi=3.141592653589793238462643383279502884197; 13 //const double twopi=6.28318530717958647692528 13 //const double twopi=6.283185307179586476925286766559005768394; 14 //const double fourpi=12.566370614359172953850 14 //const double fourpi=12.56637061435917295385057353311801153679; 15 //const double halfpi=1.5707963267948966192313 15 //const double halfpi=1.570796326794896619231321691639751442099; 16 16 17 inline double pi() {return 3.141592653589 17 inline double pi() {return 3.1415926535897931160E0;} 18 inline double two_pi() {return 6.283185307179 18 inline double two_pi() {return 6.2831853071795862320E0;} 19 inline double half_pi() {return 1.570796326794 19 inline double half_pi() {return 1.5707963267948965580E0;} 20 20 21 inline double deg2rad() { 21 inline double deg2rad() { 22 static const double s_v = pi()/180.0; 22 static const double s_v = pi()/180.0; 23 return s_v; 23 return s_v; 24 } 24 } 25 inline double rad2deg() { 25 inline double rad2deg() { 26 static const double s_v = 180.0/pi(); 26 static const double s_v = 180.0/pi(); 27 return s_v; 27 return s_v; 28 } 28 } 29 29 30 // for Lib/ExpFunc. 30 // for Lib/ExpFunc. 31 inline bool in_domain_all(double){return true; 31 inline bool in_domain_all(double){return true;} 32 inline bool in_domain_log(double a_x){return ( 32 inline bool in_domain_log(double a_x){return (a_x>0?true:false);} 33 inline bool in_domain_tan(double a_x){ 33 inline bool in_domain_tan(double a_x){ 34 int n = int(a_x/half_pi()); 34 int n = int(a_x/half_pi()); 35 if(a_x!=n*half_pi()) return true; 35 if(a_x!=n*half_pi()) return true; 36 return (2*int(n/2)==n?true:false); 36 return (2*int(n/2)==n?true:false); 37 } 37 } 38 inline bool in_domain_acos(double a_x){ 38 inline bool in_domain_acos(double a_x){ 39 if((a_x<-1)||(1<a_x)) return false; 39 if((a_x<-1)||(1<a_x)) return false; 40 return true; 40 return true; 41 } 41 } 42 42 43 /* 43 /* 44 inline double angle_modulo(double a_angle) { 44 inline double angle_modulo(double a_angle) { 45 int64 div = a_angle/two_pi(); 45 int64 div = a_angle/two_pi(); 46 double rest = a_angle - div*two_pi(); 46 double rest = a_angle - div*two_pi(); 47 if(rest<0) rest += two_pi(); 47 if(rest<0) rest += two_pi(); 48 return rest; 48 return rest; 49 } 49 } 50 */ 50 */ 51 51 52 } 52 } 53 53 54 //#include "power" 54 //#include "power" 55 55 56 #include <cmath> 56 #include <cmath> 57 57 58 namespace tools { 58 namespace tools { 59 59 60 inline double dcos(const double& a_x) {return 60 inline double dcos(const double& a_x) {return ::cos(a_x);} 61 inline double dsin(const double& a_x) {return 61 inline double dsin(const double& a_x) {return ::sin(a_x);} 62 inline double dpow(const double& a_x,const dou 62 inline double dpow(const double& a_x,const double& a_y) {return ::pow(a_x,a_y);} 63 inline double dcosh(const double& a_x) {return 63 inline double dcosh(const double& a_x) {return ::cosh(a_x);} 64 inline double dsinh(const double& a_x) {return 64 inline double dsinh(const double& a_x) {return ::sinh(a_x);} 65 65 66 inline double dconj(const double& a_x) {return 66 inline double dconj(const double& a_x) {return a_x;} 67 inline double dfabs(const double& a_x) {return 67 inline double dfabs(const double& a_x) {return ::fabs(a_x);} //if passing a_fabs(const T&). 68 inline double dsqrt(const double& a_x) {return 68 inline double dsqrt(const double& a_x) {return ::sqrt(a_x);} 69 69 70 //long double 70 //long double 71 #ifndef ANDROID 71 #ifndef ANDROID 72 inline long double ldfabs(const long double& a 72 inline long double ldfabs(const long double& a_x) {return ::fabsl(a_x);} 73 #endif 73 #endif 74 74 75 inline bool dpow(const double& a_x,const doubl 75 inline bool dpow(const double& a_x,const double& a_y,double& a_v) { 76 if((a_x==0)&&(a_y<0)) { 76 if((a_x==0)&&(a_y<0)) { 77 a_v = 0; 77 a_v = 0; 78 return false; 78 return false; 79 } 79 } 80 a_v = dpow(a_x,a_y); 80 a_v = dpow(a_x,a_y); 81 return true; 81 return true; 82 } 82 } 83 83 84 inline double dgaussian(const double& a_x,cons 84 inline double dgaussian(const double& a_x,const double& a_mean,const double& a_sigma) { 85 double _tmp = (a_x-a_mean)/a_sigma; 85 double _tmp = (a_x-a_mean)/a_sigma; 86 return ::exp(-_tmp*_tmp/2.0)/(a_sigma*::sqrt 86 return ::exp(-_tmp*_tmp/2.0)/(a_sigma*::sqrt(2*pi())); 87 } 87 } 88 88 89 } 89 } 90 90 91 #endif 91 #endif