GNU Octave  6.2.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
DET.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 2008-2021 The Octave Project Developers
4 //
5 // See the file COPYRIGHT.md in the top-level directory of this
6 // distribution or <https://octave.org/copyright/>.
7 //
8 // This file is part of Octave.
9 //
10 // Octave is free software: you can redistribute it and/or modify it
11 // under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // Octave is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with Octave; see the file COPYING. If not, see
22 // <https://www.gnu.org/licenses/>.
23 //
24 ////////////////////////////////////////////////////////////////////////
25 
26 #if ! defined (octave_DET_h)
27 #define octave_DET_h 1
28 
29 #include "octave-config.h"
30 
31 #include <cmath>
32 
33 #include "lo-mappers.h"
34 #include "oct-cmplx.h"
35 
36 template <typename T>
37 class
39 {
40 public:
41 
42  base_det (T c = 1, int e = 0)
43  : c2 (), e2 ()
44  {
45  c2 = octave::math::log2 (c, e2);
46  e2 += e;
47  }
48 
49  base_det (T c, double e, double b)
50  : c2 (), e2 ()
51  {
52  e *= octave::math::log2 (b);
53  e2 = e;
54  c *= octave::math::exp2 (e - e2);
55  int f;
56  c2 = octave::math::log2 (c, f);
57  e2 += f;
58  }
59 
60  base_det (const base_det& a) : c2 (a.c2), e2 (a.e2) { }
61 
62  base_det& operator = (const base_det& a)
63  {
64  c2 = a.c2;
65  e2 = a.e2;
66  return *this;
67  }
68 
69  T coef (void) const { return c2; }
70  int exp (void) const { return e2; }
71 
72  T value () const { return c2 * static_cast<T> (std::ldexp (1.0, e2)); }
73  operator T () const { return value (); }
74 
75  base_det square () const { return base_det (c2*c2, e2+e2); }
76 
77  void operator *= (T t)
78  {
79  int e;
80  c2 *= t;
81  // Renormalize c2 to [0.5, 1), and find required change in exponent.
82  c2 = octave::math::log2 (c2, e);
83  e2 += e;
84  }
85 
86 private:
87 
88  T c2;
89  int e2;
90 };
91 
92 // Provide the old types by typedefs.
97 
98 #endif
ComplexColumnVector operator*=(ComplexColumnVector &x, const Complex &y)
Definition: CColVector.h:152
base_det< FloatComplex > FloatComplexDET
Definition: DET.h:96
base_det< double > DET
Definition: DET.h:93
base_det< float > FloatDET
Definition: DET.h:94
base_det< Complex > ComplexDET
Definition: DET.h:95
Definition: DET.h:39
base_det(const base_det &a)
Definition: DET.h:60
T coef(void) const
Definition: DET.h:69
T c2
Definition: DET.h:88
base_det(T c=1, int e=0)
Definition: DET.h:42
base_det square() const
Definition: DET.h:75
T value() const
Definition: DET.h:72
int e2
Definition: DET.h:89
base_det(T c, double e, double b)
Definition: DET.h:49
int exp(void) const
Definition: DET.h:70
F77_RET_T const F77_DBLE const F77_DBLE * f
double exp2(double x)
Definition: lo-mappers.h:98
Complex log2(const Complex &x)
Definition: lo-mappers.cc:139