GNU Octave  8.1.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-2023 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  : m_c2 (), m_e2 ()
44  {
45  m_c2 = octave::math::log2 (c, m_e2);
46  m_e2 += e;
47  }
48 
49  base_det (T c, double e, double b)
50  : m_c2 (), m_e2 ()
51  {
52  e *= octave::math::log2 (b);
53  m_e2 = e;
54  c *= octave::math::exp2 (e - m_e2);
55  int f;
56  m_c2 = octave::math::log2 (c, f);
57  m_e2 += f;
58  }
59 
60  base_det (const base_det& a) : m_c2 (a.m_c2), m_e2 (a.m_e2) { }
61 
62  base_det& operator = (const base_det& a)
63  {
64  m_c2 = a.m_c2;
65  m_e2 = a.m_e2;
66  return *this;
67  }
68 
69  T coef (void) const { return m_c2; }
70  int exp (void) const { return m_e2; }
71 
72  T value () const { return m_c2 * static_cast<T> (std::ldexp (1.0, m_e2)); }
73  operator T () const { return value (); }
74 
75  base_det square () const { return base_det (m_c2*m_c2, m_e2+m_e2); }
76 
77  void operator *= (T t)
78  {
79  int e;
80  m_c2 *= t;
81  // Renormalize m_c2 to [0.5, 1), and find required change in exponent.
82  m_c2 = octave::math::log2 (m_c2, e);
83  m_e2 += e;
84  }
85 
86 private:
87 
88  T m_c2;
89  int m_e2;
90 };
91 
92 // Provide the old types by typedefs.
97 
98 #endif
ComplexColumnVector operator*=(ComplexColumnVector &x, const Complex &y)
Definition: CColVector.h:156
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 m_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 m_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
Complex log2(const Complex &x)
Definition: lo-mappers.cc:139
double exp2(double x)
Definition: lo-mappers.h:98
F77_RET_T const F77_DBLE const F77_DBLE * f