ergo
template_blas_basicmath.h
Go to the documentation of this file.
1 /* Ergo, version 3.3, a program for linear scaling electronic structure
2  * calculations.
3  * Copyright (C) 2013 Elias Rudberg, Emanuel H. Rubensson, and Pawel Salek.
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * Primary academic reference:
19  * Kohn−Sham Density Functional Theory Electronic Structure Calculations
20  * with Linearly Scaling Computational Time and Memory Usage,
21  * Elias Rudberg, Emanuel H. Rubensson, and Pawel Salek,
22  * J. Chem. Theory Comput. 7, 340 (2011),
23  * <http://dx.doi.org/10.1021/ct100611z>
24  *
25  * For further information about Ergo, see <http://www.ergoscf.org>.
26  */
27 
28  /* This file belongs to the template_lapack part of the Ergo source
29  * code. The source files in the template_lapack directory are modified
30  * versions of files originally distributed as CLAPACK, see the
31  * Copyright/license notice in the file template_lapack/COPYING.
32  */
33 
34 
35 #ifndef TEMPLATE_BLAS_BASICMATH_HEADER
36 #define TEMPLATE_BLAS_BASICMATH_HEADER
37 
38 #include <limits>
39 
40 template<class Treal>
41 Treal template_blas_fabs(Treal x);
42 
43 template<class Treal>
44 Treal template_blas_sqrt(Treal x);
45 
46 template<class Treal>
47 Treal template_blas_exp(Treal x);
48 
49 template<class Treal>
50 Treal template_blas_log(Treal x);
51 
52 template<class Treal>
53 Treal template_blas_erf(Treal x);
54 
55 template<class Treal>
56 Treal template_blas_erfc(Treal x);
57 
58 
59 /* template_blas_compute_pi_BBP
60  This routine computes the number pi up to the precision of Treal
61  using the BBP formula. */
62 template<class Treal>
63 Treal template_blas_compute_pi_BBP(Treal dummy)
64 {
65  Treal epsilon = std::numeric_limits<Treal>::epsilon();
66  Treal one_over_16 = (Treal)1 / (Treal)16;
67  Treal one_over_16_to_pow_k = 1;
68  Treal sum = 0;
69  int k = 0;
70  do
71  {
72  Treal factor =
73  (Treal)4 / (Treal)(8*k + 1) -
74  (Treal)2 / (Treal)(8*k + 4) -
75  (Treal)1 / (Treal)(8*k + 5) -
76  (Treal)1 / (Treal)(8*k + 6);
77  sum += one_over_16_to_pow_k * factor;
78  k++;
79  one_over_16_to_pow_k *= one_over_16;
80  }
81  while(one_over_16_to_pow_k > epsilon);
82  return sum;
83 }
84 
85 
86 #endif
Treal template_blas_erfc(Treal x)
Treal template_blas_fabs(Treal x)
Treal template_blas_exp(Treal x)
Treal template_blas_log(Treal x)
Treal template_blas_erf(Treal x)
Treal template_blas_compute_pi_BBP(Treal dummy)
Definition: template_blas_basicmath.h:63
Treal template_blas_sqrt(Treal x)