libstdc++
|
00001 // Math extensions -*- C++ -*- 00002 00003 // Copyright (C) 2013-2015 Free Software Foundation, Inc. 00004 // 00005 // This file is part of the GNU ISO C++ Library. This library is free 00006 // software; you can redistribute it and/or modify it under the 00007 // terms of the GNU General Public License as published by the 00008 // Free Software Foundation; either version 3, or (at your option) 00009 // any later version. 00010 00011 // This library is distributed in the hope that it will be useful, 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 // GNU General Public License for more details. 00015 00016 // Under Section 7 of GPL version 3, you are granted additional 00017 // permissions described in the GCC Runtime Library Exception, version 00018 // 3.1, as published by the Free Software Foundation. 00019 00020 // You should have received a copy of the GNU General Public License and 00021 // a copy of the GCC Runtime Library Exception along with this program; 00022 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 00023 // <http://www.gnu.org/licenses/>. 00024 00025 /** @file ext/cmath 00026 * This file is a GNU extension to the Standard C++ Library. 00027 */ 00028 00029 #ifndef _EXT_CMATH 00030 #define _EXT_CMATH 1 00031 00032 #pragma GCC system_header 00033 00034 #if __cplusplus < 201103L 00035 # include <bits/c++0x_warning.h> 00036 #else 00037 00038 #include <cmath> 00039 #include <type_traits> 00040 00041 namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) 00042 { 00043 _GLIBCXX_BEGIN_NAMESPACE_VERSION 00044 00045 // A class for math constants. 00046 template<typename _RealType> 00047 struct __math_constants 00048 { 00049 static_assert(std::is_floating_point<_RealType>::value, 00050 "template argument not a floating point type"); 00051 00052 // Constant @f$ \pi @f$. 00053 static constexpr _RealType __pi = 3.1415926535897932384626433832795029L; 00054 // Constant @f$ \pi / 2 @f$. 00055 static constexpr _RealType __pi_half = 1.5707963267948966192313216916397514L; 00056 // Constant @f$ \pi / 3 @f$. 00057 static constexpr _RealType __pi_third = 1.0471975511965977461542144610931676L; 00058 // Constant @f$ \pi / 4 @f$. 00059 static constexpr _RealType __pi_quarter = 0.7853981633974483096156608458198757L; 00060 // Constant @f$ \sqrt(\pi / 2) @f$. 00061 static constexpr _RealType __root_pi_div_2 = 1.2533141373155002512078826424055226L; 00062 // Constant @f$ 1 / \pi @f$. 00063 static constexpr _RealType __one_div_pi = 0.3183098861837906715377675267450287L; 00064 // Constant @f$ 2 / \pi @f$. 00065 static constexpr _RealType __two_div_pi = 0.6366197723675813430755350534900574L; 00066 // Constant @f$ 2 / \sqrt(\pi) @f$. 00067 static constexpr _RealType __two_div_root_pi = 1.1283791670955125738961589031215452L; 00068 00069 // Constant Euler's number @f$ e @f$. 00070 static constexpr _RealType __e = 2.7182818284590452353602874713526625L; 00071 // Constant @f$ 1 / e @f$. 00072 static constexpr _RealType __one_div_e = 0.36787944117144232159552377016146087L; 00073 // Constant @f$ \log_2(e) @f$. 00074 static constexpr _RealType __log2_e = 1.4426950408889634073599246810018921L; 00075 // Constant @f$ \log_10(e) @f$. 00076 static constexpr _RealType __log10_e = 0.4342944819032518276511289189166051L; 00077 // Constant @f$ \ln(2) @f$. 00078 static constexpr _RealType __ln_2 = 0.6931471805599453094172321214581766L; 00079 // Constant @f$ \ln(3) @f$. 00080 static constexpr _RealType __ln_3 = 1.0986122886681096913952452369225257L; 00081 // Constant @f$ \ln(10) @f$. 00082 static constexpr _RealType __ln_10 = 2.3025850929940456840179914546843642L; 00083 00084 // Constant Euler-Mascheroni @f$ \gamma_E @f$. 00085 static constexpr _RealType __gamma_e = 0.5772156649015328606065120900824024L; 00086 // Constant Golden Ratio @f$ \phi @f$. 00087 static constexpr _RealType __phi = 1.6180339887498948482045868343656381L; 00088 00089 // Constant @f$ \sqrt(2) @f$. 00090 static constexpr _RealType __root_2 = 1.4142135623730950488016887242096981L; 00091 // Constant @f$ \sqrt(3) @f$. 00092 static constexpr _RealType __root_3 = 1.7320508075688772935274463415058724L; 00093 // Constant @f$ \sqrt(5) @f$. 00094 static constexpr _RealType __root_5 = 2.2360679774997896964091736687312762L; 00095 // Constant @f$ \sqrt(7) @f$. 00096 static constexpr _RealType __root_7 = 2.6457513110645905905016157536392604L; 00097 // Constant @f$ 1 / \sqrt(2) @f$. 00098 static constexpr _RealType __one_div_root_2 = 0.7071067811865475244008443621048490L; 00099 }; 00100 00101 // And the template definitions for the constants. 00102 template<typename _RealType> 00103 constexpr _RealType __math_constants<_RealType>::__pi; 00104 template<typename _RealType> 00105 constexpr _RealType __math_constants<_RealType>::__pi_half; 00106 template<typename _RealType> 00107 constexpr _RealType __math_constants<_RealType>::__pi_third; 00108 template<typename _RealType> 00109 constexpr _RealType __math_constants<_RealType>::__pi_quarter; 00110 template<typename _RealType> 00111 constexpr _RealType __math_constants<_RealType>::__root_pi_div_2; 00112 template<typename _RealType> 00113 constexpr _RealType __math_constants<_RealType>::__one_div_pi; 00114 template<typename _RealType> 00115 constexpr _RealType __math_constants<_RealType>::__two_div_pi; 00116 template<typename _RealType> 00117 constexpr _RealType __math_constants<_RealType>::__two_div_root_pi; 00118 template<typename _RealType> 00119 constexpr _RealType __math_constants<_RealType>::__e; 00120 template<typename _RealType> 00121 constexpr _RealType __math_constants<_RealType>::__one_div_e; 00122 template<typename _RealType> 00123 constexpr _RealType __math_constants<_RealType>::__log2_e; 00124 template<typename _RealType> 00125 constexpr _RealType __math_constants<_RealType>::__log10_e; 00126 template<typename _RealType> 00127 constexpr _RealType __math_constants<_RealType>::__ln_2; 00128 template<typename _RealType> 00129 constexpr _RealType __math_constants<_RealType>::__ln_3; 00130 template<typename _RealType> 00131 constexpr _RealType __math_constants<_RealType>::__ln_10; 00132 template<typename _RealType> 00133 constexpr _RealType __math_constants<_RealType>::__gamma_e; 00134 template<typename _RealType> 00135 constexpr _RealType __math_constants<_RealType>::__phi; 00136 template<typename _RealType> 00137 constexpr _RealType __math_constants<_RealType>::__root_2; 00138 template<typename _RealType> 00139 constexpr _RealType __math_constants<_RealType>::__root_3; 00140 template<typename _RealType> 00141 constexpr _RealType __math_constants<_RealType>::__root_5; 00142 template<typename _RealType> 00143 constexpr _RealType __math_constants<_RealType>::__root_7; 00144 template<typename _RealType> 00145 constexpr _RealType __math_constants<_RealType>::__one_div_root_2; 00146 00147 _GLIBCXX_END_NAMESPACE_VERSION 00148 } // namespace __gnu_cxx 00149 00150 #endif // C++11 00151 00152 #endif // _EXT_CMATH