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