GNU Octave  9.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
DET.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 2008-2024 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  OCTAVE_DEFAULT_COPY_MOVE_DELETE (base_det)
61 
62  T coef () const { return m_c2; }
63  int exp () const { return m_e2; }
64 
65  T value () const { return m_c2 * static_cast<T> (std::ldexp (1.0, m_e2)); }
66  operator T () const { return value (); }
67 
68  base_det square () const { return base_det (m_c2*m_c2, m_e2+m_e2); }
69 
70  void operator *= (T t)
71  {
72  int e;
73  m_c2 *= t;
74  // Renormalize m_c2 to [0.5, 1), and find required change in exponent.
75  m_c2 = octave::math::log2 (m_c2, e);
76  m_e2 += e;
77  }
78 
79 private:
80 
81  T m_c2;
82  int m_e2;
83 };
84 
85 // Provide the old types by typedefs.
90 
91 #endif
ComplexColumnVector operator*=(ComplexColumnVector &x, const Complex &y)
Definition: CColVector.h:158
base_det< FloatComplex > FloatComplexDET
Definition: DET.h:89
base_det< double > DET
Definition: DET.h:86
base_det< float > FloatDET
Definition: DET.h:87
base_det< Complex > ComplexDET
Definition: DET.h:88
Definition: DET.h:39
base_det(T c=1, int e=0)
Definition: DET.h:42
base_det square() const
Definition: DET.h:68
T value() const
Definition: DET.h:65
int exp() const
Definition: DET.h:63
base_det(T c, double e, double b)
Definition: DET.h:49
Complex log2(const Complex &x)
Definition: lo-mappers.cc:141
double exp2(double x)
Definition: lo-mappers.h:98
F77_RET_T const F77_DBLE const F77_DBLE * f