DET.h

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (C) 2008-2012 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     : c2 (), e2 ()
00038     {
00039       c2 = xlog2 (c, e2);
00040       e2 += e;
00041     }
00042 
00043   base_det (T c, double e, double b)
00044     : c2 (), e2 ()
00045     {
00046       e *= xlog2 (b);
00047       e2 = e;
00048       c *= xexp2 (e - e2);
00049       int f;
00050       c2 = xlog2 (c, f);
00051       e2 += f;
00052     }
00053 
00054   base_det (const base_det& a) : c2 (a.c2), e2 (a.e2) { }
00055 
00056   base_det& operator = (const base_det& a)
00057     {
00058       c2 = a.c2;
00059       e2 = a.e2;
00060       return *this;
00061     }
00062 
00063   T coef (void) const { return c2; }
00064   int exp (void) const { return e2; }
00065 
00066   T value () const { return c2 * static_cast<T> (std::ldexp (1.0, e2)); }
00067   operator T () const { return value (); }
00068 
00069   base_det square () const { return base_det (c2*c2, e2+e2); }
00070 
00071   void operator *= (T t)
00072     {
00073       int e;
00074       c2 *= xlog2 (t, e);
00075       e2 += e;
00076     }
00077 
00078 private:
00079 
00080   T c2;
00081   int e2;
00082 };
00083 
00084 // Provide the old types by typedefs.
00085 typedef base_det<double> DET;
00086 typedef base_det<float> FloatDET;
00087 typedef base_det<Complex> ComplexDET;
00088 typedef base_det<FloatComplex> FloatComplexDET;
00089 
00090 #endif
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines