constants.hpp

Go to the documentation of this file.
00001 // Copyright (C) 2010 NICTA and the authors listed below
00002 // http://nicta.com.au
00003 // 
00004 // Authors:
00005 // - Conrad Sanderson (conradsand at ieee dot org)
00006 // 
00007 // This file is part of the Armadillo C++ library.
00008 // It is provided without any warranty of fitness
00009 // for any purpose. You can redistribute this file
00010 // and/or modify it under the terms of the GNU
00011 // Lesser General Public License (LGPL) as published
00012 // by the Free Software Foundation, either version 3
00013 // of the License or (at your option) any later version.
00014 // (see http://www.opensource.org/licenses for more info)
00015 
00016 
00017 //! \addtogroup constants
00018 //! @{
00019 
00020 
00021 // the long lengths of the constants are for future support of "long double"
00022 // and any smart compiler that does high-precision computation at compile-time
00023 
00024 template<typename eT>
00025 class Math
00026   {
00027   public:
00028   
00029   //! ratio of any circle's circumference to its diameter
00030   static const eT pi()        { return eT(3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679); }
00031   
00032   //! base of the natural logarithm
00033   static const eT e()         { return eT(2.7182818284590452353602874713526624977572470936999595749669676277240766303535475945713821785251664274); }
00034   
00035   //! Euler's constant, aka Euler-Mascheroni constant
00036   static const eT euler()     { return eT(0.5772156649015328606065120900824024310421593359399235988057672348848677267776646709369470632917467495); }
00037   
00038   //! golden ratio
00039   static const eT gratio()    { return eT(1.6180339887498948482045868343656381177203091798057628621354486227052604628189024497072072041893911374); }
00040   
00041   //! square root of 2
00042   static const eT sqrt2()     { return eT(1.4142135623730950488016887242096980785696718753769480731766797379907324784621070388503875343276415727); }
00043   
00044   //! the difference between 1 and the least value greater than 1 that is representable
00045   static const eT eps()       { return std::numeric_limits<eT>::epsilon(); }
00046   
00047   //! log of the minimum representable value
00048   static const eT log_min()   { static const eT out = std::log(std::numeric_limits<eT>::min()); return out; }
00049     
00050   //! log of the maximum representable value
00051   static const eT log_max()   { static const eT out = std::log(std::numeric_limits<eT>::max()); return out; }
00052   };
00053 
00054 
00055 
00056 //! Physical constants taken from NIST and WolframAlpha on 2009-06-23
00057 //! http://physics.nist.gov/cuu/Constants
00058 //! http://www.wolframalpha.com
00059 //! See also http://en.wikipedia.org/wiki/Physical_constant
00060 template<typename eT>
00061 class Phy
00062   {
00063   public:
00064 
00065   //! atomic mass constant (in kg)
00066   static const eT m_u()       {  return eT(1.660538782e-27); }
00067 
00068   //! Avogadro constant
00069   static const eT N_A()       {  return eT(6.02214179e23); }
00070 
00071   //! Boltzmann constant (in joules per kelvin)
00072   static const eT k()         {  return eT(1.3806504e-23); }
00073 
00074   //! Boltzmann constant (in eV/K)
00075   static const eT k_evk()     {  return eT(8.617343e-5); }
00076 
00077   //! Bohr radius (in meters)
00078   static const eT a_0()       { return eT(0.52917720859e-10); }
00079 
00080   //! Bohr magneton
00081   static const eT mu_B()      { return(927.400915e-26); }
00082 
00083   //! characteristic impedance of vacuum (in ohms)
00084   static const eT Z_0()       { return eT(3.76730313461771e-2); }
00085 
00086   //! conductance quantum (in siemens)
00087   static const eT G_0()       { return eT(7.7480917004e-5); }
00088 
00089   //! Coulomb's constant (in meters per farad)
00090   static const eT k_e()       { return eT(8.9875517873681764e9); }
00091 
00092   //! electric constant (in farads per meter)
00093   static const eT eps_0()     { return eT(8.85418781762039e-12); }
00094 
00095   //! electron mass (in kg)
00096   static const eT m_e()       { return eT(9.10938215e-31); }
00097 
00098   //! electron volt (in joules)
00099   static const eT eV()        { return eT(1.602176487e-19); }
00100 
00101   //! elementary charge (in coulombs)
00102   static const eT e()         { return eT(1.602176487e-19); }
00103   
00104   //! Faraday constant (in coulombs)
00105   static const eT F()         { return eT(96485.3399); }
00106 
00107   //! fine-structure constant
00108   static const eT alpha()     { return eT(7.2973525376e-3); }
00109 
00110   //! inverse fine-structure constant
00111   static const eT alpha_inv() { return eT(137.035999679); }
00112 
00113   //! Josephson constant
00114   static const eT K_J()       { return eT(483597.891e9); }
00115 
00116   //! magnetic constant (in henries per meter)
00117   static const eT mu_0()      { return eT(1.25663706143592e-06); }
00118 
00119   //! magnetic flux quantum (in webers)
00120   static const eT phi_0()     { return eT(2.067833667e-15); }
00121 
00122   //! molar gas constant (in joules per mole kelvin)
00123   static const eT R()         { return eT(8.314472); }
00124 
00125   //! Newtonian constant of gravitation (in newton square meters per kilogram squared)
00126   static const eT G()         { return eT(6.67428e-11); }
00127 
00128   //! Planck constant (in joule seconds)
00129   static const eT h()         { return eT(6.62606896e-34); }
00130 
00131   //! Planck constant over 2 pi, aka reduced Planck constant (in joule seconds)
00132   static const eT h_bar()     { return eT(1.054571628e-34); }
00133 
00134   //! proton mass (in kg)
00135   static const eT m_p()       { return eT(1.672621637e-27); }
00136 
00137   //! Rydberg constant (in reciprocal meters)
00138   static const eT R_inf()     { return eT(10973731.568527); }
00139 
00140   //! speed of light in vacuum (in meters per second)
00141   static const eT c_0()       { return eT(299792458.0); }
00142 
00143   //! Stefan-Boltzmann constant
00144   static const eT sigma()     { return eT(5.670400e-8); }
00145 
00146   //! von Klitzing constant (in ohms)
00147   static const eT R_k()       { return eT(25812.807557); }
00148 
00149   //! Wien wavelength displacement law constant
00150   static const eT b()         { return eT(2.8977685e-3); }
00151   };
00152 
00153 
00154 
00155 typedef Math<float>  fmath;
00156 typedef Math<double> math;
00157 
00158 typedef Phy<float>   fphy;
00159 typedef Phy<double>  phy;
00160 
00161 
00162 
00163 //! @}