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