ConicBundle
mymath.hxx
Go to the documentation of this file.
1 
2 
3 #ifndef CH_MATRIX_CLASSES_MYMATH_HXX
4 #define CH_MATRIX_CLASSES_MYMATH_HXX
5 
15 #include <cmath>
16 #include <cstdlib>
17 
18 namespace CH_Matrix_Classes {
19 
23 
25 inline double abs(double d)
26 {
27  return std::fabs(d);
28 }
29 
31 inline int abs(int d)
32 {
33  return std::abs(d);
34 }
35 
37 inline long abs(long d)
38 {
39  return std::labs(d);
40 }
41 
43 inline double max(double a,double b)
44 {
45  return (a>=b)?a:b;
46 }
47 
49 inline double min(double a,double b)
50 {
51  return (a<=b)?a:b;
52 }
53 
55 inline int max(int a,int b)
56 {
57  return (a>=b)?a:b;
58 }
59 
61 inline int min(int a,int b)
62 {
63  return (a<=b)?a:b;
64 }
65 
67 inline long max(long a,long b)
68 {
69  return (a>=b)?a:b;
70 }
71 
73 inline long min(long a,long b)
74 {
75  return (a<=b)?a:b;
76 }
77 
79 inline void swap(double& a,double& b)
80 {
81  double h=a; a=b; b=h;
82 }
83 
85 inline void swap(long& a,long& b)
86 {
87  long h=a; a=b; b=h;
88 }
89 
91 inline void swap(int& a,int& b)
92 {
93  int h=a; a=b; b=h;
94 }
95 
97 inline void swap(bool& a,bool& b)
98 {
99  bool h=a; a=b; b=h;
100 }
101 
103 inline int sqr(int a)
104 {
105  return a*a;
106 }
107 
109 inline long sqr(long a)
110 {
111  return a*a;
112 }
113 
115 inline double sqr(double a)
116 {
117  return a*a;
118 }
119 
121 inline double sqrt(int a)
122 {
123  return std::sqrt(double(a));
124 }
125 
127 inline double sqrt(long a)
128 {
129  return std::sqrt(double(a));
130 }
131 
133 inline int sign(int a)
134 {
135  if (a>0) return 1;
136  if (a<0) return -1;
137  return 0;
138 }
139 
141 inline long sign(long a)
142 {
143  if (a>0) return 1;
144  if (a<0) return -1;
145  return 0;
146 }
147 
149 inline double sign(double a)
150 {
151  return (a>=0)?1.:-1.;
152 }
153 
155 inline double sign(double a,double tol)
156 {
157  if (a>tol) return 1.;
158  if (a<-tol) return -1.;
159  return 0.;
160 }
161 
162 //---- functions for f2c translations
163 
165 inline double d_sign(double a,double b)
166 {
167  return (((b>=0)&&(a>=0))||((b<0)&&(a<0)))?a:-a;
168 }
169 
171 
172 }
173 
174 #endif
175 
double sqrt(long a)
return sqrt for long a
Definition: mymath.hxx:127
void swap(double &a, double &b)
swaps two double variables
Definition: mymath.hxx:79
long abs(long d)
absolute value of a long
Definition: mymath.hxx:37
int sign(int a)
return the signum of an int a (1 for a>0,-1 for a<0,0 for a==0)
Definition: mymath.hxx:133
Matrix Classes and Linear Algebra. See Matrix Classes (namespace CH_Matrix_Classes) for a quick intro...
Definition: PSCOracle.hxx:20
int sqr(int a)
return a*a for int a
Definition: mymath.hxx:103
double max(double a, double b)
maximum value of two double variables
Definition: mymath.hxx:43
double min(double a, double b)
minimum value of two double variables
Definition: mymath.hxx:49
double abs(double d)
absolute value of a double
Definition: mymath.hxx:25
double d_sign(double a, double b)
return a if a and b have the same sign, return -a otherwise
Definition: mymath.hxx:165
double sqrt(int a)
return sqrt for int a
Definition: mymath.hxx:121