|
STK++ 1.0
|
00001 /*--------------------------------------------------------------------*/ 00002 /* Copyright (C) 2004-2007 Serge Iovleff 00003 00004 This program is free software; you can redistribute it and/or modify 00005 it under the terms of the GNU Lesser General Public License as 00006 published by the Free Software Foundation; either version 2 of the 00007 License, or (at your option) any later version. 00008 00009 This program is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 GNU Lesser General Public License for more details. 00013 00014 You should have received a copy of the GNU Lesser General Public 00015 License along with this program; if not, write to the 00016 Free Software Foundation, Inc., 00017 59 Temple Place, 00018 Suite 330, 00019 Boston, MA 02111-1307 00020 USA 00021 00022 Contact : Serge.Iovleff@stkpp.org 00023 */ 00024 00025 /* 00026 * Project: Algebra 00027 * Purpose: Implement Givens methods for Algebra classes. 00028 * Author: Serge Iovleff, serge.iovleff@stkpp.org 00029 * 00030 **/ 00031 00037 #include "../include/STK_Givens.h" 00038 #include "../../STKernel/include/STK_Misc.h" 00039 00040 namespace STK 00041 { 00042 /* 00043 * Compute the Givens rotation in order to eliminate the coefficient z. 00044 **/ 00045 Real compGivens( Real const& y, Real const& z, Real& cosinus, Real& sinus) 00046 { 00047 // trivial case 00048 if (z == 0) 00049 { 00050 sinus = 0.0; 00051 cosinus = 1.0; 00052 return y; 00053 } 00054 // compute Givens rotation avoiding underflow and overflow 00055 if (abs(z) > abs(y)) 00056 { 00057 Real aux = y/z; 00058 Real t = sign(z, sqrt(1.0+aux*aux)); 00059 sinus = 1.0/t; 00060 cosinus = sinus * aux; 00061 return t*z; 00062 } 00063 else 00064 { 00065 Real aux = z/y; 00066 Real t = sign(y, sqrt(1.0+aux*aux)); 00067 cosinus = 1.0/t; 00068 sinus = cosinus * aux; 00069 return t*y; 00070 } 00071 } 00072 00073 } // namespace STK