00001 /* Ergo, version 3.7, a program for linear scaling electronic structure 00002 * calculations. 00003 * Copyright (C) 2018 Elias Rudberg, Emanuel H. Rubensson, Pawel Salek, 00004 * and Anastasia Kruchinina. 00005 * 00006 * This program is free software: you can redistribute it and/or modify 00007 * it under the terms of the GNU General Public License as published by 00008 * the Free Software Foundation, either version 3 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * This program 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 * You should have received a copy of the GNU General Public License 00017 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00018 * 00019 * Primary academic reference: 00020 * Ergo: An open-source program for linear-scaling electronic structure 00021 * calculations, 00022 * Elias Rudberg, Emanuel H. Rubensson, Pawel Salek, and Anastasia 00023 * Kruchinina, 00024 * SoftwareX 7, 107 (2018), 00025 * <http://dx.doi.org/10.1016/j.softx.2018.03.005> 00026 * 00027 * For further information about Ergo, see <http://www.ergoscf.org>. 00028 */ 00029 00030 /* This file belongs to the template_lapack part of the Ergo source 00031 * code. The source files in the template_lapack directory are modified 00032 * versions of files originally distributed as CLAPACK, see the 00033 * Copyright/license notice in the file template_lapack/COPYING. 00034 */ 00035 00036 00037 #ifndef TEMPLATE_LAPACK_LADIV_HEADER 00038 #define TEMPLATE_LAPACK_LADIV_HEADER 00039 00040 00041 template<class Treal> 00042 int template_lapack_ladiv(const Treal *a, const Treal *b, const Treal *c__, 00043 const Treal *d__, Treal *p, Treal *q) 00044 { 00045 /* -- LAPACK auxiliary routine (version 3.0) -- 00046 Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd., 00047 Courant Institute, Argonne National Lab, and Rice University 00048 October 31, 1992 00049 00050 00051 Purpose 00052 ======= 00053 00054 DLADIV performs complex division in real arithmetic 00055 00056 a + i*b 00057 p + i*q = --------- 00058 c + i*d 00059 00060 The algorithm is due to Robert L. Smith and can be found 00061 in D. Knuth, The art of Computer Programming, Vol.2, p.195 00062 00063 Arguments 00064 ========= 00065 00066 A (input) DOUBLE PRECISION 00067 B (input) DOUBLE PRECISION 00068 C (input) DOUBLE PRECISION 00069 D (input) DOUBLE PRECISION 00070 The scalars a, b, c, and d in the above expression. 00071 00072 P (output) DOUBLE PRECISION 00073 Q (output) DOUBLE PRECISION 00074 The scalars p and q in the above expression. 00075 00076 ===================================================================== */ 00077 Treal e, f; 00078 00079 00080 00081 if (absMACRO(*d__) < absMACRO(*c__)) { 00082 e = *d__ / *c__; 00083 f = *c__ + *d__ * e; 00084 *p = (*a + *b * e) / f; 00085 *q = (*b - *a * e) / f; 00086 } else { 00087 e = *c__ / *d__; 00088 f = *d__ + *c__ * e; 00089 *p = (*b + *a * e) / f; 00090 *q = (-(*a) + *b * e) / f; 00091 } 00092 00093 return 0; 00094 00095 /* End of DLADIV */ 00096 00097 } /* dladiv_ */ 00098 00099 #endif