Octave-Forge - Extra packages for GNU Octave | |
Home · Packages · Developers · Documentation · FAQ · Bugs · Mailing Lists · Links · Code |
00001 /* 00002 00003 Copyright (C) 2008, 2009 Jaroslav Hajek 00004 00005 This file is part of Octave. 00006 00007 Octave is free software; you can redistribute it and/or modify it 00008 under the terms of the GNU General Public License as published by the 00009 Free Software Foundation; either version 3 of the License, or (at your 00010 option) any later version. 00011 00012 Octave is distributed in the hope that it will be useful, but WITHOUT 00013 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00014 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 00015 for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with Octave; see the file COPYING. If not, see 00019 <http://www.gnu.org/licenses/>. 00020 00021 */ 00022 00023 #if !defined (octave_DET_h) 00024 #define octave_DET_h 1 00025 00026 #include <cmath> 00027 #include "oct-cmplx.h" 00028 #include "lo-mappers.h" 00029 00030 template <class T> 00031 class 00032 base_det 00033 { 00034 public: 00035 00036 base_det (T c = 1, int e = 0) 00037 { 00038 c2 = xlog2 (c, e2); 00039 e2 += e; 00040 } 00041 00042 base_det (T c, double e, double b) 00043 { 00044 e *= xlog2 (b); 00045 e2 = e; 00046 c *= xexp2 (e - e2); 00047 int f; 00048 c2 = xlog2 (c, f); 00049 e2 += f; 00050 } 00051 00052 base_det (const base_det& a) : c2(a.c2), e2(a.e2) { } 00053 00054 base_det& operator = (const base_det& a) 00055 { 00056 c2 = a.c2; 00057 e2 = a.e2; 00058 return *this; 00059 } 00060 00061 T coef (void) const { return c2; } 00062 int exp (void) const { return e2; } 00063 00064 T value () const { return c2 * static_cast<T> (std::ldexp (1.0, e2)); } 00065 operator T () const { return value (); } 00066 00067 base_det square () const { return base_det (c2*c2, e2+e2); } 00068 00069 void operator *= (T t) 00070 { 00071 int e; 00072 c2 *= xlog2 (t, e); 00073 e2 += e; 00074 } 00075 00076 private: 00077 00078 T c2; 00079 int e2; 00080 }; 00081 00082 // Provide the old types by typedefs. 00083 typedef base_det<double> DET; 00084 typedef base_det<float> FloatDET; 00085 typedef base_det<Complex> ComplexDET; 00086 typedef base_det<FloatComplex> FloatComplexDET; 00087 00088 #endif