constants.hpp
Go to the documentation of this file.
00001 // Copyright (C) 2008-2011 NICTA (www.nicta.com.au)
00002 // Copyright (C) 2008-2011 Conrad Sanderson
00003 // 
00004 // This file is part of the Armadillo C++ library.
00005 // It is provided without any warranty of fitness
00006 // for any purpose. You can redistribute this file
00007 // and/or modify it under the terms of the GNU
00008 // Lesser General Public License (LGPL) as published
00009 // by the Free Software Foundation, either version 3
00010 // of the License or (at your option) any later version.
00011 // (see http://www.opensource.org/licenses for more info)
00012 
00013 
00016 
00017 
00018 namespace priv
00019   {
00020   class Math_helper
00021     {
00022     public:
00023     
00024     template<typename eT>
00025     static
00026     typename arma_float_only<eT>::result
00027     nan(typename arma_float_only<eT>::result* junk = 0)
00028       {
00029       arma_ignore(junk);
00030       
00031       if(std::numeric_limits<eT>::has_quiet_NaN == true)
00032         {
00033         return std::numeric_limits<eT>::quiet_NaN();
00034         }
00035       else
00036         {
00037         return eT(0);
00038         }
00039       }
00040     
00041     
00042     template<typename eT>
00043     static
00044     typename arma_cx_only<eT>::result
00045     nan(typename arma_cx_only<eT>::result* junk = 0)
00046       {
00047       arma_ignore(junk);
00048       
00049       typedef typename get_pod_type<eT>::result T;
00050       
00051       return eT( Math_helper::nan<T>(), Math_helper::nan<T>() );
00052       }
00053     
00054     
00055     template<typename eT>
00056     static
00057     typename arma_integral_only<eT>::result
00058     nan(typename arma_integral_only<eT>::result* junk = 0)
00059       {
00060       arma_ignore(junk);
00061       
00062       return eT(0);
00063       }
00064     
00065     
00066     template<typename eT>
00067     static
00068     typename arma_float_only<eT>::result
00069     inf(typename arma_float_only<eT>::result* junk = 0)
00070       {
00071       arma_ignore(junk);
00072       
00073       if(std::numeric_limits<eT>::has_infinity == true)
00074         {
00075         return std::numeric_limits<eT>::infinity();
00076         }
00077       else
00078         {
00079         return std::numeric_limits<eT>::max();
00080         }
00081       }
00082     
00083     
00084     template<typename eT>
00085     static
00086     typename arma_cx_only<eT>::result
00087     inf(typename arma_cx_only<eT>::result* junk = 0)
00088       {
00089       arma_ignore(junk);
00090       
00091       typedef typename get_pod_type<eT>::result T;
00092       
00093       return eT( Math_helper::inf<T>(), Math_helper::inf<T>() );
00094       }
00095     
00096 
00097     template<typename eT>
00098     static
00099     typename arma_integral_only<eT>::result
00100     inf(typename arma_integral_only<eT>::result* junk = 0)
00101       {
00102       arma_ignore(junk);
00103       
00104       return std::numeric_limits<eT>::max();
00105       }
00106     
00107     };
00108   }
00109 
00110 
00111 
00112 template<typename eT>
00113 class Math
00114   {
00115   public:
00116   
00117   // the long lengths of the constants are for future support of "long double"
00118   // and any smart compiler that does high-precision computation at compile-time
00119   
00121   static eT pi()        { return eT(3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679); }
00122   
00124   static eT e()         { return eT(2.7182818284590452353602874713526624977572470936999595749669676277240766303535475945713821785251664274); }
00125   
00127   static eT euler()     { return eT(0.5772156649015328606065120900824024310421593359399235988057672348848677267776646709369470632917467495); }
00128   
00130   static eT gratio()    { return eT(1.6180339887498948482045868343656381177203091798057628621354486227052604628189024497072072041893911374); }
00131   
00133   static eT sqrt2()     { return eT(1.4142135623730950488016887242096980785696718753769480731766797379907324784621070388503875343276415727); }
00134   
00136   static eT eps()       { return std::numeric_limits<eT>::epsilon(); }
00137   
00139   static eT log_min()   { static const eT out = std::log(std::numeric_limits<eT>::min()); return out; }
00140     
00142   static eT log_max()   { static const eT out = std::log(std::numeric_limits<eT>::max()); return out; }
00143   
00145   static eT nan()       { return priv::Math_helper::nan<eT>(); }
00146   
00148   static eT inf()       { return priv::Math_helper::inf<eT>(); }
00149   };
00150 
00151 
00152 
00157 template<typename eT>
00158 class Phy
00159   {
00160   public:
00161   
00163   static eT m_u()       {  return eT(1.660538782e-27); }
00164   
00166   static eT N_A()       {  return eT(6.02214179e23); }
00167   
00169   static eT k()         {  return eT(1.3806504e-23); }
00170   
00172   static eT k_evk()     {  return eT(8.617343e-5); }
00173   
00175   static eT a_0()       { return eT(0.52917720859e-10); }
00176   
00178   static eT mu_B()      { return(927.400915e-26); }
00179   
00181   static eT Z_0()       { return eT(3.76730313461771e-2); }
00182   
00184   static eT G_0()       { return eT(7.7480917004e-5); }
00185   
00187   static eT k_e()       { return eT(8.9875517873681764e9); }
00188   
00190   static eT eps_0()     { return eT(8.85418781762039e-12); }
00191   
00193   static eT m_e()       { return eT(9.10938215e-31); }
00194   
00196   static eT eV()        { return eT(1.602176487e-19); }
00197   
00199   static eT e()         { return eT(1.602176487e-19); }
00200   
00202   static eT F()         { return eT(96485.3399); }
00203   
00205   static eT alpha()     { return eT(7.2973525376e-3); }
00206   
00208   static eT alpha_inv() { return eT(137.035999679); }
00209   
00211   static eT K_J()       { return eT(483597.891e9); }
00212   
00214   static eT mu_0()      { return eT(1.25663706143592e-06); }
00215   
00217   static eT phi_0()     { return eT(2.067833667e-15); }
00218   
00220   static eT R()         { return eT(8.314472); }
00221   
00223   static eT G()         { return eT(6.67428e-11); }
00224   
00226   static eT h()         { return eT(6.62606896e-34); }
00227   
00229   static eT h_bar()     { return eT(1.054571628e-34); }
00230   
00232   static eT m_p()       { return eT(1.672621637e-27); }
00233   
00235   static eT R_inf()     { return eT(10973731.568527); }
00236   
00238   static eT c_0()       { return eT(299792458.0); }
00239   
00241   static eT sigma()     { return eT(5.670400e-8); }
00242   
00244   static eT R_k()       { return eT(25812.807557); }
00245   
00247   static eT b()         { return eT(2.8977685e-3); }
00248   };
00249 
00250 
00251 
00252 typedef Math<float>  fmath;
00253 typedef Math<double> math;
00254 
00255 typedef Phy<float>   fphy;
00256 typedef Phy<double>  phy;
00257 
00258 
00259 
00260 namespace priv
00261   {
00262   
00263   template<typename eT>
00264   static
00265   arma_inline
00266   arma_hot
00267   typename arma_float_only<eT>::result
00268   most_neg(typename arma_float_only<eT>::result* junk = 0)
00269     {
00270     arma_ignore(junk);
00271     
00272     if(std::numeric_limits<eT>::has_infinity == true)
00273       {
00274       return -(std::numeric_limits<eT>::infinity());
00275       }
00276     else
00277       {
00278       return -(std::numeric_limits<eT>::max());
00279       }
00280     }
00281   
00282   
00283   template<typename eT>
00284   static
00285   arma_inline
00286   arma_hot
00287   typename arma_integral_only<eT>::result
00288   most_neg(typename arma_integral_only<eT>::result* junk = 0)
00289     {
00290     arma_ignore(junk);
00291     
00292     return std::numeric_limits<eT>::min();
00293     }
00294   
00295   
00296   template<typename eT>
00297   static
00298   arma_inline
00299   arma_hot
00300   typename arma_float_only<eT>::result
00301   most_pos(typename arma_float_only<eT>::result* junk = 0)
00302     {
00303     arma_ignore(junk);
00304     
00305     if(std::numeric_limits<eT>::has_infinity == true)
00306       {
00307       return std::numeric_limits<eT>::infinity();
00308       }
00309     else
00310       {
00311       return std::numeric_limits<eT>::max();
00312       }
00313     }
00314   
00315   
00316   template<typename eT>
00317   static
00318   arma_inline
00319   arma_hot
00320   typename arma_integral_only<eT>::result
00321   most_pos(typename arma_integral_only<eT>::result* junk = 0)
00322     {
00323     arma_ignore(junk);
00324     
00325     return std::numeric_limits<eT>::max();
00326     }
00327 
00328   }
00329 
00330 
00331 


armadillo_matrix
Author(s): Conrad Sanderson - NICTA (www.nicta.com.au), (Wrapper by Sjoerd van den Dries)
autogenerated on Tue Jan 7 2014 11:42:03