max@0: // Copyright (C) 2008-2011 NICTA (www.nicta.com.au) max@0: // Copyright (C) 2008-2011 Conrad Sanderson max@0: // max@0: // This file is part of the Armadillo C++ library. max@0: // It is provided without any warranty of fitness max@0: // for any purpose. You can redistribute this file max@0: // and/or modify it under the terms of the GNU max@0: // Lesser General Public License (LGPL) as published max@0: // by the Free Software Foundation, either version 3 max@0: // of the License or (at your option) any later version. max@0: // (see http://www.opensource.org/licenses for more info) max@0: max@0: max@0: //! \addtogroup constants max@0: //! @{ max@0: max@0: max@0: namespace priv max@0: { max@0: class Math_helper max@0: { max@0: public: max@0: max@0: template max@0: static max@0: typename arma_float_only::result max@0: nan(typename arma_float_only::result* junk = 0) max@0: { max@0: arma_ignore(junk); max@0: max@0: if(std::numeric_limits::has_quiet_NaN == true) max@0: { max@0: return std::numeric_limits::quiet_NaN(); max@0: } max@0: else max@0: { max@0: return eT(0); max@0: } max@0: } max@0: max@0: max@0: template max@0: static max@0: typename arma_cx_only::result max@0: nan(typename arma_cx_only::result* junk = 0) max@0: { max@0: arma_ignore(junk); max@0: max@0: typedef typename get_pod_type::result T; max@0: max@0: return eT( Math_helper::nan(), Math_helper::nan() ); max@0: } max@0: max@0: max@0: template max@0: static max@0: typename arma_integral_only::result max@0: nan(typename arma_integral_only::result* junk = 0) max@0: { max@0: arma_ignore(junk); max@0: max@0: return eT(0); max@0: } max@0: max@0: max@0: template max@0: static max@0: typename arma_float_only::result max@0: inf(typename arma_float_only::result* junk = 0) max@0: { max@0: arma_ignore(junk); max@0: max@0: if(std::numeric_limits::has_infinity == true) max@0: { max@0: return std::numeric_limits::infinity(); max@0: } max@0: else max@0: { max@0: return std::numeric_limits::max(); max@0: } max@0: } max@0: max@0: max@0: template max@0: static max@0: typename arma_cx_only::result max@0: inf(typename arma_cx_only::result* junk = 0) max@0: { max@0: arma_ignore(junk); max@0: max@0: typedef typename get_pod_type::result T; max@0: max@0: return eT( Math_helper::inf(), Math_helper::inf() ); max@0: } max@0: max@0: max@0: template max@0: static max@0: typename arma_integral_only::result max@0: inf(typename arma_integral_only::result* junk = 0) max@0: { max@0: arma_ignore(junk); max@0: max@0: return std::numeric_limits::max(); max@0: } max@0: max@0: }; max@0: } max@0: max@0: max@0: max@0: template max@0: class Math max@0: { max@0: public: max@0: max@0: // the long lengths of the constants are for future support of "long double" max@0: // and any smart compiler that does high-precision computation at compile-time max@0: max@0: //! ratio of any circle's circumference to its diameter max@0: static eT pi() { return eT(3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679); } max@0: max@0: //! base of the natural logarithm max@0: static eT e() { return eT(2.7182818284590452353602874713526624977572470936999595749669676277240766303535475945713821785251664274); } max@0: max@0: //! Euler's constant, aka Euler-Mascheroni constant max@0: static eT euler() { return eT(0.5772156649015328606065120900824024310421593359399235988057672348848677267776646709369470632917467495); } max@0: max@0: //! golden ratio max@0: static eT gratio() { return eT(1.6180339887498948482045868343656381177203091798057628621354486227052604628189024497072072041893911374); } max@0: max@0: //! square root of 2 max@0: static eT sqrt2() { return eT(1.4142135623730950488016887242096980785696718753769480731766797379907324784621070388503875343276415727); } max@0: max@0: //! the difference between 1 and the least value greater than 1 that is representable max@0: static eT eps() { return std::numeric_limits::epsilon(); } max@0: max@0: //! log of the minimum representable value max@0: static eT log_min() { static const eT out = std::log(std::numeric_limits::min()); return out; } max@0: max@0: //! log of the maximum representable value max@0: static eT log_max() { static const eT out = std::log(std::numeric_limits::max()); return out; } max@0: max@0: //! "not a number" max@0: static eT nan() { return priv::Math_helper::nan(); } max@0: max@0: //! infinity max@0: static eT inf() { return priv::Math_helper::inf(); } max@0: }; max@0: max@0: max@0: max@0: //! Physical constants taken from NIST and WolframAlpha on 2009-06-23 max@0: //! http://physics.nist.gov/cuu/Constants max@0: //! http://www.wolframalpha.com max@0: //! See also http://en.wikipedia.org/wiki/Physical_constant max@0: template max@0: class Phy max@0: { max@0: public: max@0: max@0: //! atomic mass constant (in kg) max@0: static eT m_u() { return eT(1.660538782e-27); } max@0: max@0: //! Avogadro constant max@0: static eT N_A() { return eT(6.02214179e23); } max@0: max@0: //! Boltzmann constant (in joules per kelvin) max@0: static eT k() { return eT(1.3806504e-23); } max@0: max@0: //! Boltzmann constant (in eV/K) max@0: static eT k_evk() { return eT(8.617343e-5); } max@0: max@0: //! Bohr radius (in meters) max@0: static eT a_0() { return eT(0.52917720859e-10); } max@0: max@0: //! Bohr magneton max@0: static eT mu_B() { return eT(927.400915e-26); } max@0: max@0: //! characteristic impedance of vacuum (in ohms) max@0: static eT Z_0() { return eT(3.76730313461771e-2); } max@0: max@0: //! conductance quantum (in siemens) max@0: static eT G_0() { return eT(7.7480917004e-5); } max@0: max@0: //! Coulomb's constant (in meters per farad) max@0: static eT k_e() { return eT(8.9875517873681764e9); } max@0: max@0: //! electric constant (in farads per meter) max@0: static eT eps_0() { return eT(8.85418781762039e-12); } max@0: max@0: //! electron mass (in kg) max@0: static eT m_e() { return eT(9.10938215e-31); } max@0: max@0: //! electron volt (in joules) max@0: static eT eV() { return eT(1.602176487e-19); } max@0: max@0: //! elementary charge (in coulombs) max@0: static eT e() { return eT(1.602176487e-19); } max@0: max@0: //! Faraday constant (in coulombs) max@0: static eT F() { return eT(96485.3399); } max@0: max@0: //! fine-structure constant max@0: static eT alpha() { return eT(7.2973525376e-3); } max@0: max@0: //! inverse fine-structure constant max@0: static eT alpha_inv() { return eT(137.035999679); } max@0: max@0: //! Josephson constant max@0: static eT K_J() { return eT(483597.891e9); } max@0: max@0: //! magnetic constant (in henries per meter) max@0: static eT mu_0() { return eT(1.25663706143592e-06); } max@0: max@0: //! magnetic flux quantum (in webers) max@0: static eT phi_0() { return eT(2.067833667e-15); } max@0: max@0: //! molar gas constant (in joules per mole kelvin) max@0: static eT R() { return eT(8.314472); } max@0: max@0: //! Newtonian constant of gravitation (in newton square meters per kilogram squared) max@0: static eT G() { return eT(6.67428e-11); } max@0: max@0: //! Planck constant (in joule seconds) max@0: static eT h() { return eT(6.62606896e-34); } max@0: max@0: //! Planck constant over 2 pi, aka reduced Planck constant (in joule seconds) max@0: static eT h_bar() { return eT(1.054571628e-34); } max@0: max@0: //! proton mass (in kg) max@0: static eT m_p() { return eT(1.672621637e-27); } max@0: max@0: //! Rydberg constant (in reciprocal meters) max@0: static eT R_inf() { return eT(10973731.568527); } max@0: max@0: //! speed of light in vacuum (in meters per second) max@0: static eT c_0() { return eT(299792458.0); } max@0: max@0: //! Stefan-Boltzmann constant max@0: static eT sigma() { return eT(5.670400e-8); } max@0: max@0: //! von Klitzing constant (in ohms) max@0: static eT R_k() { return eT(25812.807557); } max@0: max@0: //! Wien wavelength displacement law constant max@0: static eT b() { return eT(2.8977685e-3); } max@0: }; max@0: max@0: max@0: max@0: typedef Math fmath; max@0: typedef Math math; max@0: max@0: typedef Phy fphy; max@0: typedef Phy phy; max@0: max@0: max@0: max@0: namespace priv max@0: { max@0: max@0: template max@0: static max@0: arma_inline max@0: arma_hot max@0: typename arma_float_only::result max@0: most_neg(typename arma_float_only::result* junk = 0) max@0: { max@0: arma_ignore(junk); max@0: max@0: if(std::numeric_limits::has_infinity == true) max@0: { max@0: return -(std::numeric_limits::infinity()); max@0: } max@0: else max@0: { max@0: return -(std::numeric_limits::max()); max@0: } max@0: } max@0: max@0: max@0: template max@0: static max@0: arma_inline max@0: arma_hot max@0: typename arma_integral_only::result max@0: most_neg(typename arma_integral_only::result* junk = 0) max@0: { max@0: arma_ignore(junk); max@0: max@0: return std::numeric_limits::min(); max@0: } max@0: max@0: max@0: template max@0: static max@0: arma_inline max@0: arma_hot max@0: typename arma_float_only::result max@0: most_pos(typename arma_float_only::result* junk = 0) max@0: { max@0: arma_ignore(junk); max@0: max@0: if(std::numeric_limits::has_infinity == true) max@0: { max@0: return std::numeric_limits::infinity(); max@0: } max@0: else max@0: { max@0: return std::numeric_limits::max(); max@0: } max@0: } max@0: max@0: max@0: template max@0: static max@0: arma_inline max@0: arma_hot max@0: typename arma_integral_only::result max@0: most_pos(typename arma_integral_only::result* junk = 0) max@0: { max@0: arma_ignore(junk); max@0: max@0: return std::numeric_limits::max(); max@0: } max@0: max@0: } max@0: max@0: max@0: max@0: //! @}