1 | // Copyright (C) 2008-2012 Conrad Sanderson |
---|
2 | // Copyright (C) 2008-2012 NICTA (www.nicta.com.au) |
---|
3 | // |
---|
4 | // This Source Code Form is subject to the terms of the Mozilla Public |
---|
5 | // License, v. 2.0. If a copy of the MPL was not distributed with this |
---|
6 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. |
---|
7 | |
---|
8 | |
---|
9 | //! \addtogroup constants |
---|
10 | //! @{ |
---|
11 | |
---|
12 | |
---|
13 | namespace priv |
---|
14 | { |
---|
15 | class Datum_helper |
---|
16 | { |
---|
17 | public: |
---|
18 | |
---|
19 | template<typename eT> |
---|
20 | static |
---|
21 | typename arma_real_only<eT>::result |
---|
22 | nan(typename arma_real_only<eT>::result* junk = 0) |
---|
23 | { |
---|
24 | arma_ignore(junk); |
---|
25 | |
---|
26 | if(std::numeric_limits<eT>::has_quiet_NaN == true) |
---|
27 | { |
---|
28 | return std::numeric_limits<eT>::quiet_NaN(); |
---|
29 | } |
---|
30 | else |
---|
31 | { |
---|
32 | return eT(0); |
---|
33 | } |
---|
34 | } |
---|
35 | |
---|
36 | |
---|
37 | template<typename eT> |
---|
38 | static |
---|
39 | typename arma_cx_only<eT>::result |
---|
40 | nan(typename arma_cx_only<eT>::result* junk = 0) |
---|
41 | { |
---|
42 | arma_ignore(junk); |
---|
43 | |
---|
44 | typedef typename get_pod_type<eT>::result T; |
---|
45 | |
---|
46 | return eT( Datum_helper::nan<T>(), Datum_helper::nan<T>() ); |
---|
47 | } |
---|
48 | |
---|
49 | |
---|
50 | template<typename eT> |
---|
51 | static |
---|
52 | typename arma_integral_only<eT>::result |
---|
53 | nan(typename arma_integral_only<eT>::result* junk = 0) |
---|
54 | { |
---|
55 | arma_ignore(junk); |
---|
56 | |
---|
57 | return eT(0); |
---|
58 | } |
---|
59 | |
---|
60 | |
---|
61 | template<typename eT> |
---|
62 | static |
---|
63 | typename arma_real_only<eT>::result |
---|
64 | inf(typename arma_real_only<eT>::result* junk = 0) |
---|
65 | { |
---|
66 | arma_ignore(junk); |
---|
67 | |
---|
68 | if(std::numeric_limits<eT>::has_infinity == true) |
---|
69 | { |
---|
70 | return std::numeric_limits<eT>::infinity(); |
---|
71 | } |
---|
72 | else |
---|
73 | { |
---|
74 | return std::numeric_limits<eT>::max(); |
---|
75 | } |
---|
76 | } |
---|
77 | |
---|
78 | |
---|
79 | template<typename eT> |
---|
80 | static |
---|
81 | typename arma_cx_only<eT>::result |
---|
82 | inf(typename arma_cx_only<eT>::result* junk = 0) |
---|
83 | { |
---|
84 | arma_ignore(junk); |
---|
85 | |
---|
86 | typedef typename get_pod_type<eT>::result T; |
---|
87 | |
---|
88 | return eT( Datum_helper::inf<T>(), Datum_helper::inf<T>() ); |
---|
89 | } |
---|
90 | |
---|
91 | |
---|
92 | template<typename eT> |
---|
93 | static |
---|
94 | typename arma_integral_only<eT>::result |
---|
95 | inf(typename arma_integral_only<eT>::result* junk = 0) |
---|
96 | { |
---|
97 | arma_ignore(junk); |
---|
98 | |
---|
99 | return std::numeric_limits<eT>::max(); |
---|
100 | } |
---|
101 | |
---|
102 | }; |
---|
103 | } |
---|
104 | |
---|
105 | |
---|
106 | |
---|
107 | //! various constants. |
---|
108 | //! Physical constants taken from NIST 2010 CODATA values, and some from WolframAlpha (values provided as of 2009-06-23) |
---|
109 | //! http://physics.nist.gov/cuu/Constants |
---|
110 | //! http://www.wolframalpha.com |
---|
111 | //! See also http://en.wikipedia.org/wiki/Physical_constant |
---|
112 | |
---|
113 | |
---|
114 | template<typename eT> |
---|
115 | class Datum |
---|
116 | { |
---|
117 | public: |
---|
118 | |
---|
119 | static const eT pi; //!< ratio of any circle's circumference to its diameter |
---|
120 | static const eT e; //!< base of the natural logarithm |
---|
121 | static const eT euler; //!< Euler's constant, aka Euler-Mascheroni constant |
---|
122 | static const eT gratio; //!< golden ratio |
---|
123 | static const eT sqrt2; //!< square root of 2 |
---|
124 | static const eT eps; //!< the difference between 1 and the least value greater than 1 that is representable |
---|
125 | static const eT log_min; //!< log of the minimum representable value |
---|
126 | static const eT log_max; //!< log of the maximum representable value |
---|
127 | static const eT nan; //!< "not a number" |
---|
128 | static const eT inf; //!< infinity |
---|
129 | |
---|
130 | // |
---|
131 | |
---|
132 | static const eT m_u; //!< atomic mass constant (in kg) |
---|
133 | static const eT N_A; //!< Avogadro constant |
---|
134 | static const eT k; //!< Boltzmann constant (in joules per kelvin) |
---|
135 | static const eT k_evk; //!< Boltzmann constant (in eV/K) |
---|
136 | static const eT a_0; //!< Bohr radius (in meters) |
---|
137 | static const eT mu_B; //!< Bohr magneton |
---|
138 | static const eT Z_0; //!< characteristic impedance of vacuum (in ohms) |
---|
139 | static const eT G_0; //!< conductance quantum (in siemens) |
---|
140 | static const eT k_e; //!< Coulomb's constant (in meters per farad) |
---|
141 | static const eT eps_0; //!< electric constant (in farads per meter) |
---|
142 | static const eT m_e; //!< electron mass (in kg) |
---|
143 | static const eT eV; //!< electron volt (in joules) |
---|
144 | static const eT ec; //!< elementary charge (in coulombs) |
---|
145 | static const eT F; //!< Faraday constant (in coulombs) |
---|
146 | static const eT alpha; //!< fine-structure constant |
---|
147 | static const eT alpha_inv; //!< inverse fine-structure constant |
---|
148 | static const eT K_J; //!< Josephson constant |
---|
149 | static const eT mu_0; //!< magnetic constant (in henries per meter) |
---|
150 | static const eT phi_0; //!< magnetic flux quantum (in webers) |
---|
151 | static const eT R; //!< molar gas constant (in joules per mole kelvin) |
---|
152 | static const eT G; //!< Newtonian constant of gravitation (in newton square meters per kilogram squared) |
---|
153 | static const eT h; //!< Planck constant (in joule seconds) |
---|
154 | static const eT h_bar; //!< Planck constant over 2 pi, aka reduced Planck constant (in joule seconds) |
---|
155 | static const eT m_p; //!< proton mass (in kg) |
---|
156 | static const eT R_inf; //!< Rydberg constant (in reciprocal meters) |
---|
157 | static const eT c_0; //!< speed of light in vacuum (in meters per second) |
---|
158 | static const eT sigma; //!< Stefan-Boltzmann constant |
---|
159 | static const eT R_k; //!< von Klitzing constant (in ohms) |
---|
160 | static const eT b; //!< Wien wavelength displacement law constant |
---|
161 | }; |
---|
162 | |
---|
163 | |
---|
164 | // the long lengths of the constants are for future support of "long double" |
---|
165 | // and any smart compiler that does high-precision computation at compile-time |
---|
166 | |
---|
167 | template<typename eT> const eT Datum<eT>::pi = eT(3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679); |
---|
168 | template<typename eT> const eT Datum<eT>::e = eT(2.7182818284590452353602874713526624977572470936999595749669676277240766303535475945713821785251664274); |
---|
169 | template<typename eT> const eT Datum<eT>::euler = eT(0.5772156649015328606065120900824024310421593359399235988057672348848677267776646709369470632917467495); |
---|
170 | template<typename eT> const eT Datum<eT>::gratio = eT(1.6180339887498948482045868343656381177203091798057628621354486227052604628189024497072072041893911374); |
---|
171 | template<typename eT> const eT Datum<eT>::sqrt2 = eT(1.4142135623730950488016887242096980785696718753769480731766797379907324784621070388503875343276415727); |
---|
172 | template<typename eT> const eT Datum<eT>::eps = std::numeric_limits<eT>::epsilon(); |
---|
173 | template<typename eT> const eT Datum<eT>::log_min = std::log(std::numeric_limits<eT>::min()); |
---|
174 | template<typename eT> const eT Datum<eT>::log_max = std::log(std::numeric_limits<eT>::max()); |
---|
175 | template<typename eT> const eT Datum<eT>::nan = priv::Datum_helper::nan<eT>(); |
---|
176 | template<typename eT> const eT Datum<eT>::inf = priv::Datum_helper::inf<eT>(); |
---|
177 | |
---|
178 | template<typename eT> const eT Datum<eT>::m_u = eT(1.660538921e-27); |
---|
179 | template<typename eT> const eT Datum<eT>::N_A = eT(6.02214129e23); |
---|
180 | template<typename eT> const eT Datum<eT>::k = eT(1.3806488e-23); |
---|
181 | template<typename eT> const eT Datum<eT>::k_evk = eT(8.6173324e-5); |
---|
182 | template<typename eT> const eT Datum<eT>::a_0 = eT(0.52917721092e-10); |
---|
183 | template<typename eT> const eT Datum<eT>::mu_B = eT(927.400968e-26); |
---|
184 | template<typename eT> const eT Datum<eT>::Z_0 = eT(3.76730313461771e-2); |
---|
185 | template<typename eT> const eT Datum<eT>::G_0 = eT(7.7480917346e-5); |
---|
186 | template<typename eT> const eT Datum<eT>::k_e = eT(8.9875517873681764e9); |
---|
187 | template<typename eT> const eT Datum<eT>::eps_0 = eT(8.85418781762039e-12); |
---|
188 | template<typename eT> const eT Datum<eT>::m_e = eT(9.10938291e-31); |
---|
189 | template<typename eT> const eT Datum<eT>::eV = eT(1.602176565e-19); |
---|
190 | template<typename eT> const eT Datum<eT>::ec = eT(1.602176565e-19); |
---|
191 | template<typename eT> const eT Datum<eT>::F = eT(96485.3365); |
---|
192 | template<typename eT> const eT Datum<eT>::alpha = eT(7.2973525698e-3); |
---|
193 | template<typename eT> const eT Datum<eT>::alpha_inv = eT(137.035999074); |
---|
194 | template<typename eT> const eT Datum<eT>::K_J = eT(483597.870e9); |
---|
195 | template<typename eT> const eT Datum<eT>::mu_0 = eT(1.25663706143592e-06); |
---|
196 | template<typename eT> const eT Datum<eT>::phi_0 = eT(2.067833667e-15); |
---|
197 | template<typename eT> const eT Datum<eT>::R = eT(8.3144621); |
---|
198 | template<typename eT> const eT Datum<eT>::G = eT(6.67384e-11); |
---|
199 | template<typename eT> const eT Datum<eT>::h = eT(6.62606957e-34); |
---|
200 | template<typename eT> const eT Datum<eT>::h_bar = eT(1.054571726e-34); |
---|
201 | template<typename eT> const eT Datum<eT>::m_p = eT(1.672621777e-27); |
---|
202 | template<typename eT> const eT Datum<eT>::R_inf = eT(10973731.568539); |
---|
203 | template<typename eT> const eT Datum<eT>::c_0 = eT(299792458.0); |
---|
204 | template<typename eT> const eT Datum<eT>::sigma = eT(5.670373e-8); |
---|
205 | template<typename eT> const eT Datum<eT>::R_k = eT(25812.8074434); |
---|
206 | template<typename eT> const eT Datum<eT>::b = eT(2.8977721e-3); |
---|
207 | |
---|
208 | |
---|
209 | |
---|
210 | typedef Datum<float> fdatum; |
---|
211 | typedef Datum<double> datum; |
---|
212 | |
---|
213 | |
---|
214 | |
---|
215 | |
---|
216 | namespace priv |
---|
217 | { |
---|
218 | |
---|
219 | template<typename eT> |
---|
220 | static |
---|
221 | arma_inline |
---|
222 | arma_hot |
---|
223 | typename arma_real_only<eT>::result |
---|
224 | most_neg(typename arma_real_only<eT>::result* junk = 0) |
---|
225 | { |
---|
226 | arma_ignore(junk); |
---|
227 | |
---|
228 | if(std::numeric_limits<eT>::has_infinity == true) |
---|
229 | { |
---|
230 | return -(std::numeric_limits<eT>::infinity()); |
---|
231 | } |
---|
232 | else |
---|
233 | { |
---|
234 | return -(std::numeric_limits<eT>::max()); |
---|
235 | } |
---|
236 | } |
---|
237 | |
---|
238 | |
---|
239 | template<typename eT> |
---|
240 | static |
---|
241 | arma_inline |
---|
242 | arma_hot |
---|
243 | typename arma_integral_only<eT>::result |
---|
244 | most_neg(typename arma_integral_only<eT>::result* junk = 0) |
---|
245 | { |
---|
246 | arma_ignore(junk); |
---|
247 | |
---|
248 | return std::numeric_limits<eT>::min(); |
---|
249 | } |
---|
250 | |
---|
251 | |
---|
252 | template<typename eT> |
---|
253 | static |
---|
254 | arma_inline |
---|
255 | arma_hot |
---|
256 | typename arma_real_only<eT>::result |
---|
257 | most_pos(typename arma_real_only<eT>::result* junk = 0) |
---|
258 | { |
---|
259 | arma_ignore(junk); |
---|
260 | |
---|
261 | if(std::numeric_limits<eT>::has_infinity == true) |
---|
262 | { |
---|
263 | return std::numeric_limits<eT>::infinity(); |
---|
264 | } |
---|
265 | else |
---|
266 | { |
---|
267 | return std::numeric_limits<eT>::max(); |
---|
268 | } |
---|
269 | } |
---|
270 | |
---|
271 | |
---|
272 | template<typename eT> |
---|
273 | static |
---|
274 | arma_inline |
---|
275 | arma_hot |
---|
276 | typename arma_integral_only<eT>::result |
---|
277 | most_pos(typename arma_integral_only<eT>::result* junk = 0) |
---|
278 | { |
---|
279 | arma_ignore(junk); |
---|
280 | |
---|
281 | return std::numeric_limits<eT>::max(); |
---|
282 | } |
---|
283 | |
---|
284 | } |
---|
285 | |
---|
286 | |
---|
287 | |
---|
288 | //! @} |
---|