max@0
|
1 // Copyright (C) 2008-2011 NICTA (www.nicta.com.au)
|
max@0
|
2 // Copyright (C) 2008-2011 Conrad Sanderson
|
max@0
|
3 //
|
max@0
|
4 // This file is part of the Armadillo C++ library.
|
max@0
|
5 // It is provided without any warranty of fitness
|
max@0
|
6 // for any purpose. You can redistribute this file
|
max@0
|
7 // and/or modify it under the terms of the GNU
|
max@0
|
8 // Lesser General Public License (LGPL) as published
|
max@0
|
9 // by the Free Software Foundation, either version 3
|
max@0
|
10 // of the License or (at your option) any later version.
|
max@0
|
11 // (see http://www.opensource.org/licenses for more info)
|
max@0
|
12
|
max@0
|
13
|
max@0
|
14 //! \addtogroup constants
|
max@0
|
15 //! @{
|
max@0
|
16
|
max@0
|
17
|
max@0
|
18 namespace priv
|
max@0
|
19 {
|
max@0
|
20 class Math_helper
|
max@0
|
21 {
|
max@0
|
22 public:
|
max@0
|
23
|
max@0
|
24 template<typename eT>
|
max@0
|
25 static
|
max@0
|
26 typename arma_float_only<eT>::result
|
max@0
|
27 nan(typename arma_float_only<eT>::result* junk = 0)
|
max@0
|
28 {
|
max@0
|
29 arma_ignore(junk);
|
max@0
|
30
|
max@0
|
31 if(std::numeric_limits<eT>::has_quiet_NaN == true)
|
max@0
|
32 {
|
max@0
|
33 return std::numeric_limits<eT>::quiet_NaN();
|
max@0
|
34 }
|
max@0
|
35 else
|
max@0
|
36 {
|
max@0
|
37 return eT(0);
|
max@0
|
38 }
|
max@0
|
39 }
|
max@0
|
40
|
max@0
|
41
|
max@0
|
42 template<typename eT>
|
max@0
|
43 static
|
max@0
|
44 typename arma_cx_only<eT>::result
|
max@0
|
45 nan(typename arma_cx_only<eT>::result* junk = 0)
|
max@0
|
46 {
|
max@0
|
47 arma_ignore(junk);
|
max@0
|
48
|
max@0
|
49 typedef typename get_pod_type<eT>::result T;
|
max@0
|
50
|
max@0
|
51 return eT( Math_helper::nan<T>(), Math_helper::nan<T>() );
|
max@0
|
52 }
|
max@0
|
53
|
max@0
|
54
|
max@0
|
55 template<typename eT>
|
max@0
|
56 static
|
max@0
|
57 typename arma_integral_only<eT>::result
|
max@0
|
58 nan(typename arma_integral_only<eT>::result* junk = 0)
|
max@0
|
59 {
|
max@0
|
60 arma_ignore(junk);
|
max@0
|
61
|
max@0
|
62 return eT(0);
|
max@0
|
63 }
|
max@0
|
64
|
max@0
|
65
|
max@0
|
66 template<typename eT>
|
max@0
|
67 static
|
max@0
|
68 typename arma_float_only<eT>::result
|
max@0
|
69 inf(typename arma_float_only<eT>::result* junk = 0)
|
max@0
|
70 {
|
max@0
|
71 arma_ignore(junk);
|
max@0
|
72
|
max@0
|
73 if(std::numeric_limits<eT>::has_infinity == true)
|
max@0
|
74 {
|
max@0
|
75 return std::numeric_limits<eT>::infinity();
|
max@0
|
76 }
|
max@0
|
77 else
|
max@0
|
78 {
|
max@0
|
79 return std::numeric_limits<eT>::max();
|
max@0
|
80 }
|
max@0
|
81 }
|
max@0
|
82
|
max@0
|
83
|
max@0
|
84 template<typename eT>
|
max@0
|
85 static
|
max@0
|
86 typename arma_cx_only<eT>::result
|
max@0
|
87 inf(typename arma_cx_only<eT>::result* junk = 0)
|
max@0
|
88 {
|
max@0
|
89 arma_ignore(junk);
|
max@0
|
90
|
max@0
|
91 typedef typename get_pod_type<eT>::result T;
|
max@0
|
92
|
max@0
|
93 return eT( Math_helper::inf<T>(), Math_helper::inf<T>() );
|
max@0
|
94 }
|
max@0
|
95
|
max@0
|
96
|
max@0
|
97 template<typename eT>
|
max@0
|
98 static
|
max@0
|
99 typename arma_integral_only<eT>::result
|
max@0
|
100 inf(typename arma_integral_only<eT>::result* junk = 0)
|
max@0
|
101 {
|
max@0
|
102 arma_ignore(junk);
|
max@0
|
103
|
max@0
|
104 return std::numeric_limits<eT>::max();
|
max@0
|
105 }
|
max@0
|
106
|
max@0
|
107 };
|
max@0
|
108 }
|
max@0
|
109
|
max@0
|
110
|
max@0
|
111
|
max@0
|
112 template<typename eT>
|
max@0
|
113 class Math
|
max@0
|
114 {
|
max@0
|
115 public:
|
max@0
|
116
|
max@0
|
117 // the long lengths of the constants are for future support of "long double"
|
max@0
|
118 // and any smart compiler that does high-precision computation at compile-time
|
max@0
|
119
|
max@0
|
120 //! ratio of any circle's circumference to its diameter
|
max@0
|
121 static eT pi() { return eT(3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679); }
|
max@0
|
122
|
max@0
|
123 //! base of the natural logarithm
|
max@0
|
124 static eT e() { return eT(2.7182818284590452353602874713526624977572470936999595749669676277240766303535475945713821785251664274); }
|
max@0
|
125
|
max@0
|
126 //! Euler's constant, aka Euler-Mascheroni constant
|
max@0
|
127 static eT euler() { return eT(0.5772156649015328606065120900824024310421593359399235988057672348848677267776646709369470632917467495); }
|
max@0
|
128
|
max@0
|
129 //! golden ratio
|
max@0
|
130 static eT gratio() { return eT(1.6180339887498948482045868343656381177203091798057628621354486227052604628189024497072072041893911374); }
|
max@0
|
131
|
max@0
|
132 //! square root of 2
|
max@0
|
133 static eT sqrt2() { return eT(1.4142135623730950488016887242096980785696718753769480731766797379907324784621070388503875343276415727); }
|
max@0
|
134
|
max@0
|
135 //! the difference between 1 and the least value greater than 1 that is representable
|
max@0
|
136 static eT eps() { return std::numeric_limits<eT>::epsilon(); }
|
max@0
|
137
|
max@0
|
138 //! log of the minimum representable value
|
max@0
|
139 static eT log_min() { static const eT out = std::log(std::numeric_limits<eT>::min()); return out; }
|
max@0
|
140
|
max@0
|
141 //! log of the maximum representable value
|
max@0
|
142 static eT log_max() { static const eT out = std::log(std::numeric_limits<eT>::max()); return out; }
|
max@0
|
143
|
max@0
|
144 //! "not a number"
|
max@0
|
145 static eT nan() { return priv::Math_helper::nan<eT>(); }
|
max@0
|
146
|
max@0
|
147 //! infinity
|
max@0
|
148 static eT inf() { return priv::Math_helper::inf<eT>(); }
|
max@0
|
149 };
|
max@0
|
150
|
max@0
|
151
|
max@0
|
152
|
max@0
|
153 //! Physical constants taken from NIST and WolframAlpha on 2009-06-23
|
max@0
|
154 //! http://physics.nist.gov/cuu/Constants
|
max@0
|
155 //! http://www.wolframalpha.com
|
max@0
|
156 //! See also http://en.wikipedia.org/wiki/Physical_constant
|
max@0
|
157 template<typename eT>
|
max@0
|
158 class Phy
|
max@0
|
159 {
|
max@0
|
160 public:
|
max@0
|
161
|
max@0
|
162 //! atomic mass constant (in kg)
|
max@0
|
163 static eT m_u() { return eT(1.660538782e-27); }
|
max@0
|
164
|
max@0
|
165 //! Avogadro constant
|
max@0
|
166 static eT N_A() { return eT(6.02214179e23); }
|
max@0
|
167
|
max@0
|
168 //! Boltzmann constant (in joules per kelvin)
|
max@0
|
169 static eT k() { return eT(1.3806504e-23); }
|
max@0
|
170
|
max@0
|
171 //! Boltzmann constant (in eV/K)
|
max@0
|
172 static eT k_evk() { return eT(8.617343e-5); }
|
max@0
|
173
|
max@0
|
174 //! Bohr radius (in meters)
|
max@0
|
175 static eT a_0() { return eT(0.52917720859e-10); }
|
max@0
|
176
|
max@0
|
177 //! Bohr magneton
|
max@0
|
178 static eT mu_B() { return eT(927.400915e-26); }
|
max@0
|
179
|
max@0
|
180 //! characteristic impedance of vacuum (in ohms)
|
max@0
|
181 static eT Z_0() { return eT(3.76730313461771e-2); }
|
max@0
|
182
|
max@0
|
183 //! conductance quantum (in siemens)
|
max@0
|
184 static eT G_0() { return eT(7.7480917004e-5); }
|
max@0
|
185
|
max@0
|
186 //! Coulomb's constant (in meters per farad)
|
max@0
|
187 static eT k_e() { return eT(8.9875517873681764e9); }
|
max@0
|
188
|
max@0
|
189 //! electric constant (in farads per meter)
|
max@0
|
190 static eT eps_0() { return eT(8.85418781762039e-12); }
|
max@0
|
191
|
max@0
|
192 //! electron mass (in kg)
|
max@0
|
193 static eT m_e() { return eT(9.10938215e-31); }
|
max@0
|
194
|
max@0
|
195 //! electron volt (in joules)
|
max@0
|
196 static eT eV() { return eT(1.602176487e-19); }
|
max@0
|
197
|
max@0
|
198 //! elementary charge (in coulombs)
|
max@0
|
199 static eT e() { return eT(1.602176487e-19); }
|
max@0
|
200
|
max@0
|
201 //! Faraday constant (in coulombs)
|
max@0
|
202 static eT F() { return eT(96485.3399); }
|
max@0
|
203
|
max@0
|
204 //! fine-structure constant
|
max@0
|
205 static eT alpha() { return eT(7.2973525376e-3); }
|
max@0
|
206
|
max@0
|
207 //! inverse fine-structure constant
|
max@0
|
208 static eT alpha_inv() { return eT(137.035999679); }
|
max@0
|
209
|
max@0
|
210 //! Josephson constant
|
max@0
|
211 static eT K_J() { return eT(483597.891e9); }
|
max@0
|
212
|
max@0
|
213 //! magnetic constant (in henries per meter)
|
max@0
|
214 static eT mu_0() { return eT(1.25663706143592e-06); }
|
max@0
|
215
|
max@0
|
216 //! magnetic flux quantum (in webers)
|
max@0
|
217 static eT phi_0() { return eT(2.067833667e-15); }
|
max@0
|
218
|
max@0
|
219 //! molar gas constant (in joules per mole kelvin)
|
max@0
|
220 static eT R() { return eT(8.314472); }
|
max@0
|
221
|
max@0
|
222 //! Newtonian constant of gravitation (in newton square meters per kilogram squared)
|
max@0
|
223 static eT G() { return eT(6.67428e-11); }
|
max@0
|
224
|
max@0
|
225 //! Planck constant (in joule seconds)
|
max@0
|
226 static eT h() { return eT(6.62606896e-34); }
|
max@0
|
227
|
max@0
|
228 //! Planck constant over 2 pi, aka reduced Planck constant (in joule seconds)
|
max@0
|
229 static eT h_bar() { return eT(1.054571628e-34); }
|
max@0
|
230
|
max@0
|
231 //! proton mass (in kg)
|
max@0
|
232 static eT m_p() { return eT(1.672621637e-27); }
|
max@0
|
233
|
max@0
|
234 //! Rydberg constant (in reciprocal meters)
|
max@0
|
235 static eT R_inf() { return eT(10973731.568527); }
|
max@0
|
236
|
max@0
|
237 //! speed of light in vacuum (in meters per second)
|
max@0
|
238 static eT c_0() { return eT(299792458.0); }
|
max@0
|
239
|
max@0
|
240 //! Stefan-Boltzmann constant
|
max@0
|
241 static eT sigma() { return eT(5.670400e-8); }
|
max@0
|
242
|
max@0
|
243 //! von Klitzing constant (in ohms)
|
max@0
|
244 static eT R_k() { return eT(25812.807557); }
|
max@0
|
245
|
max@0
|
246 //! Wien wavelength displacement law constant
|
max@0
|
247 static eT b() { return eT(2.8977685e-3); }
|
max@0
|
248 };
|
max@0
|
249
|
max@0
|
250
|
max@0
|
251
|
max@0
|
252 typedef Math<float> fmath;
|
max@0
|
253 typedef Math<double> math;
|
max@0
|
254
|
max@0
|
255 typedef Phy<float> fphy;
|
max@0
|
256 typedef Phy<double> phy;
|
max@0
|
257
|
max@0
|
258
|
max@0
|
259
|
max@0
|
260 namespace priv
|
max@0
|
261 {
|
max@0
|
262
|
max@0
|
263 template<typename eT>
|
max@0
|
264 static
|
max@0
|
265 arma_inline
|
max@0
|
266 arma_hot
|
max@0
|
267 typename arma_float_only<eT>::result
|
max@0
|
268 most_neg(typename arma_float_only<eT>::result* junk = 0)
|
max@0
|
269 {
|
max@0
|
270 arma_ignore(junk);
|
max@0
|
271
|
max@0
|
272 if(std::numeric_limits<eT>::has_infinity == true)
|
max@0
|
273 {
|
max@0
|
274 return -(std::numeric_limits<eT>::infinity());
|
max@0
|
275 }
|
max@0
|
276 else
|
max@0
|
277 {
|
max@0
|
278 return -(std::numeric_limits<eT>::max());
|
max@0
|
279 }
|
max@0
|
280 }
|
max@0
|
281
|
max@0
|
282
|
max@0
|
283 template<typename eT>
|
max@0
|
284 static
|
max@0
|
285 arma_inline
|
max@0
|
286 arma_hot
|
max@0
|
287 typename arma_integral_only<eT>::result
|
max@0
|
288 most_neg(typename arma_integral_only<eT>::result* junk = 0)
|
max@0
|
289 {
|
max@0
|
290 arma_ignore(junk);
|
max@0
|
291
|
max@0
|
292 return std::numeric_limits<eT>::min();
|
max@0
|
293 }
|
max@0
|
294
|
max@0
|
295
|
max@0
|
296 template<typename eT>
|
max@0
|
297 static
|
max@0
|
298 arma_inline
|
max@0
|
299 arma_hot
|
max@0
|
300 typename arma_float_only<eT>::result
|
max@0
|
301 most_pos(typename arma_float_only<eT>::result* junk = 0)
|
max@0
|
302 {
|
max@0
|
303 arma_ignore(junk);
|
max@0
|
304
|
max@0
|
305 if(std::numeric_limits<eT>::has_infinity == true)
|
max@0
|
306 {
|
max@0
|
307 return std::numeric_limits<eT>::infinity();
|
max@0
|
308 }
|
max@0
|
309 else
|
max@0
|
310 {
|
max@0
|
311 return std::numeric_limits<eT>::max();
|
max@0
|
312 }
|
max@0
|
313 }
|
max@0
|
314
|
max@0
|
315
|
max@0
|
316 template<typename eT>
|
max@0
|
317 static
|
max@0
|
318 arma_inline
|
max@0
|
319 arma_hot
|
max@0
|
320 typename arma_integral_only<eT>::result
|
max@0
|
321 most_pos(typename arma_integral_only<eT>::result* junk = 0)
|
max@0
|
322 {
|
max@0
|
323 arma_ignore(junk);
|
max@0
|
324
|
max@0
|
325 return std::numeric_limits<eT>::max();
|
max@0
|
326 }
|
max@0
|
327
|
max@0
|
328 }
|
max@0
|
329
|
max@0
|
330
|
max@0
|
331
|
max@0
|
332 //! @}
|