ergo
|
00001 /* Ergo, version 3.2, a program for linear scaling electronic structure 00002 * calculations. 00003 * Copyright (C) 2012 Elias Rudberg, Emanuel H. Rubensson, and Pawel Salek. 00004 * 00005 * This program is free software: you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License as published by 00007 * the Free Software Foundation, either version 3 of the License, or 00008 * (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00017 * 00018 * Primary academic reference: 00019 * KohnâSham Density Functional Theory Electronic Structure Calculations 00020 * with Linearly Scaling Computational Time and Memory Usage, 00021 * Elias Rudberg, Emanuel H. Rubensson, and Pawel Salek, 00022 * J. Chem. Theory Comput. 7, 340 (2011), 00023 * <http://dx.doi.org/10.1021/ct100611z> 00024 * 00025 * For further information about Ergo, see <http://www.ergoscf.org>. 00026 */ 00027 00028 /* This file belongs to the template_lapack part of the Ergo source 00029 * code. The source files in the template_lapack directory are modified 00030 * versions of files originally distributed as CLAPACK, see the 00031 * Copyright/license notice in the file template_lapack/COPYING. 00032 */ 00033 00034 00035 #ifndef TEMPLATE_BLAS_BASICMATH_HEADER 00036 #define TEMPLATE_BLAS_BASICMATH_HEADER 00037 00038 #include <limits> 00039 00040 template<class Treal> 00041 Treal template_blas_fabs(Treal x); 00042 00043 template<class Treal> 00044 Treal template_blas_sqrt(Treal x); 00045 00046 template<class Treal> 00047 Treal template_blas_exp(Treal x); 00048 00049 template<class Treal> 00050 Treal template_blas_log(Treal x); 00051 00052 template<class Treal> 00053 Treal template_blas_erf(Treal x); 00054 00055 template<class Treal> 00056 Treal template_blas_erfc(Treal x); 00057 00058 00059 /* template_blas_compute_pi_BBP 00060 This routine computes the number pi up to the precision of Treal 00061 using the BBP formula. */ 00062 template<class Treal> 00063 Treal template_blas_compute_pi_BBP(Treal dummy) 00064 { 00065 Treal epsilon = std::numeric_limits<Treal>::epsilon(); 00066 Treal one_over_16 = (Treal)1 / (Treal)16; 00067 Treal one_over_16_to_pow_k = 1; 00068 Treal sum = 0; 00069 int k = 0; 00070 do 00071 { 00072 Treal factor = 00073 (Treal)4 / (Treal)(8*k + 1) - 00074 (Treal)2 / (Treal)(8*k + 4) - 00075 (Treal)1 / (Treal)(8*k + 5) - 00076 (Treal)1 / (Treal)(8*k + 6); 00077 sum += one_over_16_to_pow_k * factor; 00078 k++; 00079 one_over_16_to_pow_k *= one_over_16; 00080 } 00081 while(one_over_16_to_pow_k > epsilon); 00082 return sum; 00083 } 00084 00085 00086 #endif