template_lapack_ladiv.h

Go to the documentation of this file.
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_LAPACK_LADIV_HEADER
00036 #define TEMPLATE_LAPACK_LADIV_HEADER
00037 
00038 
00039 template<class Treal>
00040 int template_lapack_ladiv(const Treal *a, const Treal *b, const Treal *c__, 
00041         const Treal *d__, Treal *p, Treal *q)
00042 {
00043 /*  -- LAPACK auxiliary routine (version 3.0) --   
00044        Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,   
00045        Courant Institute, Argonne National Lab, and Rice University   
00046        October 31, 1992   
00047 
00048 
00049     Purpose   
00050     =======   
00051 
00052     DLADIV performs complex division in  real arithmetic   
00053 
00054                           a + i*b   
00055                p + i*q = ---------   
00056                           c + i*d   
00057 
00058     The algorithm is due to Robert L. Smith and can be found   
00059     in D. Knuth, The art of Computer Programming, Vol.2, p.195   
00060 
00061     Arguments   
00062     =========   
00063 
00064     A       (input) DOUBLE PRECISION   
00065     B       (input) DOUBLE PRECISION   
00066     C       (input) DOUBLE PRECISION   
00067     D       (input) DOUBLE PRECISION   
00068             The scalars a, b, c, and d in the above expression.   
00069 
00070     P       (output) DOUBLE PRECISION   
00071     Q       (output) DOUBLE PRECISION   
00072             The scalars p and q in the above expression.   
00073 
00074     ===================================================================== */
00075      Treal e, f;
00076 
00077 
00078 
00079     if (absMACRO(*d__) < absMACRO(*c__)) {
00080         e = *d__ / *c__;
00081         f = *c__ + *d__ * e;
00082         *p = (*a + *b * e) / f;
00083         *q = (*b - *a * e) / f;
00084     } else {
00085         e = *c__ / *d__;
00086         f = *d__ + *c__ * e;
00087         *p = (*b + *a * e) / f;
00088         *q = (-(*a) + *b * e) / f;
00089     }
00090 
00091     return 0;
00092 
00093 /*     End of DLADIV */
00094 
00095 } /* dladiv_ */
00096 
00097 #endif

Generated on Wed Nov 21 09:32:37 2012 for ergo by  doxygen 1.4.7