GNU Octave 10.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 
Loading...
Searching...
No Matches
DET.h
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 2008-2025 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
36template <typename T>
38{
39public:
40
41 base_det (T c = 1, int e = 0)
42 : m_c2 (), m_e2 ()
43 {
44 m_c2 = octave::math::log2 (c, m_e2);
45 m_e2 += e;
46 }
47
48 base_det (T c, double e, double b)
49 : m_c2 (), m_e2 ()
50 {
51 e *= octave::math::log2 (b);
52 m_e2 = e;
53 c *= octave::math::exp2 (e - m_e2);
54 int f;
55 m_c2 = octave::math::log2 (c, f);
56 m_e2 += f;
57 }
58
59 OCTAVE_DEFAULT_COPY_MOVE_DELETE (base_det)
60
61 T coef () const { return m_c2; }
62 int exp () const { return m_e2; }
63
64 T value () const { return m_c2 * static_cast<T> (std::ldexp (1.0, m_e2)); }
65 operator T () const { return value (); }
66
67 base_det square () const { return base_det (m_c2*m_c2, m_e2+m_e2); }
68
69 void operator *= (T t)
70 {
71 int e;
72 m_c2 *= t;
73 // Renormalize m_c2 to [0.5, 1), and find required change in exponent.
74 m_c2 = octave::math::log2 (m_c2, e);
75 m_e2 += e;
76 }
77
78private:
79
80 T m_c2;
81 int m_e2;
82};
83
84// Provide the old types by typedefs.
89
90#endif
base_det< FloatComplex > FloatComplexDET
Definition DET.h:88
base_det< double > DET
Definition DET.h:85
base_det< float > FloatDET
Definition DET.h:86
base_det< Complex > ComplexDET
Definition DET.h:87
Definition DET.h:38
void operator*=(T t)
Definition DET.h:69
base_det(T c=1, int e=0)
Definition DET.h:41
base_det square() const
Definition DET.h:67
T coef() const
Definition DET.h:61
T value() const
Definition DET.h:64
int exp() const
Definition DET.h:62
base_det(T c, double e, double b)
Definition DET.h:48
F77_RET_T const F77_DBLE const F77_DBLE * f