xref: /dflybsd-src/contrib/gcc-8.0/libstdc++-v3/include/ext/cmath (revision 38fd149817dfbff97799f62fcb70be98c4e32523)
1*38fd1498Szrj// Math extensions -*- C++ -*-
2*38fd1498Szrj
3*38fd1498Szrj// Copyright (C) 2013-2018 Free Software Foundation, Inc.
4*38fd1498Szrj//
5*38fd1498Szrj// This file is part of the GNU ISO C++ Library.  This library is free
6*38fd1498Szrj// software; you can redistribute it and/or modify it under the
7*38fd1498Szrj// terms of the GNU General Public License as published by the
8*38fd1498Szrj// Free Software Foundation; either version 3, or (at your option)
9*38fd1498Szrj// any later version.
10*38fd1498Szrj
11*38fd1498Szrj// This library is distributed in the hope that it will be useful,
12*38fd1498Szrj// but WITHOUT ANY WARRANTY; without even the implied warranty of
13*38fd1498Szrj// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14*38fd1498Szrj// GNU General Public License for more details.
15*38fd1498Szrj
16*38fd1498Szrj// Under Section 7 of GPL version 3, you are granted additional
17*38fd1498Szrj// permissions described in the GCC Runtime Library Exception, version
18*38fd1498Szrj// 3.1, as published by the Free Software Foundation.
19*38fd1498Szrj
20*38fd1498Szrj// You should have received a copy of the GNU General Public License and
21*38fd1498Szrj// a copy of the GCC Runtime Library Exception along with this program;
22*38fd1498Szrj// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
23*38fd1498Szrj// <http://www.gnu.org/licenses/>.
24*38fd1498Szrj
25*38fd1498Szrj/** @file ext/cmath
26*38fd1498Szrj *  This file is a GNU extension to the Standard C++ Library.
27*38fd1498Szrj */
28*38fd1498Szrj
29*38fd1498Szrj#ifndef _EXT_CMATH
30*38fd1498Szrj#define _EXT_CMATH 1
31*38fd1498Szrj
32*38fd1498Szrj#pragma GCC system_header
33*38fd1498Szrj
34*38fd1498Szrj#if __cplusplus < 201103L
35*38fd1498Szrj# include <bits/c++0x_warning.h>
36*38fd1498Szrj#else
37*38fd1498Szrj
38*38fd1498Szrj#include <cmath>
39*38fd1498Szrj#include <type_traits>
40*38fd1498Szrj
41*38fd1498Szrjnamespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
42*38fd1498Szrj{
43*38fd1498Szrj_GLIBCXX_BEGIN_NAMESPACE_VERSION
44*38fd1498Szrj
45*38fd1498Szrj  // A class for math constants.
46*38fd1498Szrj  template<typename _RealType>
47*38fd1498Szrj    struct __math_constants
48*38fd1498Szrj    {
49*38fd1498Szrj      static_assert(std::is_floating_point<_RealType>::value,
50*38fd1498Szrj		    "template argument not a floating point type");
51*38fd1498Szrj
52*38fd1498Szrj      // Constant @f$ \pi @f$.
53*38fd1498Szrj      static constexpr _RealType __pi = 3.1415926535897932384626433832795029L;
54*38fd1498Szrj      // Constant @f$ \pi / 2 @f$.
55*38fd1498Szrj      static constexpr _RealType __pi_half = 1.5707963267948966192313216916397514L;
56*38fd1498Szrj      // Constant @f$ \pi / 3 @f$.
57*38fd1498Szrj      static constexpr _RealType __pi_third = 1.0471975511965977461542144610931676L;
58*38fd1498Szrj      // Constant @f$ \pi / 4 @f$.
59*38fd1498Szrj      static constexpr _RealType __pi_quarter = 0.7853981633974483096156608458198757L;
60*38fd1498Szrj      // Constant @f$ \sqrt(\pi / 2) @f$.
61*38fd1498Szrj      static constexpr _RealType __root_pi_div_2 = 1.2533141373155002512078826424055226L;
62*38fd1498Szrj      // Constant @f$ 1 / \pi @f$.
63*38fd1498Szrj      static constexpr _RealType __one_div_pi = 0.3183098861837906715377675267450287L;
64*38fd1498Szrj      // Constant @f$ 2 / \pi @f$.
65*38fd1498Szrj      static constexpr _RealType __two_div_pi = 0.6366197723675813430755350534900574L;
66*38fd1498Szrj      // Constant @f$ 2 / \sqrt(\pi) @f$.
67*38fd1498Szrj      static constexpr _RealType __two_div_root_pi = 1.1283791670955125738961589031215452L;
68*38fd1498Szrj
69*38fd1498Szrj      // Constant Euler's number @f$ e @f$.
70*38fd1498Szrj      static constexpr _RealType __e = 2.7182818284590452353602874713526625L;
71*38fd1498Szrj      // Constant @f$ 1 / e @f$.
72*38fd1498Szrj      static constexpr _RealType __one_div_e = 0.36787944117144232159552377016146087L;
73*38fd1498Szrj      // Constant @f$ \log_2(e) @f$.
74*38fd1498Szrj      static constexpr _RealType __log2_e = 1.4426950408889634073599246810018921L;
75*38fd1498Szrj      // Constant @f$ \log_10(e) @f$.
76*38fd1498Szrj      static constexpr _RealType __log10_e = 0.4342944819032518276511289189166051L;
77*38fd1498Szrj      // Constant @f$ \ln(2) @f$.
78*38fd1498Szrj      static constexpr _RealType __ln_2 = 0.6931471805599453094172321214581766L;
79*38fd1498Szrj      // Constant @f$ \ln(3) @f$.
80*38fd1498Szrj      static constexpr _RealType __ln_3 = 1.0986122886681096913952452369225257L;
81*38fd1498Szrj      // Constant @f$ \ln(10) @f$.
82*38fd1498Szrj      static constexpr _RealType __ln_10 = 2.3025850929940456840179914546843642L;
83*38fd1498Szrj
84*38fd1498Szrj      // Constant Euler-Mascheroni @f$ \gamma_E @f$.
85*38fd1498Szrj      static constexpr _RealType __gamma_e = 0.5772156649015328606065120900824024L;
86*38fd1498Szrj      // Constant Golden Ratio @f$ \phi @f$.
87*38fd1498Szrj      static constexpr _RealType __phi = 1.6180339887498948482045868343656381L;
88*38fd1498Szrj
89*38fd1498Szrj      // Constant @f$ \sqrt(2) @f$.
90*38fd1498Szrj      static constexpr _RealType __root_2 = 1.4142135623730950488016887242096981L;
91*38fd1498Szrj      // Constant @f$ \sqrt(3) @f$.
92*38fd1498Szrj      static constexpr _RealType __root_3 = 1.7320508075688772935274463415058724L;
93*38fd1498Szrj      // Constant @f$ \sqrt(5) @f$.
94*38fd1498Szrj      static constexpr _RealType __root_5 = 2.2360679774997896964091736687312762L;
95*38fd1498Szrj      // Constant @f$ \sqrt(7) @f$.
96*38fd1498Szrj      static constexpr _RealType __root_7 = 2.6457513110645905905016157536392604L;
97*38fd1498Szrj      // Constant @f$ 1 / \sqrt(2) @f$.
98*38fd1498Szrj      static constexpr _RealType __one_div_root_2 = 0.7071067811865475244008443621048490L;
99*38fd1498Szrj    };
100*38fd1498Szrj
101*38fd1498Szrj  // And the template definitions for the constants.
102*38fd1498Szrj  template<typename _RealType>
103*38fd1498Szrj    constexpr _RealType __math_constants<_RealType>::__pi;
104*38fd1498Szrj  template<typename _RealType>
105*38fd1498Szrj    constexpr _RealType __math_constants<_RealType>::__pi_half;
106*38fd1498Szrj  template<typename _RealType>
107*38fd1498Szrj    constexpr _RealType __math_constants<_RealType>::__pi_third;
108*38fd1498Szrj  template<typename _RealType>
109*38fd1498Szrj    constexpr _RealType __math_constants<_RealType>::__pi_quarter;
110*38fd1498Szrj  template<typename _RealType>
111*38fd1498Szrj    constexpr _RealType __math_constants<_RealType>::__root_pi_div_2;
112*38fd1498Szrj  template<typename _RealType>
113*38fd1498Szrj    constexpr _RealType __math_constants<_RealType>::__one_div_pi;
114*38fd1498Szrj  template<typename _RealType>
115*38fd1498Szrj    constexpr _RealType __math_constants<_RealType>::__two_div_pi;
116*38fd1498Szrj  template<typename _RealType>
117*38fd1498Szrj    constexpr _RealType __math_constants<_RealType>::__two_div_root_pi;
118*38fd1498Szrj  template<typename _RealType>
119*38fd1498Szrj    constexpr _RealType __math_constants<_RealType>::__e;
120*38fd1498Szrj  template<typename _RealType>
121*38fd1498Szrj    constexpr _RealType __math_constants<_RealType>::__one_div_e;
122*38fd1498Szrj  template<typename _RealType>
123*38fd1498Szrj    constexpr _RealType __math_constants<_RealType>::__log2_e;
124*38fd1498Szrj  template<typename _RealType>
125*38fd1498Szrj    constexpr _RealType __math_constants<_RealType>::__log10_e;
126*38fd1498Szrj  template<typename _RealType>
127*38fd1498Szrj    constexpr _RealType __math_constants<_RealType>::__ln_2;
128*38fd1498Szrj  template<typename _RealType>
129*38fd1498Szrj    constexpr _RealType __math_constants<_RealType>::__ln_3;
130*38fd1498Szrj  template<typename _RealType>
131*38fd1498Szrj    constexpr _RealType __math_constants<_RealType>::__ln_10;
132*38fd1498Szrj  template<typename _RealType>
133*38fd1498Szrj    constexpr _RealType __math_constants<_RealType>::__gamma_e;
134*38fd1498Szrj  template<typename _RealType>
135*38fd1498Szrj    constexpr _RealType __math_constants<_RealType>::__phi;
136*38fd1498Szrj  template<typename _RealType>
137*38fd1498Szrj    constexpr _RealType __math_constants<_RealType>::__root_2;
138*38fd1498Szrj  template<typename _RealType>
139*38fd1498Szrj    constexpr _RealType __math_constants<_RealType>::__root_3;
140*38fd1498Szrj  template<typename _RealType>
141*38fd1498Szrj    constexpr _RealType __math_constants<_RealType>::__root_5;
142*38fd1498Szrj  template<typename _RealType>
143*38fd1498Szrj    constexpr _RealType __math_constants<_RealType>::__root_7;
144*38fd1498Szrj  template<typename _RealType>
145*38fd1498Szrj    constexpr _RealType __math_constants<_RealType>::__one_div_root_2;
146*38fd1498Szrj
147*38fd1498Szrj_GLIBCXX_END_NAMESPACE_VERSION
148*38fd1498Szrj} // namespace __gnu_cxx
149*38fd1498Szrj
150*38fd1498Szrj#endif // C++11
151*38fd1498Szrj
152*38fd1498Szrj#endif // _EXT_CMATH
153